opennebula 5.12.13 → 5.13.80.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +5 -5
  2. data/lib/ActionManager.rb +1 -1
  3. data/lib/CommandManager.rb +1 -1
  4. data/lib/DriverExecHelper.rb +44 -28
  5. data/lib/OpenNebulaDriver.rb +8 -4
  6. data/lib/VirtualMachineDriver.rb +9 -2
  7. data/lib/cloud/CloudClient.rb +3 -3
  8. data/lib/datacenter.rb +1258 -0
  9. data/lib/datastore.rb +1025 -0
  10. data/lib/distributed_firewall.rb +280 -0
  11. data/lib/file_helper.rb +370 -0
  12. data/lib/host.rb +1517 -0
  13. data/lib/logical_port.rb +50 -0
  14. data/lib/logical_switch.rb +77 -0
  15. data/lib/memoize.rb +74 -0
  16. data/lib/models/role.rb +39 -8
  17. data/lib/models/service.rb +92 -31
  18. data/lib/models.rb +5 -5
  19. data/lib/network.rb +635 -0
  20. data/lib/nsx_client.rb +144 -0
  21. data/lib/nsx_component.rb +28 -0
  22. data/lib/nsx_constants.rb +149 -0
  23. data/lib/nsx_driver.rb +78 -0
  24. data/lib/nsx_error.rb +77 -0
  25. data/lib/nsx_rule.rb +193 -0
  26. data/lib/nsxt_client.rb +176 -0
  27. data/lib/nsxt_dfw.rb +196 -0
  28. data/lib/nsxt_logical_port.rb +94 -0
  29. data/lib/nsxt_rule.rb +188 -0
  30. data/lib/nsxt_tz.rb +38 -0
  31. data/lib/nsxv_client.rb +176 -0
  32. data/lib/nsxv_dfw.rb +202 -0
  33. data/lib/nsxv_logical_port.rb +107 -0
  34. data/lib/nsxv_rule.rb +172 -0
  35. data/lib/nsxv_tz.rb +41 -0
  36. data/lib/opaque_network.rb +134 -0
  37. data/lib/opennebula/acl.rb +1 -1
  38. data/lib/opennebula/acl_pool.rb +1 -1
  39. data/lib/opennebula/client.rb +1 -1
  40. data/lib/opennebula/cluster.rb +1 -1
  41. data/lib/opennebula/cluster_pool.rb +1 -1
  42. data/lib/opennebula/datastore.rb +1 -1
  43. data/lib/opennebula/datastore_pool.rb +1 -1
  44. data/lib/opennebula/document.rb +8 -29
  45. data/lib/opennebula/document_json.rb +42 -12
  46. data/lib/opennebula/document_pool.rb +1 -1
  47. data/lib/opennebula/document_pool_json.rb +1 -1
  48. data/lib/opennebula/error.rb +4 -1
  49. data/lib/opennebula/flow/grammar.rb +1195 -0
  50. data/lib/{models → opennebula/flow}/service_pool.rb +26 -2
  51. data/lib/{models → opennebula/flow}/service_template.rb +86 -17
  52. data/lib/opennebula/flow/service_template_ext.rb +84 -0
  53. data/lib/{models → opennebula/flow}/service_template_pool.rb +1 -1
  54. data/lib/opennebula/flow/validator.rb +499 -0
  55. data/lib/opennebula/flow.rb +23 -0
  56. data/lib/opennebula/group.rb +1 -1
  57. data/lib/opennebula/group_pool.rb +1 -1
  58. data/lib/opennebula/hook.rb +5 -12
  59. data/lib/opennebula/hook_log.rb +1 -1
  60. data/lib/opennebula/hook_pool.rb +1 -1
  61. data/lib/opennebula/host.rb +1 -1
  62. data/lib/opennebula/host_pool.rb +1 -1
  63. data/lib/opennebula/image.rb +17 -14
  64. data/lib/opennebula/image_pool.rb +1 -1
  65. data/lib/opennebula/ldap_auth.rb +1 -1
  66. data/lib/opennebula/ldap_auth_spec.rb +1 -1
  67. data/lib/opennebula/lockable_ext.rb +163 -0
  68. data/lib/opennebula/marketplace.rb +1 -1
  69. data/lib/opennebula/marketplace_pool.rb +1 -1
  70. data/lib/opennebula/marketplaceapp.rb +9 -119
  71. data/lib/opennebula/marketplaceapp_ext.rb +522 -0
  72. data/lib/opennebula/marketplaceapp_pool.rb +1 -1
  73. data/lib/opennebula/oneflow_client.rb +4 -3
  74. data/lib/opennebula/pool.rb +4 -3
  75. data/lib/opennebula/pool_element.rb +1 -1
  76. data/lib/opennebula/security_group.rb +1 -1
  77. data/lib/opennebula/security_group_pool.rb +1 -1
  78. data/lib/opennebula/server_cipher_auth.rb +1 -1
  79. data/lib/opennebula/server_x509_auth.rb +1 -1
  80. data/lib/opennebula/ssh_auth.rb +1 -1
  81. data/lib/opennebula/system.rb +1 -1
  82. data/lib/opennebula/template.rb +4 -13
  83. data/lib/opennebula/template_ext.rb +325 -0
  84. data/lib/opennebula/template_pool.rb +1 -1
  85. data/lib/opennebula/user.rb +26 -2
  86. data/lib/opennebula/user_pool.rb +1 -1
  87. data/lib/opennebula/utils.rb +1 -1
  88. data/lib/opennebula/vdc.rb +1 -1
  89. data/lib/opennebula/vdc_pool.rb +1 -1
  90. data/lib/opennebula/virtual_machine.rb +25 -207
  91. data/lib/opennebula/virtual_machine_ext.rb +469 -0
  92. data/lib/opennebula/virtual_machine_pool.rb +1 -5
  93. data/lib/opennebula/virtual_network.rb +4 -10
  94. data/lib/opennebula/virtual_network_pool.rb +1 -1
  95. data/lib/opennebula/virtual_router.rb +4 -12
  96. data/lib/opennebula/virtual_router_pool.rb +1 -1
  97. data/lib/opennebula/vm_group.rb +4 -11
  98. data/lib/opennebula/vm_group_pool.rb +1 -1
  99. data/lib/opennebula/vntemplate.rb +4 -13
  100. data/lib/opennebula/vntemplate_pool.rb +1 -1
  101. data/lib/opennebula/wait_ext.rb +222 -0
  102. data/lib/opennebula/x509_auth.rb +1 -1
  103. data/lib/opennebula/xml_element.rb +1 -1
  104. data/lib/opennebula/xml_pool.rb +1 -1
  105. data/lib/opennebula/xml_utils.rb +1 -1
  106. data/lib/opennebula/zone.rb +1 -1
  107. data/lib/opennebula/zone_pool.rb +1 -1
  108. data/lib/opennebula.rb +5 -2
  109. data/lib/rest_client.rb +201 -0
  110. data/lib/scripts_common.rb +180 -0
  111. data/lib/transport_zone.rb +43 -0
  112. data/lib/vcenter_driver.rb +9 -22
  113. data/lib/vcenter_importer.rb +616 -0
  114. data/lib/vi_client.rb +281 -0
  115. data/lib/vi_helper.rb +312 -0
  116. data/lib/virtual_machine.rb +3477 -0
  117. data/lib/virtual_wire.rb +158 -0
  118. data/lib/vm_device.rb +80 -0
  119. data/lib/vm_disk.rb +202 -0
  120. data/lib/vm_folder.rb +69 -0
  121. data/lib/vm_helper.rb +30 -0
  122. data/lib/vm_monitor.rb +303 -0
  123. data/lib/vm_nic.rb +70 -0
  124. data/lib/vm_template.rb +1961 -0
  125. data/lib/vmm_importer.rb +121 -0
  126. metadata +101 -35
