opennebula 5.12.4 → 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 +4 -4
  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.rb +32 -0
  17. data/lib/models/role.rb +1126 -0
  18. data/lib/models/service.rb +709 -0
  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.rb +5 -2
  38. data/lib/opennebula/acl.rb +1 -1
  39. data/lib/opennebula/acl_pool.rb +1 -1
  40. data/lib/opennebula/client.rb +1 -1
  41. data/lib/opennebula/cluster.rb +1 -1
  42. data/lib/opennebula/cluster_pool.rb +1 -1
  43. data/lib/opennebula/datastore.rb +1 -1
  44. data/lib/opennebula/datastore_pool.rb +1 -1
  45. data/lib/opennebula/document.rb +8 -29
  46. data/lib/opennebula/document_json.rb +42 -12
  47. data/lib/opennebula/document_pool.rb +1 -1
  48. data/lib/opennebula/document_pool_json.rb +1 -1
  49. data/lib/opennebula/error.rb +4 -1
  50. data/lib/opennebula/flow.rb +23 -0
  51. data/lib/opennebula/flow/grammar.rb +1195 -0
  52. data/lib/opennebula/flow/service_pool.rb +190 -0
  53. data/lib/opennebula/flow/service_template.rb +572 -0
  54. data/lib/opennebula/flow/service_template_ext.rb +84 -0
  55. data/lib/opennebula/flow/service_template_pool.rb +32 -0
  56. data/lib/opennebula/flow/validator.rb +499 -0
  57. data/lib/opennebula/group.rb +1 -1
  58. data/lib/opennebula/group_pool.rb +1 -1
  59. data/lib/opennebula/hook.rb +5 -12
  60. data/lib/opennebula/hook_log.rb +1 -1
  61. data/lib/opennebula/hook_pool.rb +1 -1
  62. data/lib/opennebula/host.rb +1 -1
  63. data/lib/opennebula/host_pool.rb +1 -1
  64. data/lib/opennebula/image.rb +17 -14
  65. data/lib/opennebula/image_pool.rb +1 -1
  66. data/lib/opennebula/ldap_auth.rb +1 -1
  67. data/lib/opennebula/ldap_auth_spec.rb +1 -1
  68. data/lib/opennebula/lockable_ext.rb +163 -0
  69. data/lib/opennebula/marketplace.rb +1 -1
  70. data/lib/opennebula/marketplace_pool.rb +1 -1
  71. data/lib/opennebula/marketplaceapp.rb +9 -119
  72. data/lib/opennebula/marketplaceapp_ext.rb +522 -0
  73. data/lib/opennebula/marketplaceapp_pool.rb +1 -1
  74. data/lib/opennebula/oneflow_client.rb +4 -3
  75. data/lib/opennebula/pool.rb +17 -3
  76. data/lib/opennebula/pool_element.rb +1 -1
  77. data/lib/opennebula/security_group.rb +1 -1
  78. data/lib/opennebula/security_group_pool.rb +1 -1
  79. data/lib/opennebula/server_cipher_auth.rb +1 -1
  80. data/lib/opennebula/server_x509_auth.rb +1 -1
  81. data/lib/opennebula/ssh_auth.rb +1 -1
  82. data/lib/opennebula/system.rb +1 -1
  83. data/lib/opennebula/template.rb +4 -13
  84. data/lib/opennebula/template_ext.rb +325 -0
  85. data/lib/opennebula/template_pool.rb +1 -1
  86. data/lib/opennebula/user.rb +26 -2
  87. data/lib/opennebula/user_pool.rb +1 -1
  88. data/lib/opennebula/utils.rb +1 -1
  89. data/lib/opennebula/vdc.rb +1 -1
  90. data/lib/opennebula/vdc_pool.rb +1 -1
  91. data/lib/opennebula/virtual_machine.rb +25 -207
  92. data/lib/opennebula/virtual_machine_ext.rb +469 -0
  93. data/lib/opennebula/virtual_machine_pool.rb +28 -17
  94. data/lib/opennebula/virtual_network.rb +4 -10
  95. data/lib/opennebula/virtual_network_pool.rb +1 -1
  96. data/lib/opennebula/virtual_router.rb +4 -12
  97. data/lib/opennebula/virtual_router_pool.rb +1 -1
  98. data/lib/opennebula/vm_group.rb +4 -11
  99. data/lib/opennebula/vm_group_pool.rb +1 -1
  100. data/lib/opennebula/vntemplate.rb +4 -13
  101. data/lib/opennebula/vntemplate_pool.rb +1 -1
  102. data/lib/opennebula/wait_ext.rb +222 -0
  103. data/lib/opennebula/x509_auth.rb +1 -1
  104. data/lib/opennebula/xml_element.rb +1 -1
  105. data/lib/opennebula/xml_pool.rb +1 -1
  106. data/lib/opennebula/xml_utils.rb +1 -1
  107. data/lib/opennebula/zone.rb +1 -1
  108. data/lib/opennebula/zone_pool.rb +1 -1
  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 +13 -11
  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 +118 -5
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
2
+ # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
3
3
  # #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
