opennebula-oca 3.9.0.beta → 3.9.90.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -0
- metadata +35 -108
- data/LICENSE +0 -202
- data/NOTICE +0 -48
- data/lib/opennebula/acl.rb +0 -259
- data/lib/opennebula/acl_pool.rb +0 -53
- data/lib/opennebula/client.rb +0 -102
- data/lib/opennebula/cluster.rb +0 -247
- data/lib/opennebula/cluster_pool.rb +0 -56
- data/lib/opennebula/datastore.rb +0 -169
- data/lib/opennebula/datastore_pool.rb +0 -53
- data/lib/opennebula/document.rb +0 -259
- data/lib/opennebula/document_json.rb +0 -129
- data/lib/opennebula/document_pool.rb +0 -97
- data/lib/opennebula/document_pool_json.rb +0 -58
- data/lib/opennebula/error.rb +0 -52
- data/lib/opennebula/group.rb +0 -161
- data/lib/opennebula/group_pool.rb +0 -54
- data/lib/opennebula/host.rb +0 -199
- data/lib/opennebula/host_pool.rb +0 -91
- data/lib/opennebula/image.rb +0 -293
- data/lib/opennebula/image_pool.rb +0 -74
- data/lib/opennebula/ldap_auth.rb +0 -99
- data/lib/opennebula/ldap_auth_spec.rb +0 -70
- data/lib/opennebula/pool.rb +0 -157
- data/lib/opennebula/pool_element.rb +0 -269
- data/lib/opennebula/server_cipher_auth.rb +0 -148
- data/lib/opennebula/server_x509_auth.rb +0 -104
- data/lib/opennebula/ssh_auth.rb +0 -139
- data/lib/opennebula/system.rb +0 -141
- data/lib/opennebula/template.rb +0 -201
- data/lib/opennebula/template_pool.rb +0 -74
- data/lib/opennebula/user.rb +0 -172
- data/lib/opennebula/user_pool.rb +0 -53
- data/lib/opennebula/virtual_machine.rb +0 -426
- data/lib/opennebula/virtual_machine_pool.rb +0 -318
- data/lib/opennebula/virtual_network.rb +0 -247
- data/lib/opennebula/virtual_network_pool.rb +0 -74
- data/lib/opennebula/x509_auth.rb +0 -241
- data/lib/opennebula/xml_element.rb +0 -427
- data/lib/opennebula/xml_pool.rb +0 -45
- data/lib/opennebula/xml_utils.rb +0 -34
- data/lib/opennebula.rb +0 -58
@@ -1,318 +0,0 @@
|
|
1
|
-
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
3
|
-
# #
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
|
-
# not use this file except in compliance with the License. You may obtain #
|
6
|
-
# a copy of the License at #
|
7
|
-
# #
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0 #
|
9
|
-
# #
|
10
|
-
# Unless required by applicable law or agreed to in writing, software #
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS, #
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
13
|
-
# See the License for the specific language governing permissions and #
|
14
|
-
# limitations under the License. #
|
15
|
-
#--------------------------------------------------------------------------- #
|
16
|
-
|
17
|
-
|
18
|
-
require 'opennebula/pool'
|
19
|
-
|
20
|
-
module OpenNebula
|
21
|
-
class VirtualMachinePool < Pool
|
22
|
-
#######################################################################
|
23
|
-
# Constants and Class attribute accessors
|
24
|
-
#######################################################################
|
25
|
-
|
26
|
-
|
27
|
-
VM_POOL_METHODS = {
|
28
|
-
:info => "vmpool.info",
|
29
|
-
:monitoring => "vmpool.monitoring",
|
30
|
-
:accounting => "vmpool.accounting"
|
31
|
-
}
|
32
|
-
|
33
|
-
# Constants for info queries (include/RequestManagerPoolInfoFilter.h)
|
34
|
-
INFO_NOT_DONE = -1
|
35
|
-
INFO_ALL_VM = -2
|
36
|
-
|
37
|
-
#######################################################################
|
38
|
-
# Class constructor & Pool Methods
|
39
|
-
#######################################################################
|
40
|
-
|
41
|
-
|
42
|
-
# +client+ a Client object that represents a XML-RPC connection
|
43
|
-
# +user_id+ is to refer to a Pool with VirtualMachines from that user
|
44
|
-
def initialize(client, user_id=0)
|
45
|
-
super('VM_POOL','VM',client)
|
46
|
-
|
47
|
-
@user_id = user_id
|
48
|
-
end
|
49
|
-
|
50
|
-
# Default Factory Method for the Pools
|
51
|
-
def factory(element_xml)
|
52
|
-
OpenNebula::VirtualMachine.new(element_xml,@client)
|
53
|
-
end
|
54
|
-
|
55
|
-
#######################################################################
|
56
|
-
# XML-RPC Methods for the Virtual Network Object
|
57
|
-
#######################################################################
|
58
|
-
|
59
|
-
# Retrieves all or part of the VirtualMachines in the pool.
|
60
|
-
# No arguments, returns the not-in-done VMs for the user
|
61
|
-
# [user_id, start_id, end_id]
|
62
|
-
# [user_id, start_id, end_id, state]
|
63
|
-
def info(*args)
|
64
|
-
case args.size
|
65
|
-
when 0
|
66
|
-
info_filter(VM_POOL_METHODS[:info],
|
67
|
-
@user_id,
|
68
|
-
-1,
|
69
|
-
-1,
|
70
|
-
INFO_NOT_DONE)
|
71
|
-
when 1
|
72
|
-
info_filter(VM_POOL_METHODS[:info],
|
73
|
-
args[0],
|
74
|
-
-1,
|
75
|
-
-1,
|
76
|
-
INFO_NOT_DONE)
|
77
|
-
when 3
|
78
|
-
info_filter(VM_POOL_METHODS[:info],
|
79
|
-
args[0],
|
80
|
-
args[1],
|
81
|
-
args[2],
|
82
|
-
INFO_NOT_DONE)
|
83
|
-
when 4
|
84
|
-
info_filter(VM_POOL_METHODS[:info],
|
85
|
-
args[0],
|
86
|
-
args[1],
|
87
|
-
args[2],
|
88
|
-
args[3])
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def info_all()
|
93
|
-
return info_filter(VM_POOL_METHODS[:info],
|
94
|
-
INFO_ALL,
|
95
|
-
-1,
|
96
|
-
-1,
|
97
|
-
INFO_NOT_DONE)
|
98
|
-
end
|
99
|
-
|
100
|
-
def info_mine()
|
101
|
-
return info_filter(VM_POOL_METHODS[:info],
|
102
|
-
INFO_MINE,
|
103
|
-
-1,
|
104
|
-
-1,
|
105
|
-
INFO_NOT_DONE)
|
106
|
-
end
|
107
|
-
|
108
|
-
def info_group()
|
109
|
-
return info_filter(VM_POOL_METHODS[:info],
|
110
|
-
INFO_GROUP,
|
111
|
-
-1,
|
112
|
-
-1,
|
113
|
-
INFO_NOT_DONE)
|
114
|
-
end
|
115
|
-
|
116
|
-
# Retrieves the monitoring data for all the VMs in the pool
|
117
|
-
#
|
118
|
-
# @param [Array<String>] xpath_expressions Elements to retrieve.
|
119
|
-
# @param [Integer] filter_flag Optional filter flag to retrieve all or
|
120
|
-
# part of the Pool. Possible values: INFO_ALL, INFO_GROUP, INFO_MINE.
|
121
|
-
#
|
122
|
-
# @return [Hash<String, <Hash<String, Array<Array<int>>>>>,
|
123
|
-
# OpenNebula::Error] The first level hash uses the VM ID as keys, and
|
124
|
-
# as value a Hash with the requested xpath expressions,
|
125
|
-
# and an Array of 'timestamp, value'.
|
126
|
-
#
|
127
|
-
# @example
|
128
|
-
# vm_pool.monitoring( ['CPU', 'NET_TX', 'TEMPLATE/CUSTOM_PROBE'] )
|
129
|
-
#
|
130
|
-
# {"1"=>
|
131
|
-
# {"CPU"=>
|
132
|
-
# [["1337608271", "0"], ["1337608301", "0"], ["1337608331", "0"]],
|
133
|
-
# "NET_TX"=>
|
134
|
-
# [["1337608271", "510"], ["1337608301", "510"], ["1337608331", "520"]],
|
135
|
-
# "TEMPLATE/CUSTOM_PROBE"=>
|
136
|
-
# []},
|
137
|
-
#
|
138
|
-
# "0"=>
|
139
|
-
# {"CPU"=>
|
140
|
-
# [["1337608271", "0"], ["1337608301", "0"], ["1337608331", "0"]],
|
141
|
-
# "NET_TX"=>
|
142
|
-
# [["1337608271", "510"], ["1337608301", "510"], ["1337608331", "520"]],
|
143
|
-
# "TEMPLATE/CUSTOM_PROBE"=>
|
144
|
-
# []}}
|
145
|
-
def monitoring(xpath_expressions, filter_flag=INFO_ALL)
|
146
|
-
return super(VM_POOL_METHODS[:monitoring],
|
147
|
-
'VM', 'LAST_POLL', xpath_expressions, filter_flag)
|
148
|
-
end
|
149
|
-
|
150
|
-
# Retrieves the monitoring data for all the VMs in the pool, in XML
|
151
|
-
#
|
152
|
-
# @param [Integer] filter_flag Optional filter flag to retrieve all or
|
153
|
-
# part of the Pool. Possible values: INFO_ALL, INFO_GROUP, INFO_MINE.
|
154
|
-
#
|
155
|
-
# @return [String] VM monitoring data, in XML
|
156
|
-
def monitoring_xml(filter_flag=INFO_ALL)
|
157
|
-
return @client.call(VM_POOL_METHODS[:monitoring], filter_flag)
|
158
|
-
end
|
159
|
-
|
160
|
-
# Retrieves the accounting data for all the VMs in the pool
|
161
|
-
#
|
162
|
-
# @param [Integer] filter_flag Optional filter flag to retrieve all or
|
163
|
-
# part of the Pool. Possible values: INFO_ALL, INFO_GROUP, INFO_MINE
|
164
|
-
# or user_id
|
165
|
-
# @param [Hash] options
|
166
|
-
# @option params [Integer] :start_time Start date and time to take into account,
|
167
|
-
# if no start_time is required use -1
|
168
|
-
# @option params [Integer] :end_time End date and time to take into account,
|
169
|
-
# if no end_time is required use -1
|
170
|
-
# @option params [Integer] :host Host id to filter the results
|
171
|
-
# @option params [Integer] :group Group id to filter the results
|
172
|
-
# @option params [String] :xpath Xpath expression to filter the results.
|
173
|
-
# For example: HISTORY[ETIME>0]
|
174
|
-
# @option params [String] :order_by_1 Xpath expression to group the
|
175
|
-
# @option params [String] :order_by_2 Xpath expression to group the
|
176
|
-
# returned hash. This will be the second level of the hash
|
177
|
-
#
|
178
|
-
# @return [Hash, OpenNebula::Error]
|
179
|
-
# The first level hash uses the :order_by_1 values as keys, and
|
180
|
-
# as value a Hash with the :order_by_2 values and the HISTORY_RECORDS
|
181
|
-
#
|
182
|
-
# @example
|
183
|
-
# {"HISTORY_RECORDS"=>
|
184
|
-
# {"HISTORY"=> [
|
185
|
-
# {"OID"=>"0",
|
186
|
-
# "SEQ"=>"0",
|
187
|
-
# "HOSTNAME"=>"dummy",
|
188
|
-
# ...
|
189
|
-
# },
|
190
|
-
# {"OID"=>"0",
|
191
|
-
# "SEQ"=>"0",
|
192
|
-
# "HOSTNAME"=>"dummy",
|
193
|
-
#
|
194
|
-
# @example :order_by_1 => VM/UID
|
195
|
-
# {"0"=>
|
196
|
-
# {"HISTORY_RECORDS"=>
|
197
|
-
# {"HISTORY"=> [
|
198
|
-
# {"OID"=>"0",
|
199
|
-
# "SEQ"=>"0",
|
200
|
-
# "HOSTNAME"=>"dummy",
|
201
|
-
# ...
|
202
|
-
# },
|
203
|
-
# {"OID"=>"0",
|
204
|
-
# "SEQ"=>"0",
|
205
|
-
# "HOSTNAME"=>"dummy",
|
206
|
-
#
|
207
|
-
# @example :order_by_1 => VM/UID, :order_by_2 => VM/ID
|
208
|
-
# {"0"=>
|
209
|
-
# {"0"=>
|
210
|
-
# {"HISTORY_RECORDS"=>
|
211
|
-
# {"HISTORY"=> [
|
212
|
-
# {"OID"=>"0",
|
213
|
-
# "SEQ"=>"0",
|
214
|
-
# "HOSTNAME"=>"dummy",
|
215
|
-
# ...
|
216
|
-
# },
|
217
|
-
# {"OID"=>"0",
|
218
|
-
# "SEQ"=>"0",
|
219
|
-
# "HOSTNAME"=>"dummy",
|
220
|
-
#
|
221
|
-
def accounting(filter_flag=INFO_ALL, options={})
|
222
|
-
acct_hash = Hash.new
|
223
|
-
|
224
|
-
rc = build_accounting(filter_flag, options) do |history|
|
225
|
-
hash = acct_hash
|
226
|
-
|
227
|
-
if options[:order_by_1]
|
228
|
-
id_1 = history[options[:order_by_1]]
|
229
|
-
acct_hash[id_1] ||= Hash.new
|
230
|
-
|
231
|
-
if options[:order_by_2]
|
232
|
-
id_2 = history[options[:order_by_2]]
|
233
|
-
acct_hash[id_1][id_2] ||= Hash.new
|
234
|
-
|
235
|
-
hash = acct_hash[id_1][id_2]
|
236
|
-
else
|
237
|
-
hash = acct_hash[id_1]
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
hash["HISTORY_RECORDS"] ||= Hash.new
|
242
|
-
hash["HISTORY_RECORDS"]["HISTORY"] ||= Array.new
|
243
|
-
hash["HISTORY_RECORDS"]["HISTORY"] << history.to_hash['HISTORY']
|
244
|
-
end
|
245
|
-
|
246
|
-
return rc if OpenNebula.is_error?(rc)
|
247
|
-
|
248
|
-
acct_hash
|
249
|
-
end
|
250
|
-
|
251
|
-
# Retrieves the accounting data for all the VMs in the pool in xml
|
252
|
-
#
|
253
|
-
# @param [Integer] filter_flag Optional filter flag to retrieve all or
|
254
|
-
# part of the Pool. Possible values: INFO_ALL, INFO_GROUP, INFO_MINE
|
255
|
-
# or user_id
|
256
|
-
# @param [Hash] options
|
257
|
-
# @option params [Integer] :start_time Start date and time to take into account,
|
258
|
-
# if no start_time is required use -1
|
259
|
-
# @option params [Integer] :end_time End date and time to take into account,
|
260
|
-
# if no end_time is required use -1
|
261
|
-
# @option params [Integer] :host Host id to filter the results
|
262
|
-
# @option params [Integer] :group Group id to filter the results
|
263
|
-
# @option params [String] :xpath Xpath expression to filter the results.
|
264
|
-
# For example: HISTORY[ETIME>0]
|
265
|
-
#
|
266
|
-
# @return [String] the xml representing the accounting data
|
267
|
-
def accounting_xml(filter_flag=INFO_ALL, options={})
|
268
|
-
acct_hash = Hash.new
|
269
|
-
xml_str = "<HISTORY_RECORDS>\n"
|
270
|
-
|
271
|
-
rc = build_accounting(filter_flag, options) do |history|
|
272
|
-
xml_str << history.to_xml
|
273
|
-
end
|
274
|
-
|
275
|
-
return rc if OpenNebula.is_error?(rc)
|
276
|
-
|
277
|
-
xml_str << "\n</HISTORY_RECORDS>"
|
278
|
-
xml_str
|
279
|
-
end
|
280
|
-
|
281
|
-
private
|
282
|
-
|
283
|
-
def build_accounting(filter_flag, options, &block)
|
284
|
-
xml_str = @client.call(VM_POOL_METHODS[:accounting],
|
285
|
-
filter_flag,
|
286
|
-
options[:start_time],
|
287
|
-
options[:end_time])
|
288
|
-
|
289
|
-
return xml_str if OpenNebula.is_error?(xml_str)
|
290
|
-
|
291
|
-
xmldoc = XMLElement.new
|
292
|
-
xmldoc.initialize_xml(xml_str, 'HISTORY_RECORDS')
|
293
|
-
|
294
|
-
xpath_array = Array.new
|
295
|
-
xpath_array << "HISTORY[HID=#{options[:host]}]" if options[:host]
|
296
|
-
xpath_array << "HISTORY[VM/GID=#{options[:group]}]" if options[:group]
|
297
|
-
xpath_array << options[:xpath] if options[:xpath]
|
298
|
-
|
299
|
-
if xpath_array.empty?
|
300
|
-
xpath_str = "HISTORY"
|
301
|
-
else
|
302
|
-
xpath_str = xpath_array.join(' | ')
|
303
|
-
end
|
304
|
-
|
305
|
-
acct_hash = Hash.new
|
306
|
-
|
307
|
-
xmldoc.each(xpath_str) do |history|
|
308
|
-
block.call(history)
|
309
|
-
end
|
310
|
-
|
311
|
-
acct_hash
|
312
|
-
end
|
313
|
-
|
314
|
-
def info_filter(xml_method, who, start_id, end_id, state)
|
315
|
-
return xmlrpc_info(xml_method, who, start_id, end_id, state)
|
316
|
-
end
|
317
|
-
end
|
318
|
-
end
|
@@ -1,247 +0,0 @@
|
|
1
|
-
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
3
|
-
# #
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
|
-
# not use this file except in compliance with the License. You may obtain #
|
6
|
-
# a copy of the License at #
|
7
|
-
# #
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0 #
|
9
|
-
# #
|
10
|
-
# Unless required by applicable law or agreed to in writing, software #
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS, #
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
13
|
-
# See the License for the specific language governing permissions and #
|
14
|
-
# limitations under the License. #
|
15
|
-
#--------------------------------------------------------------------------- #
|
16
|
-
|
17
|
-
|
18
|
-
require 'opennebula/pool_element'
|
19
|
-
|
20
|
-
module OpenNebula
|
21
|
-
class VirtualNetwork < PoolElement
|
22
|
-
#######################################################################
|
23
|
-
# Constants and Class Methods
|
24
|
-
#######################################################################
|
25
|
-
|
26
|
-
|
27
|
-
VN_METHODS = {
|
28
|
-
:info => "vn.info",
|
29
|
-
:allocate => "vn.allocate",
|
30
|
-
:delete => "vn.delete",
|
31
|
-
:addleases => "vn.addleases",
|
32
|
-
:rmleases => "vn.rmleases",
|
33
|
-
:chown => "vn.chown",
|
34
|
-
:chmod => "vn.chmod",
|
35
|
-
:update => "vn.update",
|
36
|
-
:hold => "vn.hold",
|
37
|
-
:release => "vn.release",
|
38
|
-
:rename => "vn.rename"
|
39
|
-
}
|
40
|
-
|
41
|
-
VN_TYPES=%w{RANGED FIXED}
|
42
|
-
|
43
|
-
SHORT_VN_TYPES={
|
44
|
-
"RANGED" => "R",
|
45
|
-
"FIXED" => "F"
|
46
|
-
}
|
47
|
-
|
48
|
-
# Creates a VirtualNetwork description with just its identifier
|
49
|
-
# this method should be used to create plain VirtualNetwork objects.
|
50
|
-
# +id+ the id of the network
|
51
|
-
#
|
52
|
-
# Example:
|
53
|
-
# vnet = VirtualNetwork.new(VirtualNetwork.build_xml(3),rpc_client)
|
54
|
-
#
|
55
|
-
def VirtualNetwork.build_xml(pe_id=nil)
|
56
|
-
if pe_id
|
57
|
-
vn_xml = "<VNET><ID>#{pe_id}</ID></VNET>"
|
58
|
-
else
|
59
|
-
vn_xml = "<VNET></VNET>"
|
60
|
-
end
|
61
|
-
|
62
|
-
XMLElement.build_xml(vn_xml, 'VNET')
|
63
|
-
end
|
64
|
-
|
65
|
-
# Class constructor
|
66
|
-
def initialize(xml, client)
|
67
|
-
super(xml,client)
|
68
|
-
end
|
69
|
-
|
70
|
-
#######################################################################
|
71
|
-
# XML-RPC Methods for the Virtual Network Object
|
72
|
-
#######################################################################
|
73
|
-
|
74
|
-
# Retrieves the information of the given VirtualNetwork.
|
75
|
-
def info()
|
76
|
-
super(VN_METHODS[:info], 'VNET')
|
77
|
-
end
|
78
|
-
|
79
|
-
# Allocates a new VirtualNetwork in OpenNebula
|
80
|
-
#
|
81
|
-
# @param description [String] The template of the VirtualNetwork.
|
82
|
-
# @param cluster_id [Integer] Id of the cluster
|
83
|
-
#
|
84
|
-
# @return [Integer, OpenNebula::Error] the new ID in case of
|
85
|
-
# success, error otherwise
|
86
|
-
def allocate(description,cluster_id=ClusterPool::NONE_CLUSTER_ID)
|
87
|
-
super(VN_METHODS[:allocate], description, cluster_id)
|
88
|
-
end
|
89
|
-
|
90
|
-
# Replaces the template contents
|
91
|
-
#
|
92
|
-
# +new_template+ New template contents. If no argument is provided
|
93
|
-
# the object will be updated using the @xml variable
|
94
|
-
def update(new_template=nil)
|
95
|
-
super(VN_METHODS[:update], new_template)
|
96
|
-
end
|
97
|
-
|
98
|
-
# Publishes the VirtualNetwork, to be used by other users
|
99
|
-
def publish
|
100
|
-
set_publish(true)
|
101
|
-
end
|
102
|
-
|
103
|
-
# Unplubishes the VirtualNetwork
|
104
|
-
def unpublish
|
105
|
-
set_publish(false)
|
106
|
-
end
|
107
|
-
|
108
|
-
# Deletes the VirtualNetwork
|
109
|
-
def delete()
|
110
|
-
super(VN_METHODS[:delete])
|
111
|
-
end
|
112
|
-
|
113
|
-
# Adds a lease to the VirtualNetwork
|
114
|
-
def addleases(ip, mac = nil)
|
115
|
-
return Error.new('ID not defined') if !@pe_id
|
116
|
-
|
117
|
-
lease_template = "LEASES = [ IP = #{ip}"
|
118
|
-
lease_template << ", MAC = #{mac}" if mac
|
119
|
-
lease_template << " ]"
|
120
|
-
|
121
|
-
rc = @client.call(VN_METHODS[:addleases], @pe_id, lease_template)
|
122
|
-
rc = nil if !OpenNebula.is_error?(rc)
|
123
|
-
|
124
|
-
return rc
|
125
|
-
end
|
126
|
-
|
127
|
-
# Removes a lease from the VirtualNetwork
|
128
|
-
def rmleases(ip)
|
129
|
-
return Error.new('ID not defined') if !@pe_id
|
130
|
-
|
131
|
-
lease_template = "LEASES = [ IP = #{ip} ]"
|
132
|
-
|
133
|
-
rc = @client.call(VN_METHODS[:rmleases], @pe_id, lease_template)
|
134
|
-
rc = nil if !OpenNebula.is_error?(rc)
|
135
|
-
|
136
|
-
return rc
|
137
|
-
end
|
138
|
-
|
139
|
-
# Holds a virtual network Lease as used
|
140
|
-
# @param ip [String] IP to hold
|
141
|
-
def hold(ip)
|
142
|
-
return Error.new('ID not defined') if !@pe_id
|
143
|
-
|
144
|
-
lease_template = "LEASES = [ IP = #{ip} ]"
|
145
|
-
|
146
|
-
rc = @client.call(VN_METHODS[:hold], @pe_id, lease_template)
|
147
|
-
rc = nil if !OpenNebula.is_error?(rc)
|
148
|
-
|
149
|
-
return rc
|
150
|
-
end
|
151
|
-
|
152
|
-
# Releases a virtual network Lease on hold
|
153
|
-
# @param ip [String] IP to release
|
154
|
-
def release(ip)
|
155
|
-
return Error.new('ID not defined') if !@pe_id
|
156
|
-
|
157
|
-
lease_template = "LEASES = [ IP = #{ip} ]"
|
158
|
-
|
159
|
-
rc = @client.call(VN_METHODS[:release], @pe_id, lease_template)
|
160
|
-
rc = nil if !OpenNebula.is_error?(rc)
|
161
|
-
|
162
|
-
return rc
|
163
|
-
end
|
164
|
-
|
165
|
-
# Changes the owner/group
|
166
|
-
#
|
167
|
-
# @param uid [Integer] the new owner id. Set to -1 to leave the current one
|
168
|
-
# @param gid [Integer] the new group id. Set to -1 to leave the current one
|
169
|
-
#
|
170
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
171
|
-
# otherwise
|
172
|
-
def chown(uid, gid)
|
173
|
-
super(VN_METHODS[:chown], uid, gid)
|
174
|
-
end
|
175
|
-
|
176
|
-
# Changes the virtual network permissions.
|
177
|
-
#
|
178
|
-
# @param octet [String] Permissions octed , e.g. 640
|
179
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
180
|
-
# otherwise
|
181
|
-
def chmod_octet(octet)
|
182
|
-
super(VN_METHODS[:chmod], octet)
|
183
|
-
end
|
184
|
-
|
185
|
-
# Changes the virtual network permissions.
|
186
|
-
# Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
|
187
|
-
#
|
188
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
189
|
-
# otherwise
|
190
|
-
def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
191
|
-
other_m, other_a)
|
192
|
-
super(VN_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
|
193
|
-
group_m, group_a, other_u, other_m, other_a)
|
194
|
-
end
|
195
|
-
|
196
|
-
# Renames this virtual network
|
197
|
-
#
|
198
|
-
# @param name [String] New name for the virtual network.
|
199
|
-
#
|
200
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
201
|
-
# otherwise
|
202
|
-
def rename(name)
|
203
|
-
return call(VN_METHODS[:rename], @pe_id, name)
|
204
|
-
end
|
205
|
-
|
206
|
-
#######################################################################
|
207
|
-
# Helpers to get VirtualNetwork information
|
208
|
-
#######################################################################
|
209
|
-
|
210
|
-
# Returns the group identifier
|
211
|
-
# [return] _Integer_ the element's group ID
|
212
|
-
def gid
|
213
|
-
self['GID'].to_i
|
214
|
-
end
|
215
|
-
|
216
|
-
# Returns the type of the Virtual Network (numeric value)
|
217
|
-
def type
|
218
|
-
self['TYPE'].to_i
|
219
|
-
end
|
220
|
-
|
221
|
-
# Returns the type of the Virtual Network (string value)
|
222
|
-
def type_str
|
223
|
-
VN_TYPES[type]
|
224
|
-
end
|
225
|
-
|
226
|
-
# Returns the state of the Virtual Network (string value)
|
227
|
-
def short_type_str
|
228
|
-
SHORT_VN_TYPES[type_str]
|
229
|
-
end
|
230
|
-
|
231
|
-
def public?
|
232
|
-
if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
|
233
|
-
true
|
234
|
-
else
|
235
|
-
false
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
private
|
240
|
-
def set_publish(published)
|
241
|
-
group_u = published ? 1 : 0
|
242
|
-
|
243
|
-
chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1)
|
244
|
-
end
|
245
|
-
|
246
|
-
end
|
247
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
3
|
-
# #
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
|
-
# not use this file except in compliance with the License. You may obtain #
|
6
|
-
# a copy of the License at #
|
7
|
-
# #
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0 #
|
9
|
-
# #
|
10
|
-
# Unless required by applicable law or agreed to in writing, software #
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS, #
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
13
|
-
# See the License for the specific language governing permissions and #
|
14
|
-
# limitations under the License. #
|
15
|
-
#--------------------------------------------------------------------------- #
|
16
|
-
|
17
|
-
|
18
|
-
require 'opennebula/pool'
|
19
|
-
|
20
|
-
module OpenNebula
|
21
|
-
class VirtualNetworkPool < Pool
|
22
|
-
#######################################################################
|
23
|
-
# Constants and Class attribute accessors
|
24
|
-
#######################################################################
|
25
|
-
|
26
|
-
|
27
|
-
VN_POOL_METHODS = {
|
28
|
-
:info => "vnpool.info"
|
29
|
-
}
|
30
|
-
|
31
|
-
#######################################################################
|
32
|
-
# Class constructor & Pool Methods
|
33
|
-
#######################################################################
|
34
|
-
|
35
|
-
# +client+ a Client object that represents a XML-RPC connection
|
36
|
-
# +user_id+ is to refer to a Pool with VirtualNetworks from that user
|
37
|
-
def initialize(client, user_id=0)
|
38
|
-
super('VNET_POOL','VNET',client)
|
39
|
-
|
40
|
-
@user_id = user_id
|
41
|
-
end
|
42
|
-
|
43
|
-
# Default Factory Method for the Pools
|
44
|
-
def factory(element_xml)
|
45
|
-
OpenNebula::VirtualNetwork.new(element_xml,@client)
|
46
|
-
end
|
47
|
-
|
48
|
-
#######################################################################
|
49
|
-
# XML-RPC Methods for the Virtual Network Object
|
50
|
-
#######################################################################
|
51
|
-
|
52
|
-
# Retrieves all or part of the VirtualMachines in the pool.
|
53
|
-
def info(*args)
|
54
|
-
case args.size
|
55
|
-
when 0
|
56
|
-
info_filter(VN_POOL_METHODS[:info],@user_id,-1,-1)
|
57
|
-
when 3
|
58
|
-
info_filter(VN_POOL_METHODS[:info],args[0],args[1],args[2])
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def info_all()
|
63
|
-
return super(VN_POOL_METHODS[:info])
|
64
|
-
end
|
65
|
-
|
66
|
-
def info_mine()
|
67
|
-
return super(VN_POOL_METHODS[:info])
|
68
|
-
end
|
69
|
-
|
70
|
-
def info_group()
|
71
|
-
return super(VN_POOL_METHODS[:info])
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|