opennebula 5.2.1 → 5.3.80.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a03807dc5cd00c6e5a42fe341caa95a84a5734b7
4
- data.tar.gz: 8c4bd35f71422c0f168616d4d32422aee5feef69
3
+ metadata.gz: 793beff44dc5a782c2aafcfc3049362b981f972b
4
+ data.tar.gz: ed04d3cf4814a0715471a99342cf04811ad86520
5
5
  SHA512:
6
- metadata.gz: 40a1c600b081b6190144d8ec8110b1dbf6a829e83cad138d08119621dfa958632a5918e12bdc0565e877b1d11b03faf2cbaddce40bc9fa1a5a613bd800f3c816
7
- data.tar.gz: 928962cd78fcd5353ffcacb009e6b2ac7326345abe1cd4e6a4f2f844f350ab9d9b5defc203066b6e144374874e0dfbc62a93e20bceca2879279d1a311a0edeee
6
+ metadata.gz: c892fa6c7a0f2012185c432eae4b7954ed3500f35962e4b5d453279db3c702f716d27fed588ae653cf383d7d8eede5dd4ecb55534bbc62d1c46033b75b452161
7
+ data.tar.gz: e751d6869d55f43512f28746bf0f4d98b8e0cdb67576263b5577a676013823286e020a05bd45109937198f4209f5fe6240812d9790009f52bd291c4b6a22e56e
@@ -50,6 +50,7 @@ class VirtualMachineDriver < OpenNebulaDriver
50
50
  :attach_nic => "ATTACHNIC",
51
51
  :detach_nic => "DETACHNIC",
52
52
  :disk_snapshot_create => "DISKSNAPSHOTCREATE",
53
+ :resize_disk => "RESIZEDISK",
53
54
  :update_sg => "UPDATESG"
54
55
  }
55
56
 
@@ -93,6 +94,7 @@ class VirtualMachineDriver < OpenNebulaDriver
93
94
  register_action(ACTION[:attach_nic].to_sym, method("attach_nic"))
94
95
  register_action(ACTION[:detach_nic].to_sym, method("detach_nic"))
95
96
  register_action(ACTION[:disk_snapshot_create].to_sym, method("disk_snapshot_create"))
97
+ register_action(ACTION[:resize_disk].to_sym, method("resize_disk"))
96
98
  register_action(ACTION[:update_sg].to_sym, method("update_sg"))
97
99
  end
98
100
 
@@ -203,6 +205,11 @@ class VirtualMachineDriver < OpenNebulaDriver
203
205
  send_message(ACTION[:disk_snapshot_create],RESULT[:failure],id,error)
204
206
  end
205
207
 
208
+ def resize_disk(id, drv_message)
209
+ error = "Action not implemented by driver #{self.class}"
210
+ send_message(ACTION[:resize_disk],RESULT[:failure],id,error)
211
+ end
212
+
206
213
  def update_sg(id, drv_message)
207
214
  error = "Action not implemented by driver #{self.class}"
208
215
  send_message(ACTION[:update_sg],RESULT[:failure],id,error)
@@ -50,7 +50,7 @@ end
50
50
  module CloudClient
51
51
 
52
52
  # OpenNebula version
53
- VERSION = '5.2.1'
53
+ VERSION = '5.3.80'
54
54
 
55
55
  # #########################################################################
56
56
  # Default location for the authentication file
@@ -23,19 +23,23 @@ module OpenNebula
23
23
  # @<num>
24
24
  # ALL
25
25
  # RESOURCE -> + separated list and "/{#,@,%}<num>|ALL"
26
- # VM,
26
+ # VM
27
27
  # HOST
28
28
  # NET
29
29
  # IMAGE
30
30
  # USER
31
31
  # TEMPLATE
32
32
  # GROUP
33
- # ACL
33
+ # DATASTORE
34
+ # CLUSTER
35
+ # DOCUMENT
36
+ # ZONE
34
37
  # SECGROUP
35
38
  # VDC
36
39
  # VROUTER
37
40
  # MARKETPLACE