5
  # not use this file except in compliance with the License. You may obtain #
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
2
+ # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
3
3
  # #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
5
  # not use this file except in compliance with the License. You may obtain #
@@ -386,8 +386,9 @@ module Service
386
386
  do_request(req)
387
387
  end
388
388
 
389
- def delete(path)
390
- req =Net::HTTP::Proxy(@host, @port)::Delete.new(path)
389
+ def delete(path, body = nil)
390
+ req = Net::HTTP::Proxy(@host, @port)::Delete.new(path)
391
+ req.body = body if body
391
392
 
392
393
  do_request(req)
393
394
  end
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
2
+ # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
3
3
  # #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
5
  # not use this file except in compliance with the License. You may obtain #
@@ -28,7 +28,7 @@ module OpenNebula
28
28
  attr_reader :element_name
29
29
 
30
30
  PAGINATED_POOLS=%w{VM_POOL IMAGE_POOL TEMPLATE_POOL VN_POOL
31
- DOCUMENT_POOL SECGROUP_POOL}
31
+ SECGROUP_POOL DOCUMENT_POOL}
32
32
 
33
33
  protected
34
34
  #pool:: _String_ XML name of the root element
@@ -127,6 +127,19 @@ module OpenNebula
127
127
  return hash
128
128
  end
129
129
 
130
+ def monitoring_last(xml_method, *args)
131
+ rc = @client.call(xml_method, *args)
132
+
133
+ if OpenNebula.is_error?(rc)
134
+ return rc
135
+ end
136
+
137
+ xmldoc = XMLElement.new
138
+ xmldoc.initialize_xml(rc, 'MONITORING_DATA')
139
+
140
+ xmldoc.to_hash
141
+ end
142
+
130
143
  private
131
144
  # Calls to the corresponding info method to retreive the pool
132
145
  # representation in XML format
@@ -233,7 +246,8 @@ module OpenNebula
233
246
  # state state of the objects
234
247
  # hash:: return page as a hash
235
248
  def get_page(size, current, extended = false, state = -1)
236
- rc = nil
249
+ rc = nil
250
+ state ||= -1
237
251
 
238
252
  if PAGINATED_POOLS.include?(@pool_name)
239
253
  pool_name = @pool_name.delete('_').downcase
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
2
+ # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
3
3
  # #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
5
  # not use this file except in compliance with the License. You may obtain #
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
2
+ # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
3
3
  # #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
5
  # not use this file except in compliance with the License. You may obtain #
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
2
+ # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
3
3
  # #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
5
  # not use this file except in compliance with the License. You may obtain #
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
2
+ # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
3
3
  # #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
5
  # not use this file except in compliance with the License. You may obtain #
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
2
+ # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
3
3
  # #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
5
  # not use this file except in compliance with the License. You may obtain #
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
2
+ # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
3
3
  # #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
5
  # not use this file except in compliance with the License. You may obtain #
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
2
+ # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
3
3
  # #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
5
  # not use this file except in compliance with the License. You may obtain #
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
2
+ # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
3
3
  # #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
5
  # not use this file except in compliance with the License. You may obtain #