@@ -0,0 +1,158 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2021, 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
+ module NSXDriver
17
+
18
+ # Class VirtualWire NSX-V Network
19
+ class VirtualWire < LogicalSwitch
20
+
21
+ # CONSTRUCTOR
22
+ def initialize(nsx_client, ls_id = nil, tz_id = nil, ls_data = nil)
23
+ super(nsx_client)
24
+ if ls_id
25
+ initialize_with_id(ls_id)
26
+ else
27
+ if tz_id && ls_data
28
+ begin
29
+ @ls_id = new_logical_switch(ls_data, tz_id)
30
+ rescue NSXError::IncorrectResponseCodeError => e
31
+ raise 'VirtualWire not created in NSX Manager: ' \
32
+ "#{e.message}"
33
+ end
34
+ unless @ls_id
35
+ raise 'Virtual Wire not created in NSX Manager: ' \
36
+ 'generic error'
37
+ end
38
+
39
+ # Construct URL of the created logical switch
40
+ @url_ls = NSXConstants::NSXV_LS_SECTION + @ls_id
41
+ @ls_vni = ls_vni
42
+ @ls_name = ls_name
43
+ @tz_id = ls_tz
44
+ @tenant_id = 'virtual wire tenant'
45
+ @guest_vlan_allowed = false
46
+ end
47
+ end
48
+ end
49
+
50
+ # Creates a VirtualWire from its name
51
+ def self.new_from_name(nsx_client, ls_name)
52
+ virtualwire = new(nsx_client)
53
+ ls_id = virtualwire.ls_id_from_name(nsx_client, ls_name)
54
+ unless ls_id
55
+ error_msg = "VirtualWire with name: #{ls_name} not found"
56
+ error = NSXError::ObjectNotFound
57
+ .new(error_msg)
58
+ raise error
59
+ end
60
+
61
+ # initialize_with_id(@ls_id)
62
+ virtualwire.initialize_with_id(ls_id)
63
+ virtualwire
64
+ end
65
+
66
+ # Creates a VirtualWire from its id
67
+ def initialize_with_id(ls_id)
68
+ @ls_id = ls_id
69
+ # Construct URL of the created logical switch
70
+ @url_ls = NSXConstants::NSXV_LS_SECTION + \
71
+ @ls_id
72
+ # Raise an error if VirtualWire id doesn't exists
73
+ unless ls?
74
+ error_msg = "VirtualWire with id: #{ls_id} not found"
75
+ error = NSXError::ObjectNotFound
76
+ .new(error_msg)
77
+ raise error
78
+ end
79
+
80
+ @ls_vni = ls_vni
81
+ @ls_name = ls_name
82
+ @tz_id = ls_tz
83
+ @tenant_id = 'virtual wire tenant'
84
+ @guest_vlan_allowed = false
85
+ end
86
+
87
+ # Get the logical switch id from its name
88
+ def ls_id_from_name(nsx_client, name)
89
+ url = NSXConstants::NSXV_LS_SECTION
90
+ virtualwires = nsx_client
91
+ .get(url)
92
+ .xpath(NSXConstants::NSXV_LS_XPATH)
93
+ virtualwires.each do |virtualwire|
94
+ lsname_arr = name.split(/-sid-/)
95
+ lsname = lsname_arr[-1].split('-', 2)[-1]
96
+ lsid = lsname_arr[0].split(/vxw-dvs-\w.-/)[-1]
97
+ if virtualwire.xpath('name').text == lsname &&
98
+ virtualwire.xpath('objectId').text == lsid
99
+ return virtualwire.xpath('objectId').text
100
+ end
101
+ end
102
+ nil
103
+ end
104
+
105
+ # METHODS
106
+
107
+ # Check if logical switch exists
108
+ def ls?
109
+ @nsx_client.get(@url_ls) ? true : false
110
+ end
111
+
112
+ # Get logical switch's name
113
+ def ls_name
114
+ @nsx_client.get(@url_ls)
115
+ .xpath(NSXConstants::NSXV_LS_NAME_XPATH).text
116
+ end
117
+
118
+ # Get logical switch's vni
119
+ def ls_vni
120
+ @nsx_client.get(@url_ls)
121
+ .xpath(NSXConstants::NSXV_LS_VNI_XPATH).text
122
+ end
123
+
124
+ # Get the Transport Zone of the logical switch
125
+ def ls_tz
126
+ @nsx_client.get(@url_ls)
127
+ .xpath(NSXConstants::NSXV_TZ_XPATH).text
128
+ end
129
+
130
+ # Get the logical switch reference into vcenter
131
+ def ls_vcenter_ref
132
+ @nsx_client.get(@url_ls)
133
+ .xpath(NSXConstants::NSXV_LS_BACKING_XPATH)
134
+ .text
135
+ end
136
+
137
+ # Get the distributed virtual switch's ref associated to a LS
138
+ def ls_dvs_ref
139
+ @nsx_client.get(@url_ls)
140
+ .xpath(NSXConstants::NSXV_LS_OBJECTID_XPATH)
141
+ .text
142
+ end
143
+
144
+ # Create a new logical switch (NSX-V: virtualwire)
145
+ def new_logical_switch(ls_data, tz_id)
146
+ url = "#{NSXConstants::NSXV_TZ_SECTION}#{tz_id}" \
147
+ '/virtualwires'
148
+ @nsx_client.post(url, ls_data)
149
+ end
150
+
151
+ # Delete a logical switch
152
+ def delete_logical_switch
153
+ @nsx_client.delete(@url_ls)
154
+ end
155
+
156
+ end
157
+
158
+ end
data/lib/vm_device.rb ADDED
@@ -0,0 +1,80 @@
1
+ module VirtualMachineDevice
2
+
3
+ ############################################################################
4
+ # Device Classes
5
+ ############################################################################
6
+ # Device base class
7
+ #
8
+ # @param id [Integer] The OpenNebula resource id
9
+ # @param one_res [XMLElement] The OpenNebula representation of the object
10
+ # @param vc_res [vCenter_class_specific] vCenter object representation
11
+ ############################################################################
12
+ class Device
13
+
14
+ def initialize(id, one_res, vc_res)
15
+ @id = id
16
+ @one_res = one_res
17
+ @vc_res = vc_res
18
+ end
19
+
20
+ def id
21
+ raise_if_no_exists_in_one
22
+ @id
23
+ end
24
+
25
+ def one_item
26
+ raise_if_no_exists_in_one
27
+ @one_res
28
+ end
29
+
30
+ def vc_item
31
+ raise_if_no_exists_in_vcenter
32
+ @vc_res
33
+ end
34
+
35
+ def one?
36
+ !@one_res.nil?
37
+ end
38
+
39
+ def exists?
40
+ !@vc_res.nil?
41
+ end
42
+
43
+ # Fails if the device is not present in OpenNebula
44
+ def raise_if_no_exists_in_one
45
+ raise 'OpenNebula device does not exist at the moment' unless one?
46
+ end
47
+
48
+ # Fails if the device is not present in vCenter
49
+ def raise_if_no_exists_in_vcenter
50
+ raise 'vCenter device does not exist at the moment' unless exists?
51
+ end
52
+
53
+ def no_exists?
54
+ !exists?
55
+ end
56
+
57
+ def synced?
58
+ one? && exists?
59
+ end
60
+
61
+ def unsynced?
62
+ !synced?
63
+ end
64
+
65
+ def detached?
66
+ !one?
67
+ end
68
+
69
+ def managed?
70
+ raise_if_no_exists_in_one
71
+
72
+ return unless @one_res
73
+
74
+ !(@one_res['OPENNEBULA_MANAGED'] &&
75
+ @one_res['OPENNEBULA_MANAGED'].downcase == 'no')
76
+ end
77
+
78
+ end
79
+
80
+ end
data/lib/vm_disk.rb ADDED
@@ -0,0 +1,202 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2021, 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
+ module VirtualMachineDevice
17
+
18
+ # Disk class
19
+ class Disk < Device
20
+
21
+ attr_reader :size
22
+
23
+ # Create the OpenNebula disk representation
24
+ # Allow us to create the class without vCenter representation
25
+ # example: attached disks not synced with vCenter
26
+ def self.one_disk(id, one_res)
27
+ new(id, one_res, nil)
28
+ end
29
+
30
+ # Create the vCenter disk representation
31
+ # Allow us to create the class without OpenNebula representation
32
+ # example: detached disks that not exists in OpenNebula
33
+ def self.vc_disk(vc_res)
34
+ new(nil, nil, vc_res)
35
+ end
36
+
37
+ def storpod?
38
+ raise_if_no_exists_in_one
39
+ @one_res['VCENTER_DS_REF'].start_with?('group-')
40
+ end
41
+
42
+ def device
43
+ raise_if_no_exists_in_vcenter
44
+ @vc_res[:device]
45
+ end
46
+
47
+ def node
48
+ raise_if_no_exists_in_vcenter
49
+ @vc_res[:tag]
50
+ end
51
+
52
+ def path
53
+ raise_if_no_exists_in_vcenter
54
+ @vc_res[:path_wo_ds]
55
+ end
56
+
57
+ def ds
58
+ raise_if_no_exists_in_vcenter
59
+ @vc_res[:datastore]
60
+ end
61
+
62
+ def image_ds_ref
63
+ raise_if_no_exists_in_one
64
+ @one_res['VCENTER_DS_REF']
65
+ end
66
+
67
+ def key
68
+ raise_if_no_exists_in_vcenter
69
+ @vc_res[:key]
70
+ end
71
+
72
+ def prefix
73
+ raise_if_no_exists_in_vcenter
74
+ @vc_res[:prefix]
75
+ end
76
+
77
+ def type
78
+ raise_if_no_exists_in_vcenter
79
+ @vc_res[:type]
80
+ end
81
+
82
+ def file
83
+ path.split('/').last
84
+ end
85
+
86
+ def cd?
87
+ raise_if_no_exists_in_vcenter
88
+ @vc_res[:type] == 'CDROM'
89
+ end
90
+
91
+ def config(action)
92
+ raise_if_no_exists_in_vcenter
93
+
94
+ config = {}
95
+
96
+ case action
97
+ when :delete
98
+ if managed?
99
+ key = "opennebula.mdisk.#{@id}"
100
+ else
101
+ key = "opennebula.disk.#{@id}"
102
+ end
103
+
104
+ config[:key] = key
105
+ config[:value] = ''
106
+ when :resize
107
+ if new_size
108
+ d = device
109
+ d.capacityInKB = new_size
110
+ config[:device] = d
111
+ config[:operation] = :edit
112
+ end
113
+ when :attach
114
+ puts 'not supported'
115
+ end
116
+
117
+ config
118
+ end
119
+
120
+ def persistent?
121
+ raise_if_no_exists_in_one
122
+ @one_res['PERSISTENT'] == 'YES'
123
+ end
124
+
125
+ def volatile?
126
+ raise_if_no_exists_in_one
127
+ @one_res['TYPE'] && @one_res['TYPE'].downcase == 'fs'
128
+ end
129
+
130
+ def cloned?
131
+ raise_if_no_exists_in_one
132
+ @one_res['SOURCE'] != @vc_res[:path_wo_ds]
133
+ end
134
+
135
+ def connected?
136
+ raise_if_no_exists_in_vcenter
137
+ @vc_res[:device].connectable.connected
138
+ end
139
+
140
+ def boot_dev
141
+ if cd?
142
+ RbVmomi::VIM.VirtualMachineBootOptionsBootableCdromDevice()
143
+ else
144
+ RbVmomi::VIM.VirtualMachineBootOptionsBootableDiskDevice(
145
+ :deviceKey => device.key
146
+ )
147
+ end
148
+ end
149
+
150
+ def change_size(size)
151
+ size = size.to_i
152
+
153
+ if @one_res['ORIGINAL_SIZE'] &&
154
+ @one_res['ORIGINAL_SIZE'].to_i >= size
155
+ raise "'disk-resize' cannot decrease the disk's size"
156
+ end
157
+
158
+ @size = size
159
+ end
160
+
161
+ # Shrink not supported (nil). Size is in KB
162
+ def new_size
163
+ return @size * 1024 if @size
164
+
165
+ return unless @one_res['ORIGINAL_SIZE']
166
+
167
+ osize = @one_res['ORIGINAL_SIZE'].to_i
168
+ nsize = @one_res['SIZE'].to_i
169
+ nsize > osize ? nsize * 1024 : nil
170
+ end
171
+
172
+ def destroy
173
+ return if cd?
174
+
175
+ raise_if_no_exists_in_vcenter
176
+
177
+ ds = VCenterDriver::Datastore.new(self.ds)
178
+ img_path = path
179
+
180
+ begin
181
+ img_dir = File.dirname(img_path)
182
+ search_params = ds.get_search_params(
183
+ ds['name'],
184
+ img_dir,
185
+ File.basename(img_path)
186
+ )
187
+ search_task = ds['browser']
188
+ .SearchDatastoreSubFolders_Task(search_params)
189
+ search_task.wait_for_completion
190
+ ds.delete_virtual_disk(img_path)
191
+ ds.rm_directory(img_dir) if ds.dir_empty?(img_dir)
192
+ rescue StandardError => e
193
+ if !e.message.start_with?('FileNotFound')
194
+ # Ignore FileNotFound
195
+ raise e.message
196
+ end
197
+ end
198
+ end
199
+
200
+ end
201
+
202
+ end
data/lib/vm_folder.rb ADDED
@@ -0,0 +1,69 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2021, 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
+ module VCenterDriver
18
+
19
+ # VirtualMachineFolder class
20
+ class VirtualMachineFolder
21
+
22
+ attr_accessor :item, :items
23
+
24
+ def initialize(item)
25
+ @item = item
26
+ check_item(@item, nil)
27
+ @items = {}
28
+ end
29
+
30
+ ########################################################################
31
+ # Builds a hash with Datastore-Ref / Datastore to be used as a cache
32
+ # @return [Hash] in the form
33
+ # { ds_ref [Symbol] => Datastore object }
34
+ ########################################################################
35
+
36
+ def fetch!
37
+ VIClient.get_entities(@item, 'VirtualMachine').each do |item|
38
+ item_name = item._ref
39
+ @items[item_name.to_sym] = VirtualMachine.new_with_item(item)
40
+ end
41
+ end
42
+
43
+ def fetch_templates!
44
+ VIClient.get_entities(@item, 'VirtualMachine').each do |item|
45
+ if item.config.template
46
+ item_name = item._ref
47
+ @items[item_name.to_sym] = Template.new(item)
48
+ end
49
+ end
50
+ end
51
+
52
+ ########################################################################
53
+ # Returns a Datastore. Uses the cache if available.
54
+ # @param ref [Symbol] the vcenter ref
55
+ # @return Datastore
56
+ ########################################################################
57
+
58
+ def get(ref)
59
+ if !@items[ref.to_sym]
60
+ rbvmomi_dc = RbVmomi::VIM::Datastore.new(@item._connection, ref)
61
+ @items[ref.to_sym] = Datastore.new(rbvmomi_dc)
62
+ end
63
+
64
+ @items[ref.to_sym]
65
+ end
66
+
67
+ end
68
+
69
+ end
data/lib/vm_helper.rb ADDED
@@ -0,0 +1,30 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2021, 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
+ module VirtualMachineHelper
17
+
18
+ # This method raises an exception if the timeout is reached
19
+ # The exception needs to be handled in the VMM drivers and any
20
+ # process that uses this method
21
+ def wait_timeout(action, timeout = 300)
22
+ time_start = Time.now
23
+ until send(action)
24
+ sleep(1)
25
+ condition = (Time.now - time_start).to_i >= timeout
26
+ raise 'Reached deploy timeout' if condition
27
+ end
28
+ end
29
+
30
+ end