38
41
  # MARKETPLACEAPP
42
+ # VMGROUP
39
43
  # RIGHTS -> + separated list
40
44
  # USE
41
45
  # MANAGE
@@ -67,7 +71,8 @@ module OpenNebula
67
71
  "VDC" => 0x2000000000000,
68
72
  "VROUTER" => 0x4000000000000,
69
73
  "MARKETPLACE" => 0x8000000000000,
70
- "MARKETPLACEAPP"=> 0x10000000000000
74
+ "MARKETPLACEAPP"=> 0x10000000000000,
75
+ "VMGROUP" => 0x20000000000000
71
76
  }
72
77
 
73
78
  RIGHTS =
@@ -201,7 +201,7 @@ module OpenNebula
201
201
  response[1] #response[1..-1]
202
202
  end
203
203
  rescue Exception => e
204
- Error.new(e.message)
204
+ Error.new(e.message, Error::EXML_RPC_CALL)
205
205
  end
206
206
  end
207
207
 
@@ -28,8 +28,10 @@ module OpenNebula
28
28
  EACTION = 0x0800
29
29
  EXML_RPC_API = 0x1000
30
30
  EINTERNAL = 0x2000
31
- ENOTDEFINED = 0x1111
32
-
31
+ EALLOCATE = 0x4000
32
+ ENOTDEFINED = 0xF001
33
+ EXML_RPC_CALL = 0xF002
34
+
33
35
  attr_reader :message, :errno
34
36
 
35
37
  # +message+ Description of the error
@@ -42,6 +44,11 @@ module OpenNebula
42
44
  def to_str()
43
45
  @message
44
46
  end
47
+
48
+ def is_exml_rpc_call?()
49
+ @errno == EXML_RPC_CALL
50
+ end
51
+
45
52
  end
46
53
 
47
54
  # Returns true if the object returned by a method of the OpenNebula
@@ -49,4 +56,5 @@ module OpenNebula
49
56
  def self.is_error?(value)
50
57
  value.class==OpenNebula::Error
51
58
  end
59
+
52
60
  end
@@ -37,7 +37,7 @@ module OpenNebula
37
37
  SELF = -1
38
38
 
39
39
  # Default resource ACL's for group users (create)
40
- GROUP_DEFAULT_ACLS = "VM+IMAGE+TEMPLATE+DOCUMENT+SECGROUP+VROUTER"
40
+ GROUP_DEFAULT_ACLS = "VM+IMAGE+TEMPLATE+DOCUMENT+SECGROUP+VROUTER+VMGROUP"
41
41
 
42
42
  # The default view for group and group admins, must be defined in
43
43
  # sunstone_views.yaml
@@ -104,14 +104,14 @@ module OpenNebula
104
104
  end
105
105
 
106
106
  # Allocate group
107
- rc = self.allocate(group_hash[:name])
107
+ rc = allocate(group_hash[:name])
108
108
  return rc if OpenNebula.is_error?(rc)
109
109
 
110
110
  # Set group ACLs to create resources
111
111
  rc, msg = create_default_acls(group_hash[:resources])
112
112
 
113
113
  if OpenNebula.is_error?(rc)
114
- self.delete
114
+ delete
115
115
  error_msg = "Error creating group ACL's: #{rc.message}"
116
116
  return OpenNebula::Error.new(error_msg)
117
117
  end
@@ -119,7 +119,7 @@ module OpenNebula
119
119
  # Set group ACLs to share resources
120
120
  if group_hash[:shared_resources]
121
121
  acls = Array.new
122
- acls << "@#{self.id} #{group_hash[:shared_resources]}/@#{self.id} USE"
122
+ acls << "@#{id} #{group_hash[:shared_resources]}/@#{id} USE"
123
123
 
124
124
  rc, msg = create_group_acls(acls)
125
125
 
@@ -134,7 +134,7 @@ module OpenNebula
134
134
  rc = create_admin_user(group_hash)
135
135
 
136
136
  if OpenNebula.is_error?(rc)
137
- self.delete
137
+ delete
138
138
  error_msg = "Error creating admin user: #{rc.message}"