@@ -14,7 +14,7 @@
14
14
  # limitations under the License. #
15
15
  #--------------------------------------------------------------------------- #
16
16
 
17
-
17
+ require 'opennebula/lockable_ext'
18
18
  require 'opennebula/pool_element'
19
19
 
20
20
  module OpenNebula
@@ -23,7 +23,6 @@ module OpenNebula
23
23
  # Constants and Class Methods
24
24
  #######################################################################
25
25
 
26
-
27
26
  TEMPLATE_METHODS = {
28
27
  :allocate => "template.allocate",
29
28
  :instantiate => "template.instantiate",
@@ -57,6 +56,8 @@ module OpenNebula
57
56
 
58
57
  # Class constructor
59
58
  def initialize(xml, client)
59
+ LockableExt.make_lockable(self, TEMPLATE_METHODS)
60
+
60
61
  super(xml,client)
61
62
 
62
63
  @client = client
@@ -243,16 +244,6 @@ module OpenNebula
243
244
  self['UID'].to_i
244
245
  end
245
246
 
246
- # Lock a Template
247
- def lock(level)
248
- return call(TEMPLATE_METHODS[:lock], @pe_id, level)
249
- end
250
-
251
- # Unlock a Template
252
- def unlock()
253
- return call(TEMPLATE_METHODS[:unlock], @pe_id)
254
- end
255
-
256
247
  def public?
257
248
  if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
258
249
  true
@@ -0,0 +1,325 @@
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
+ require 'securerandom'
18
+ require 'opennebula/wait_ext'
19
+
20
+ # Module to decorate Template class with additional helpers not directly
21
+ # exposed through the OpenNebula XMLRPC API. The extensions include
22
+ # - mp_import helper that imports a template into a marketplace
23
+ #
24
+ # rubocop:disable Style/ClassAndModuleChildren
25
+ module OpenNebula::TemplateExt
26
+
27
+ def self.extend_object(obj)
28
+ if !obj.is_a?(OpenNebula::Template)
29
+ raise StandardError, "Cannot extended #{obj.class} with TemplateExt"
30
+ end
31
+
32
+ class << obj
33
+
34
+ ####################################################################
35
+ # Public extended interface
36
+ ####################################################################
37
+
38
+ # ------------------------------------------------------------------
39
+ # Imports template into marketplace
40
+ #
41
+ # @param market [Integer] Market to import the Template
42
+ # @param import_all [Bool] true to import images too,
43
+ # @param template_name [String] Virtual Machine Template app name
44
+ #
45
+ # @return [String, Array]
46
+ # - Error message in case of any or random generated template name
47
+ # - Objects IDs
48
+ # ------------------------------------------------------------------
49
+ def mp_import(market, import_all, template_name = nil, opts = {})
50
+ opts = {
51
+ :wait => false,
52
+ :logger => nil
53
+ }.merge(opts)
54
+
55
+ ids = []
56
+ images = []
57
+ logger = opts[:logger]
58
+
59
+ main_template = ''
60
+
61
+ #---------------------------------------------------------------
62
+ # Import all disks as IMAGE
63
+ #---------------------------------------------------------------
64
+ logger.info 'Processing VM disks' if logger
65
+
66
+ retrieve_xmlelements('TEMPLATE/DISK').each_with_index do
67
+ |disk, idx|
68
+
69
+ image = image_lookup(disk)
70
+
71
+ if OpenNebula.is_error?(image)
72
+ logger.fatal image.message if logger
73
+
74
+ rollback(ids)
75
+ return [image, ids]
76
+ end
77
+
78
+ logger.info "Adding disk with image #{image.id}" if logger
79
+
80
+ tmpl, main = create_app_template(image, idx)
81
+
82
+ if OpenNebula.is_error?(tmpl)
83
+ logger.fatal tmpl.message if logger
84
+
85
+ rollback(ids)
86
+ return [tmpl, ids]
87
+ end
88
+
89
+ main_template << main
90
+
91
+ next unless import_all
92
+
93
+ logger.info 'Importing image to market place' if logger
94
+
95
+ rc = create_app(tmpl, market)
96
+
97
+ if OpenNebula.is_error?(rc)
98
+ logger.fatal rc.message if logger
99
+
100
+ rollback(ids)
101
+ return [rc, ids]
102
+ end
103
+
104
+ images << image
105
+
106
+ ids << rc
107
+ end
108
+
109
+ delete_element('TEMPLATE/DISK')
110
+
111
+ #---------------------------------------------------------------
112
+ # Import VM template
113
+ #---------------------------------------------------------------
114
+ logger.info 'Processing VM NICs' if logger
115
+
116
+ # Replace all nics by auto nics
117
+ nic_xpath = '/VMTEMPLATE/TEMPLATE/NIC'
118
+ alias_xpath = '/VMTEMPLATE/TEMPLATE/NIC_ALIAS'
119
+
120
+ retrieve_xmlelements(nic_xpath).each do |nic|
121
+ if nic['NETWORK']
122
+ net = "[NETWORK=\"#{nic['NETWORK']}\"]"
123
+ elsif nic['NETWORK_ID']
124
+ net = "[NETWORK_ID=\"#{nic['NETWORK_ID']}\"]"
125
+ end
126
+
127
+ # NIC can be already in auto mode
128
+ next unless net
129
+
130
+ # If there are ALIAS the NIC can't be auto,
131
+ # because this combination isn't supported by the core
132
+ nic_alias = retrieve_xmlelements(alias_xpath)
133
+
134
+ if !nic_alias || nic_alias.empty?
135
+ nic.add_element("#{nic_xpath}#{net}",
136
+ 'NETWORK_MODE' => 'auto')
137
+ else
138
+ # Add attribute to avoid empty elements
139
+ nic.add_element("#{nic_xpath}#{net}", 'MARKET' => 'YES')
140
+ end
141
+
142
+ delete_nic_attributes(nic)
143
+ end
144
+
145
+ retrieve_xmlelements(alias_xpath).each do |nic|
146
+ delete_nic_attributes(nic)
147
+ end
148
+
149
+ # Rename it to avoid clashing names
150
+ if template_name
151
+ name = template_name
152
+ else
153
+ name = "#{self['NAME']}-#{SecureRandom.hex[0..9]}"
154
+ end
155
+
156
+ main_template << <<-EOT
157
+ NAME ="#{name}"
158
+ ORIGIN_ID ="-1\"
159
+ TYPE ="VMTEMPLATE"
160
+ VERSION ="#{OpenNebula::VERSION}"
161
+
162
+ APPTEMPLATE64 ="#{Base64.strict_encode64(template_str)}"
163
+ EOT
164
+
165
+ logger.info 'Creating VM app' if logger
166
+
167
+ rc = create_app(main_template, market)
168
+
169
+ if OpenNebula.is_error?(rc)
170
+ logger.fatal rc.message if logger
171
+
172
+ rollback(ids)
173
+ return [rc, ids]
174
+ end
175
+
176
+ logger.info 'Waiting for image upload' if logger && opts[:wait]
177
+
178
+ images.each {|i| i.wait('READY') } if opts[:wait]
179
+
180
+ ids << rc
181
+
182
+ [name, ids]
183
+ end
184
+
185
+ ####################################################################
186
+ # Private methods
187
+ ####################################################################
188
+ private
189
+
190
+ #-------------------------------------------------------------------
191
+ # NIC and NIC Alias attributes to delete when importing template
192
+ # into marketplace.
193
+ # @param nic [XMLElement] to delete attributes from
194
+ #-------------------------------------------------------------------
195
+ def delete_nic_attributes(nic)
196
+ %w[NETWORK NETWORK_ID NETWORK_UNAME SECURITY_GROUPS].each do |a|
197
+ nic.delete_element(a)
198
+ end
199
+ end
200
+
201
+ #-------------------------------------------------------------------
202
+ # Create application template
203
+ #
204
+ # @param id [Image] OpenNebula Image
205
+ # @param idx [Integer] Image ID in VM template
206
+ #
207
+ # @return [String, String]
208
+ # - app template
209
+ # - content for VM template
210
+ #-------------------------------------------------------------------
211
+ def create_app_template(image, idx = 0)
212
+ # Wait until the image is READY to safe copy it to the MP
213
+ image.wait('READY') if Integer(image['STATE']) != 1
214
+
215
+ # Rename to avoid clashing names
216
+ app_name = "#{image['NAME']}-#{SecureRandom.hex[0..9]}"
217
+
218
+ dev_prefix = image['TEMPLATE/DEV_PREFIX']
219
+ img_type = image.type_str
220
+
221
+ template64 = "TYPE=#{img_type}\n"
222
+ template64 << "DEV_PREFIX=\"#{dev_prefix}\"\n" if dev_prefix
223
+
224
+ template = <<-EOT
225
+ NAME ="#{app_name}"
226
+ ORIGIN_ID ="#{image['ID']}"
227
+ TYPE ="IMAGE"
228
+ VERSION ="#{OpenNebula::VERSION}"
229
+
230
+ APPTEMPLATE64 = "#{Base64.strict_encode64(template64)}"
231
+ EOT
232
+
233
+ main_template = <<-EOT
234
+ DISK = [
235
+ NAME = "#{img_type}_#{idx}",
236
+ APP = "#{app_name}"
237
+ ]
238
+ EOT
239
+
240
+ [template, main_template]
241
+ end
242
+
243
+ #-------------------------------------------------------------------
244
+ # Create application in marketplace
245
+ #
246
+ # @param template [String] APP template
247
+ # @param market_id [Integer] Marketplace to import it
248
+ #
249
+ # @return [Integer] APP ID
250
+ #-------------------------------------------------------------------
251
+ def create_app(template, market_id)
252
+ xml = OpenNebula::MarketPlaceApp.build_xml
253
+ app = OpenNebula::MarketPlaceApp.new(xml, @client)
254
+
255
+ rc = app.allocate(template, market_id)
256
+
257
+ return rc if OpenNebula.is_error?(rc)
258
+
259
+ app.id
260
+ end
261
+
262
+ #-------------------------------------------------------------------
263
+ # Delete IDS apps
264
+ #
265
+ # @param ids [Array] Apps IDs to delete
266
+ #-------------------------------------------------------------------
267
+ def rollback(ids)
268
+ ids.each do |id|
269
+ app = OpenNebula::MarketPlaceApp.new_with_id(id, @client)
270
+
271
+ app.delete
272
+ end
273
+ end
274
+
275
+ #-------------------------------------------------------------------
276
+ # Lookup OpenNebula Images by name or id. Lookup is made on a cached
277
+ # image pool.
278
+ #
279
+ # @param id [Integer, nil] Image id
280
+ # @param name [String] Image name
281
+ #
282
+ # @return [Image]
283
+ #-------------------------------------------------------------------
284
+ def image_lookup(disk)
285
+ # Image pool cache for image id lookup
286
+ if @image_lookup_cache.nil?
287
+ @image_lookup_cache = OpenNebula::ImagePool.new(@client)
288
+ @image_lookup_cache.info
289
+ end
290
+
291
+ # Find image information, from ID or NAME. NAME uses the
292
+ # specified user or template owner namespaces
293
+ image = nil
294
+
295
+ image_id = disk['IMAGE_ID']
296
+
297
+ if image_id
298
+ image = OpenNebula::Image.new_with_id(image_id, @client)
299
+ else
300
+ name = disk['IMAGE']
301
+ uname = disk['IMAGE_UNAME']
302
+ uname ||= self['UNAME']
303
+
304
+ name.gsub!('"', '')
305
+ image = @image_lookup_cache.find do |v|
306
+ v['NAME'] == name && v['UNAME'] == uname
307
+ end
308
+
309
+ return Error.new("Image #{image} not found") if image.nil?
310
+ end
311
+
312
+ rc = image.info
313
+
314
+ return rc if OpenNebula.is_error? rc
315
+
316
+ image.extend(OpenNebula::WaitExt)
317
+
318
+ image
319
+ end
320
+
321
+ end
322
+ end
323
+
324
+ end
325
+ # rubocop:enable Style/ClassAndModuleChildren