139
139
  return OpenNebula::Error.new(error_msg)
140
140
  end
@@ -163,10 +163,40 @@ module OpenNebula
163
163
  sunstone_attrs << "GROUP_ADMIN_DEFAULT_VIEW=#{GROUP_ADMIN_SUNSTONE_VIEWS}"
164
164
  end
165
165
 
166
+ do_update = false
167
+
166
168
  if sunstone_attrs.length > 0
167
- rc = self.update("SUNSTONE=[#{sunstone_attrs.join(",\n")}]", true)
169
+ do_update = true
170
+
171
+ update_str = "SUNSTONE=[#{sunstone_attrs.join(",\n")}]\n"
172
+ end
173
+
174
+ opennebula_attrs = []
175
+
176
+ # Persistency attributes for new images
177
+ if group_hash[:opennebula]
178
+ if group_hash[:opennebula][:default_image_persistent]
179
+ opennebula_attrs << "DEFAULT_IMAGE_PERSISTENT=\""\
180
+ "#{group_hash[:opennebula][:default_image_persistent]}\""
181
+ end
182
+
183
+ if group_hash[:opennebula][:default_image_persistent_new]
184
+ opennebula_attrs << "DEFAULT_IMAGE_PERSISTENT_NEW=\""\
185
+ "#{group_hash[:opennebula][:default_image_persistent_new]}\""
186
+ end
187
+ end
188
+
189
+ if opennebula_attrs.length > 0
190
+ do_update = true
191
+
192
+ update_str += "OPENNEBULA=[#{opennebula_attrs.join(",\n")}]\n"
193
+ end
194
+
195
+ if do_update
196
+ rc = update(update_str, true)
197
+
168
198
  if OpenNebula.is_error?(rc)
169
- self.delete
199
+ delete
170
200
  error_msg = "Error updating group template: #{rc.message}"
171
201
  return OpenNebula::Error.new(error_msg)
172
202
  end
@@ -223,12 +223,23 @@ module OpenNebula
223
223
  xml = OpenNebula::VirtualMachine.build_xml
224
224
  vm = OpenNebula::VirtualMachine.new(xml, @client)
225
225
 
226
- rc = vm.allocate(template)
226
+ # vCenter wild VMs has a different process
227
+ # image and vnets objects representing existing nics and disks
228
+ # must be created and referenced
229
+ vcenter_wild_vm = wild.key? "VCENTER_TEMPLATE"
230
+ if vcenter_wild_vm
231
+ require 'vcenter_driver'
232
+ host_id = self["ID"]
233
+ vm_ref = wild["DEPLOY_ID"]
234
+ return VCenterDriver::Importer.import_wild(host_id, vm_ref, vm, template)
235
+ else
236
+ rc = vm.allocate(template)
227
237
 
228
- return rc if OpenNebula.is_error?(rc)
238
+ return rc if OpenNebula.is_error?(rc)
229
239
 
230
- vm.deploy(id, false)
231
- return vm.id
240
+ vm.deploy(id, false)
241
+ return vm.id
242
+ end
232
243
  end
233
244
 
234
245
  #######################################################################
@@ -39,12 +39,13 @@ class OpenNebula::ServerCipherAuth
39
39
  @srv_passwd = srv_passwd
40
40
 
41
41
  if !srv_passwd.empty?
42
- @key = Digest::SHA1.hexdigest(@srv_passwd)
42
+ # truncate token to 32-bytes for Ruby >= 2.4
43
+ @key = Digest::SHA1.hexdigest(@srv_passwd)[0..31]
43
44
  else
44
45
  @key = ""
45
46
  end
46
47
 
47
- @cipher = OpenSSL::Cipher::Cipher.new(CIPHER)
48
+ @cipher = OpenSSL::Cipher.new(CIPHER)
48
49
  end
49
50
 
50
51
  ###########################################################################
@@ -109,7 +110,8 @@ class OpenNebula::ServerCipherAuth
109
110
  # auth method for auth_mad
110
111
  def authenticate(srv_user,srv_pass, signed_text)
111
112
  begin
112
- @key = srv_pass
113
+ # truncate token to 32-bytes for Ruby >= 2.4
114
+ @key = srv_pass[0..31]
113
115
 
114
116
  s_user, t_user, expires = decrypt(signed_text).split(':')
115
117
 
@@ -29,7 +29,8 @@ module OpenNebula
29
29
  :groupquotainfo => "groupquota.info",
30
30
  :groupquotaupdate => "groupquota.update",
31
31
  :version => "system.version",
32
- :config => "system.config"
32
+ :config => "system.config",
33
+ :sql => "system.sql"
33
34
  }
34
35
 
35
36
  #######################################################################
@@ -46,6 +47,17 @@ module OpenNebula
46
47
  # XML-RPC Methods
47
48
  #######################################################################
48
49
 
50
+ # Executes and replicates SQL commands on OpenNebula DB
51
+ # @param [String] Sql string
52
+ # @param [Boolean] True to replicate command on a federation. To
53
+ # operate on federated tables
54
+ # @return [Integer, OpenNebula::Error] Sql execution result in case
55
+ # of success, Error otherwise
56
+ def sql_command(sql, federate)
57
+ return @client.call(SYSTEM_METHODS[:sql], sql, federate)
58
+ end
59
+
60
+ #
49
61
  # Gets the oned version
50
62
  #
51
63
  # @return [String, OpenNebula::Error] the oned version in case
@@ -47,6 +47,7 @@ module OpenNebula
47
47
  :disksnapshotcreate => "vm.disksnapshotcreate",
48
48
  :disksnapshotrevert => "vm.disksnapshotrevert",
49
49
  :disksnapshotdelete => "vm.disksnapshotdelete",
50
+ :diskresize => "vm.diskresize",
50
51
  :updateconf => "vm.updateconf"
51
52
  }
52
53
 
@@ -116,6 +117,9 @@ module OpenNebula
116
117
  DISK_SNAPSHOT_DELETE
117
118
  PROLOG_MIGRATE_UNKNOWN
118
119
  PROLOG_MIGRATE_UNKNOWN_FAILURE
120
+ DISK_RESIZE
121
+ DISK_RESIZE_POWEROFF
122
+ DISK_RESIZE_UNDEPLOYED
119
123
  }
120
124
 
121
125
  SHORT_VM_STATES={
@@ -193,26 +197,25 @@ module OpenNebula
193
197
  "DISK_SNAPSHOT" => "snap",
194
198
  "DISK_SNAPSHOT_DELETE" => "snap",
195
199
  "PROLOG_MIGRATE_UNKNOWN" => "migr",
196
- "PROLOG_MIGRATE_UNKNOWN_FAILURE" => "fail"
197
- }
198
-
199
- MIGRATE_REASON=%w{NONE ERROR USER}
200
-
201
- SHORT_MIGRATE_REASON={
202
- "NONE" => "none",
203
- "ERROR" => "erro",
204
- "USER" => "user"
200
+ "PROLOG_MIGRATE_UNKNOWN_FAILURE" => "fail",
201
+ "DISK_RESIZE" => "drsz",
202
+ "DISK_RESIZE_POWEROFF" => "drsz",
203
+ "DISK_RESIZE_UNDEPLOYED" => "drsz"
205
204
  }
206
205
 
207
206
  HISTORY_ACTION=%w{none migrate live-migrate shutdown shutdown-hard
208
207
  undeploy undeploy-hard hold release stop suspend resume boot delete
209
208
  delete-recreate reboot reboot-hard resched unresched poweroff
210
209
  poweroff-hard disk-attach disk-detach nic-attach nic-detach
211
- snap-create snap-delete terminate terminate-hard}
210
+ disk-snapshot-create disk-snapshot-delete terminate terminate-hard
211
+ disk-resize deploy chown chmod updateconf rename resize update
212
+ snapshot-resize snapshot-delete snapshot-revert disk-saveas
213
+ disk-snapshot-revert recover retry monitor}
212
214
 
213
215
  EXTERNAL_IP_ATTRS = [
214
216
  'GUEST_IP',
215
217
  'AWS_IP_ADDRESS',
218
+ 'AWS_PUBLIC_IP_ADDRESS',
216
219
  'AWS_PRIVATE_IP_ADDRESS',
217
220
  'AZ_IPADDRESS',
218
221
  'SL_PRIMARYIPADDRESS'
@@ -256,13 +259,6 @@ module OpenNebula
256
259
  XMLElement.build_xml(vm_xml, 'VM')
257
260
  end
258
261
 
259
- def VirtualMachine.get_reason(reason)
260
- reason=MIGRATE_REASON[reason.to_i]
261
- reason_str=SHORT_MIGRATE_REASON[reason]
262
-
263
- reason_str
264
- end
265
-
266
262
  def VirtualMachine.get_history_action(action)
267
263
  return HISTORY_ACTION[action.to_i]
268
264
  end
@@ -354,7 +350,7 @@ module OpenNebula
354
350
  ds = OpenNebula::Datastore.new_with_id(ds_id, @client)
355
351
  rc = ds.info
356
352
  return rc if OpenNebula.is_error?(rc)
357
- self.update("VCENTER_DATASTORE=#{ds['/DATASTORE/NAME']}", true)
353
+ self.update("VCENTER_DS_REF=#{ds['/DATASTORE/VCENTER_DS_REF']}", true)
358
354
  end
359
355
 
360
356
  return call(VM_METHODS[:deploy],
@@ -659,6 +655,16 @@ module OpenNebula
659
655
  return call(VM_METHODS[:disksnapshotdelete], @pe_id, disk_id, snap_id)
660
656
  end
661
657
 
658
+ # Changes the size of a disk
659
+ #
660
+ # @param disk_id [Integer] Id of the disk
661
+ # @param size [Integer] new size in MiB
662
+ #
663
+ # @return [nil, OpenNebula::Error] nil in case of success or error
664
+ def disk_resize(disk_id, size)
665
+ return call(VM_METHODS[:diskresize], @pe_id, disk_id, size.to_s)
666
+ end
667
+
662
668
  # Recovers an ACTIVE VM
663
669
  #
664
670
  # @param result [Integer] Recover with failure (0), success (1),
@@ -739,13 +745,6 @@ module OpenNebula
739
745
  self['DEPLOY_ID']
740
746
  end
741
747
 
742
- # Returns the deploy_id of the VirtualMachine (numeric value)
743
- def keep_disks?
744
- !self['USER_TEMPLATE/KEEP_DISKS_ON_DONE'].nil? &&
745
- self['USER_TEMPLATE/KEEP_DISKS_ON_DONE'].downcase=="yes"
746
- end
747
-
748
-
749
748
  # Clones the VM's source Template, replacing the disks with live snapshots
750
749
  # of the current disks. The VM capacity and NICs are also preserved
751
750
  #
@@ -755,6 +754,7 @@ module OpenNebula
755
754
  #
756
755
  # @return [Integer, OpenNebula::Error] the new Template ID in case of
757
756
  # success, error otherwise
757
+ REMOVE_VNET_ATTRS = %w{AR_ID BRIDGE CLUSTER_ID IP MAC TARGET NIC_ID NETWORK_ID VN_MAD SECURITY_GROUPS}
758
758
  def save_as_template(name, persistent=nil)
759
759
  img_ids = []
760
760
  new_tid = nil
@@ -852,21 +852,18 @@ module OpenNebula
852
852
  end
853
853
 
854
854
  self.each('TEMPLATE/NIC') do |nic|
855
+
855
856
  nic_id = nic["NIC_ID"]
856
857
  if nic_id.nil? || nic_id.empty?
857
858
  rc = Error.new('The NIC_ID is missing from the VM template')
858
859
  raise
859
860
  end
860
-
861
- net_id = nic["NETWORK_ID"]
862
-
863
- if !net_id.nil? && !net_id.empty?
864
- replace << "NIC = [ NETWORK_ID = #{net_id} ]\n"
865
- else
866
- # This NIC does not use a Virtual Network
867
- replace << self.template_like_str(
868
- "TEMPLATE", true, "NIC[NIC_ID=#{nic_id}]") << "\n"
861
+ REMOVE_VNET_ATTRS.each do |attr|
862
+ nic.delete_element(attr)
869
863
  end
864
+
865
+ replace << self.template_like_str(
866
+ "TEMPLATE", true, "NIC[#{nic}]") << "\n"
870
867
  end
871
868
 
872
869
  # Required by the Sunstone Cloud View
@@ -16,6 +16,7 @@
16
16
 
17
17
 
18
18
  require 'opennebula/pool_element'
19
+ require 'ipaddr'
19
20
 
20
21
  module OpenNebula
21
22
  class VirtualNetwork < PoolElement
@@ -184,11 +185,9 @@ module OpenNebula
184
185
  def hold(ip, ar_id=-1)
185
186
  return Error.new('ID not defined') if !@pe_id
186
187
 
187
- if ip.include?':'
188
- addr_name = "MAC"
189
- else
190
- addr_name = "IP"
191
- end
188
+ addr_name = address_type(ip)
189
+
190
+ return addr_name if OpenNebula.is_error?(addr_name)
192
191
 
193
192
  lease_template = "LEASES = [ #{addr_name} = #{ip}"
194
193
  lease_template << ", AR_ID = #{ar_id}" if ar_id != -1
@@ -207,11 +206,9 @@ module OpenNebula
207
206
  def release(ip, ar_id=-1)
208
207
  return Error.new('ID not defined') if !@pe_id
209
208
 
210
- if ip.include?':'
211
- addr_name = "MAC"
212
- else
213
- addr_name = "IP"
214
- end
209
+ addr_name = address_type(ip)
210
+
211
+ return addr_name if OpenNebula.is_error?(addr_name)
215
212
 
216
213
  lease_template = "LEASES = [ #{addr_name} = #{ip}"
217
214
  lease_template << ", AR_ID = #{ar_id}" if ar_id != -1
@@ -243,11 +240,9 @@ module OpenNebula
243
240
  rtmpl << "NETWORK_ID = #{vnet}\n" if !vnet.nil?
244
241
 
245
242
  if !addr.nil?
246
- if addr.include?':'
247
- addr_name = "MAC"
248
- else
249
- addr_name = "IP"
250
- end
243
+ addr_name = address_type(addr)
244
+
245
+ return addr_name if OpenNebula.is_error?(addr_name)
251
246
 
252
247
  rtmpl << "#{addr_name} = #{addr}\n"
253
248
  end
@@ -342,5 +337,27 @@ module OpenNebula
342
337
  chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1)
343
338
  end
344
339
 
340
+ # Returns the OpenNebula name of the address to use it in LEASE
341
+ # attributes. MAC, IP or IP6 is returned for MAC addresses in colon
342
+ # notation, ipv4 and ipv6 respectively
343
+ def address_type(addr)
344
+ begin
345
+ ipaddr = IPAddr.new addr
346
+
347
+ if ipaddr.ipv4?
348
+ return "IP"
349
+ elsif ipaddr.ipv6?
350
+ return "IP6"
351
+ else
352
+ return Error.new('Unknown IP type')
353
+ end
354
+ rescue
355
+ if /^(\h{2}:){5}\h{2}$/ =~ addr
356
+ return "MAC"
357
+ else
358
+ return Error.new('Unknown address type')
359
+ end
360
+ end
361
+ end
345
362
  end
346
363
  end
@@ -0,0 +1,151 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2017, OpenNebula Project, OpenNebula Systems #
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
+ require 'opennebula/pool_element'
18
+
19
+ module OpenNebula
20
+ class VMGroup < PoolElement
21
+ #######################################################################
22
+ # Constants and Class Methods
23
+ #######################################################################
24
+ VMGROUP_METHODS = {
25
+ :allocate => "vmgroup.allocate",
26
+ :info => "vmgroup.info",
27
+ :update => "vmgroup.update",
28
+ :delete => "vmgroup.delete",
29
+ :chown => "vmgroup.chown",
30
+ :chmod => "vmgroup.chmod",
31
+ :rename => "vmgroup.rename"
32
+ }
33
+
34
+ # Creates a VMGroup description with just its identifier
35
+ # this method should be used to create plain VMGroup objects.
36
+ # @param pe_id [Integer] the id of the object
37
+ def VMGroup.build_xml(pe_id=nil)
38
+ if pe_id
39
+ obj_xml = "<VM_GROUP><ID>#{pe_id}</ID></VM_GROUP>"
40
+ else
41
+ obj_xml = "<VM_GROUP></VM_GROUP>"
42
+ end
43
+
44
+ XMLElement.build_xml(obj_xml,'VM_GROUP')
45
+ end
46
+
47
+ # Class constructor
48
+ def initialize(xml, client)
49
+ super(xml,client)
50
+
51
+ @client = client
52
+ end
53
+
54
+ #######################################################################
55
+ # XML-RPC Methods for the VMGroup Object
56
+ #######################################################################
57
+
58
+ # Retrieves the information of the VMGroup.
59
+ def info()
60
+ super(VMGROUP_METHODS[:info], 'VM_GROUP')
61
+ end
62
+
63
+ alias_method :info!, :info
64
+
65
+ # Allocates a new VMGroup in OpenNebula
66
+ #
67
+ # @param description [String] The contents of the VMGroup.
68
+ #
69
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
70
+ # otherwise
71
+ def allocate(description)
72
+ super(VMGROUP_METHODS[:allocate], description)
73
+ end
74
+
75
+ # Deletes the SecurityGroup
76
+ def delete()
77
+ super(VMGROUP_METHODS[:delete])
78
+ end
79
+
80
+ # Replaces the vm group contents
81
+ #
82
+ # @param new_vmgroup [String] New vmgroup contents
83
+ # @param append [true, false] True to append new attributes instead of
84
+ # replace the whole securitygroup
85
+ #
86
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
87
+ # otherwise
88
+ def update(new_vmgroup, append=false)
89
+ super(VMGROUP_METHODS[:update], new_vmgroup, append ? 1 : 0)
90
+ end
91
+
92
+ # Changes the owner/group
93
+ #
94
+ # @param uid [Integer] the new owner id. Set to -1 to leave the current one
95
+ # @param gid [Integer] the new group id. Set to -1 to leave the current one
96
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
97
+ # otherwise
98
+ def chown(uid, gid)
99
+ super(VMGROUP_METHODS[:chown], uid, gid)
100
+ end
101
+
102
+ # Changes the SecurityGroup permissions.
103
+ #
104
+ # @param octet [String] Permissions octed , e.g. 640
105
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
106
+ # otherwise
107
+ def chmod_octet(octet)
108
+ super(VMGROUP_METHODS[:chmod], octet)
109
+ end
110
+
111
+ # Changes the SecurityGroup permissions.
112
+ # Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
113
+ #
114
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
115
+ # otherwise
116
+ def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
117
+ other_m, other_a)
118
+ super(VMGROUP_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
119
+ group_m, group_a, other_u, other_m, other_a)
120
+ end
121
+
122
+ # Renames this VMGroup
123
+ #
124
+ # @param name [String] New name for the VMGroup.
125
+ #
126
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
127
+ # otherwise
128
+ def rename(name)
129
+ return call(VMGROUP_METHODS[:rename], @pe_id, name)
130
+ end
131
+
132
+ #######################################################################
133
+ # Helpers to get VMGroup information
134
+ #######################################################################
135
+
136
+ # Returns the group identifier
137
+ # [return] _Integer_ the element's group ID
138
+ def gid
139
+ self['GID'].to_i
140
+ end
141
+
142
+ def owner_id
143
+ self['UID'].to_i
144
+ end
145
+
146
+ # [return] _Array_ with the name of roles
147
+ def role_names
148
+ self.retrieve_elements('ROLES/ROLE/NAME')
149
+ end
150
+ end
151
+ end