opennebula 5.12.9 → 6.0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ActionManager.rb +1 -1
- data/lib/CommandManager.rb +1 -1
- data/lib/DriverExecHelper.rb +44 -28
- data/lib/OpenNebulaDriver.rb +8 -4
- data/lib/VirtualMachineDriver.rb +9 -2
- data/lib/cloud/CloudClient.rb +3 -3
- data/lib/datacenter.rb +1257 -0
- data/lib/datastore.rb +1025 -0
- data/lib/distributed_firewall.rb +280 -0
- data/lib/file_helper.rb +370 -0
- data/lib/host.rb +1517 -0
- data/lib/logical_port.rb +50 -0
- data/lib/logical_switch.rb +77 -0
- data/lib/memoize.rb +74 -0
- data/lib/models.rb +32 -0
- data/lib/models/role.rb +1126 -0
- data/lib/models/service.rb +709 -0
- data/lib/network.rb +699 -0
- data/lib/nsx_client.rb +144 -0
- data/lib/nsx_component.rb +28 -0
- data/lib/nsx_constants.rb +149 -0
- data/lib/nsx_driver.rb +78 -0
- data/lib/nsx_error.rb +77 -0
- data/lib/nsx_rule.rb +193 -0
- data/lib/nsxt_client.rb +176 -0
- data/lib/nsxt_dfw.rb +196 -0
- data/lib/nsxt_logical_port.rb +94 -0
- data/lib/nsxt_rule.rb +188 -0
- data/lib/nsxt_tz.rb +38 -0
- data/lib/nsxv_client.rb +176 -0
- data/lib/nsxv_dfw.rb +202 -0
- data/lib/nsxv_logical_port.rb +107 -0
- data/lib/nsxv_rule.rb +172 -0
- data/lib/nsxv_tz.rb +41 -0
- data/lib/opaque_network.rb +134 -0
- data/lib/opennebula.rb +5 -2
- data/lib/opennebula/acl.rb +1 -1
- data/lib/opennebula/acl_pool.rb +1 -1
- data/lib/opennebula/client.rb +10 -2
- data/lib/opennebula/cluster.rb +1 -1
- data/lib/opennebula/cluster_pool.rb +1 -1
- data/lib/opennebula/datastore.rb +1 -1
- data/lib/opennebula/datastore_pool.rb +1 -1
- data/lib/opennebula/document.rb +8 -29
- data/lib/opennebula/document_json.rb +42 -12
- data/lib/opennebula/document_pool.rb +1 -1
- data/lib/opennebula/document_pool_json.rb +1 -1
- data/lib/opennebula/error.rb +4 -1
- data/lib/opennebula/flow.rb +23 -0
- data/lib/opennebula/flow/grammar.rb +1195 -0
- data/lib/opennebula/flow/service_pool.rb +190 -0
- data/lib/opennebula/flow/service_template.rb +608 -0
- data/lib/opennebula/flow/service_template_ext.rb +84 -0
- data/lib/opennebula/flow/service_template_pool.rb +32 -0
- data/lib/opennebula/flow/validator.rb +499 -0
- data/lib/opennebula/group.rb +1 -1
- data/lib/opennebula/group_pool.rb +1 -1
- data/lib/opennebula/hook.rb +5 -12
- data/lib/opennebula/hook_log.rb +1 -1
- data/lib/opennebula/hook_pool.rb +1 -1
- data/lib/opennebula/host.rb +1 -1
- data/lib/opennebula/host_pool.rb +1 -1
- data/lib/opennebula/image.rb +19 -14
- data/lib/opennebula/image_pool.rb +1 -1
- data/lib/opennebula/ldap_auth.rb +1 -1
- data/lib/opennebula/ldap_auth_spec.rb +1 -1
- data/lib/opennebula/lockable_ext.rb +163 -0
- data/lib/opennebula/marketplace.rb +1 -1
- data/lib/opennebula/marketplace_pool.rb +1 -1
- data/lib/opennebula/marketplaceapp.rb +9 -119
- data/lib/opennebula/marketplaceapp_ext.rb +586 -0
- data/lib/opennebula/marketplaceapp_pool.rb +1 -1
- data/lib/opennebula/oneflow_client.rb +4 -3
- data/lib/opennebula/pool.rb +6 -3
- data/lib/opennebula/pool_element.rb +1 -1
- data/lib/opennebula/security_group.rb +1 -1
- data/lib/opennebula/security_group_pool.rb +1 -1
- data/lib/opennebula/server_cipher_auth.rb +1 -1
- data/lib/opennebula/server_x509_auth.rb +1 -1
- data/lib/opennebula/ssh_auth.rb +1 -1
- data/lib/opennebula/system.rb +1 -1
- data/lib/opennebula/template.rb +4 -13
- data/lib/opennebula/template_ext.rb +342 -0
- data/lib/opennebula/template_pool.rb +1 -1
- data/lib/opennebula/user.rb +26 -2
- data/lib/opennebula/user_pool.rb +1 -1
- data/lib/opennebula/utils.rb +1 -1
- data/lib/opennebula/vdc.rb +1 -1
- data/lib/opennebula/vdc_pool.rb +1 -1
- data/lib/opennebula/virtual_machine.rb +26 -206
- data/lib/opennebula/virtual_machine_ext.rb +469 -0
- data/lib/opennebula/virtual_machine_pool.rb +1 -1
- data/lib/opennebula/virtual_network.rb +4 -10
- data/lib/opennebula/virtual_network_pool.rb +1 -1
- data/lib/opennebula/virtual_router.rb +4 -12
- data/lib/opennebula/virtual_router_pool.rb +1 -1
- data/lib/opennebula/vm_group.rb +4 -11
- data/lib/opennebula/vm_group_pool.rb +1 -1
- data/lib/opennebula/vntemplate.rb +4 -13
- data/lib/opennebula/vntemplate_pool.rb +1 -1
- data/lib/opennebula/wait_ext.rb +257 -0
- data/lib/opennebula/x509_auth.rb +1 -1
- data/lib/opennebula/xml_element.rb +1 -1
- data/lib/opennebula/xml_pool.rb +1 -1
- data/lib/opennebula/xml_utils.rb +1 -1
- data/lib/opennebula/zone.rb +1 -1
- data/lib/opennebula/zone_pool.rb +1 -1
- data/lib/rest_client.rb +201 -0
- data/lib/scripts_common.rb +183 -0
- data/lib/transport_zone.rb +43 -0
- data/lib/vcenter_driver.rb +13 -12
- data/lib/vcenter_importer.rb +616 -0
- data/lib/vi_client.rb +281 -0
- data/lib/vi_helper.rb +313 -0
- data/lib/virtual_machine.rb +3477 -0
- data/lib/virtual_wire.rb +158 -0
- data/lib/vm_device.rb +80 -0
- data/lib/vm_disk.rb +202 -0
- data/lib/vm_folder.rb +69 -0
- data/lib/vm_helper.rb +30 -0
- data/lib/vm_monitor.rb +303 -0
- data/lib/vm_nic.rb +70 -0
- data/lib/vm_template.rb +1963 -0
- data/lib/vmm_importer.rb +121 -0
- metadata +140 -27
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
|
2
|
-
# Copyright 2002-
|
|
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-
|
|
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
|
data/lib/opennebula/pool.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
|
2
|
-
# Copyright 2002-
|
|
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
|
|
31
|
+
SECGROUP_POOL DOCUMENT_POOL}
|
|
32
32
|
|
|
33
33
|
protected
|
|
34
34
|
#pool:: _String_ XML name of the root element
|
|
@@ -246,7 +246,8 @@ module OpenNebula
|
|
|
246
246
|
# state state of the objects
|
|
247
247
|
# hash:: return page as a hash
|
|
248
248
|
def get_page(size, current, extended = false, state = -1)
|
|
249
|
-
rc
|
|
249
|
+
rc = nil
|
|
250
|
+
state ||= -1
|
|
250
251
|
|
|
251
252
|
if PAGINATED_POOLS.include?(@pool_name)
|
|
252
253
|
pool_name = @pool_name.delete('_').downcase
|
|
@@ -321,5 +322,7 @@ module OpenNebula
|
|
|
321
322
|
def is_paginated?
|
|
322
323
|
PAGINATED_POOLS.include?(@pool_name)
|
|
323
324
|
end
|
|
325
|
+
|
|
324
326
|
end
|
|
327
|
+
|
|
325
328
|
end
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
|
2
|
-
# Copyright 2002-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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 #
|
data/lib/opennebula/ssh_auth.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
|
2
|
-
# Copyright 2002-
|
|
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 #
|
data/lib/opennebula/system.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
|
2
|
-
# Copyright 2002-
|
|
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 #
|
data/lib/opennebula/template.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
|
2
|
-
# Copyright 2002-
|
|
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,342 @@
|
|
|
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
|
+
i_state = OpenNebula::Image::IMAGE_STATES[
|
|
79
|
+
image['STATE'].to_i
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
unless %w[LOCKED READY USED].include?(i_state)
|
|
83
|
+
logger.fatal "Wrong image state #{i_state}" if logger
|
|
84
|
+
|
|
85
|
+
rollback(ids)
|
|
86
|
+
return [image, ids]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
logger.info "Adding disk with image #{image.id}" if logger
|
|
90
|
+
|
|
91
|
+
tmpl, main = create_app_template(image, idx)
|
|
92
|
+
|
|
93
|
+
if OpenNebula.is_error?(tmpl)
|
|
94
|
+
logger.fatal tmpl.message if logger
|
|
95
|
+
|
|
96
|
+
rollback(ids)
|
|
97
|
+
return [tmpl, ids]
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
main_template << main
|
|
101
|
+
|
|
102
|
+
next unless import_all
|
|
103
|
+
|
|
104
|
+
logger.info 'Importing image to market place' if logger
|
|
105
|
+
|
|
106
|
+
rc = create_app(tmpl, market)
|
|
107
|
+
|
|
108
|
+
if OpenNebula.is_error?(rc)
|
|
109
|
+
logger.fatal rc.message if logger
|
|
110
|
+
|
|
111
|
+
rollback(ids)
|
|
112
|
+
return [rc, ids]
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
images << image
|
|
116
|
+
|
|
117
|
+
ids << rc
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
delete_element('TEMPLATE/DISK')
|
|
121
|
+
|
|
122
|
+
#---------------------------------------------------------------
|
|
123
|
+
# Import VM template
|
|
124
|
+
#---------------------------------------------------------------
|
|
125
|
+
logger.info 'Processing VM NICs' if logger
|
|
126
|
+
|
|
127
|
+
# Replace all nics by auto nics
|
|
128
|
+
nic_xpath = '/VMTEMPLATE/TEMPLATE/NIC'
|
|
129
|
+
alias_xpath = '/VMTEMPLATE/TEMPLATE/NIC_ALIAS'
|
|
130
|
+
|
|
131
|
+
retrieve_xmlelements(nic_xpath).each do |nic|
|
|
132
|
+
if nic['NETWORK']
|
|
133
|
+
net = "[NETWORK=\"#{nic['NETWORK']}\"]"
|
|
134
|
+
elsif nic['NETWORK_ID']
|
|
135
|
+
net = "[NETWORK_ID=\"#{nic['NETWORK_ID']}\"]"
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# NIC can be already in auto mode
|
|
139
|
+
next unless net
|
|
140
|
+
|
|
141
|
+
# If there are ALIAS the NIC can't be auto,
|
|
142
|
+
# because this combination isn't supported by the core
|
|
143
|
+
nic_alias = retrieve_xmlelements(alias_xpath)
|
|
144
|
+
|
|
145
|
+
if !nic_alias || nic_alias.empty?
|
|
146
|
+
nic.add_element("#{nic_xpath}#{net}",
|
|
147
|
+
'NETWORK_MODE' => 'auto')
|
|
148
|
+
else
|
|
149
|
+
# Add attribute to avoid empty elements
|
|
150
|
+
nic.add_element("#{nic_xpath}#{net}", 'MARKET' => 'YES')
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
delete_nic_attributes(nic)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
retrieve_xmlelements(alias_xpath).each do |nic|
|
|
157
|
+
delete_nic_attributes(nic)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# Rename it to avoid clashing names
|
|
161
|
+
if template_name
|
|
162
|
+
name = template_name
|
|
163
|
+
else
|
|
164
|
+
name = "#{self['NAME']}-#{SecureRandom.hex[0..9]}"
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
main_template << <<-EOT
|
|
168
|
+
NAME ="#{name}"
|
|
169
|
+
ORIGIN_ID ="-1\"
|
|
170
|
+
TYPE ="VMTEMPLATE"
|
|
171
|
+
VERSION ="#{OpenNebula::VERSION}"
|
|
172
|
+
|
|
173
|
+
APPTEMPLATE64 ="#{Base64.strict_encode64(template_str)}"
|
|
174
|
+
EOT
|
|
175
|
+
|
|
176
|
+
logger.info 'Creating VM app' if logger
|
|
177
|
+
|
|
178
|
+
rc = create_app(main_template, market)
|
|
179
|
+
|
|
180
|
+
if OpenNebula.is_error?(rc)
|
|
181
|
+
logger.fatal rc.message if logger
|
|
182
|
+
|
|
183
|
+
rollback(ids)
|
|
184
|
+
return [rc, ids]
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
logger.info 'Waiting for image upload' if logger && opts[:wait]
|
|
188
|
+
|
|
189
|
+
images.each {|i| i.wait('READY') } if opts[:wait]
|
|
190
|
+
|
|
191
|
+
ids << rc
|
|
192
|
+
|
|
193
|
+
[name, ids]
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
####################################################################
|
|
197
|
+
# Private methods
|
|
198
|
+
####################################################################
|
|
199
|
+
private
|
|
200
|
+
|
|
201
|
+
#-------------------------------------------------------------------
|
|
202
|
+
# NIC and NIC Alias attributes to delete when importing template
|
|
203
|
+
# into marketplace.
|
|
204
|
+
# @param nic [XMLElement] to delete attributes from
|
|
205
|
+
#-------------------------------------------------------------------
|
|
206
|
+
def delete_nic_attributes(nic)
|
|
207
|
+
%w[NETWORK NETWORK_ID NETWORK_UNAME SECURITY_GROUPS].each do |a|
|
|
208
|
+
nic.delete_element(a)
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
#-------------------------------------------------------------------
|
|
213
|
+
# Create application template
|
|
214
|
+
#
|
|
215
|
+
# @param id [Image] OpenNebula Image
|
|
216
|
+
# @param idx [Integer] Image ID in VM template
|
|
217
|
+
#
|
|
218
|
+
# @return [String, String]
|
|
219
|
+
# - app template
|
|
220
|
+
# - content for VM template
|
|
221
|
+
#-------------------------------------------------------------------
|
|
222
|
+
def create_app_template(image, idx = 0)
|
|
223
|
+
i_state = OpenNebula::Image::IMAGE_STATES[image['STATE'].to_i]
|
|
224
|
+
|
|
225
|
+
# If the image is used, there is no need to wait until it is
|
|
226
|
+
# ready because the image is already ready to be copied
|
|
227
|
+
if i_state != 'USED' && Integer(image['STATE']) != 1
|
|
228
|
+
# Wait until the image is READY to safe copy it to the MP
|
|
229
|
+
image.wait('READY')
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Rename to avoid clashing names
|
|
233
|
+
app_name = "#{image['NAME']}-#{SecureRandom.hex[0..9]}"
|
|
234
|
+
|
|
235
|
+
dev_prefix = image['TEMPLATE/DEV_PREFIX']
|
|
236
|
+
img_type = image.type_str
|
|
237
|
+
|
|
238
|
+
template64 = "TYPE=#{img_type}\n"
|
|
239
|
+
template64 << "DEV_PREFIX=\"#{dev_prefix}\"\n" if dev_prefix
|
|
240
|
+
|
|
241
|
+
template = <<-EOT
|
|
242
|
+
NAME ="#{app_name}"
|
|
243
|
+
ORIGIN_ID ="#{image['ID']}"
|
|
244
|
+
TYPE ="IMAGE"
|
|
245
|
+
VERSION ="#{OpenNebula::VERSION}"
|
|
246
|
+
|
|
247
|
+
APPTEMPLATE64 = "#{Base64.strict_encode64(template64)}"
|
|
248
|
+
EOT
|
|
249
|
+
|
|
250
|
+
main_template = <<-EOT
|
|
251
|
+
DISK = [
|
|
252
|
+
NAME = "#{img_type}_#{idx}",
|
|
253
|
+
APP = "#{app_name}"
|
|
254
|
+
]
|
|
255
|
+
EOT
|
|
256
|
+
|
|
257
|
+
[template, main_template]
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
#-------------------------------------------------------------------
|
|
261
|
+
# Create application in marketplace
|
|
262
|
+
#
|
|
263
|
+
# @param template [String] APP template
|
|
264
|
+
# @param market_id [Integer] Marketplace to import it
|
|
265
|
+
#
|
|
266
|
+
# @return [Integer] APP ID
|
|
267
|
+
#-------------------------------------------------------------------
|
|
268
|
+
def create_app(template, market_id)
|
|
269
|
+
xml = OpenNebula::MarketPlaceApp.build_xml
|
|
270
|
+
app = OpenNebula::MarketPlaceApp.new(xml, @client)
|
|
271
|
+
|
|
272
|
+
rc = app.allocate(template, market_id)
|
|
273
|
+
|
|
274
|
+
return rc if OpenNebula.is_error?(rc)
|
|
275
|
+
|
|
276
|
+
app.id
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
#-------------------------------------------------------------------
|
|
280
|
+
# Delete IDS apps
|
|
281
|
+
#
|
|
282
|
+
# @param ids [Array] Apps IDs to delete
|
|
283
|
+
#-------------------------------------------------------------------
|
|
284
|
+
def rollback(ids)
|
|
285
|
+
ids.each do |id|
|
|
286
|
+
app = OpenNebula::MarketPlaceApp.new_with_id(id, @client)
|
|
287
|
+
|
|
288
|
+
app.delete
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
#-------------------------------------------------------------------
|
|
293
|
+
# Lookup OpenNebula Images by name or id. Lookup is made on a cached
|
|
294
|
+
# image pool.
|
|
295
|
+
#
|
|
296
|
+
# @param id [Integer, nil] Image id
|
|
297
|
+
# @param name [String] Image name
|
|
298
|
+
#
|
|
299
|
+
# @return [Image]
|
|
300
|
+
#-------------------------------------------------------------------
|
|
301
|
+
def image_lookup(disk)
|
|
302
|
+
# Image pool cache for image id lookup
|
|
303
|
+
if @image_lookup_cache.nil?
|
|
304
|
+
@image_lookup_cache = OpenNebula::ImagePool.new(@client)
|
|
305
|
+
@image_lookup_cache.info
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
# Find image information, from ID or NAME. NAME uses the
|
|
309
|
+
# specified user or template owner namespaces
|
|
310
|
+
image = nil
|
|
311
|
+
|
|
312
|
+
image_id = disk['IMAGE_ID']
|
|
313
|
+
|
|
314
|
+
if image_id
|
|
315
|
+
image = OpenNebula::Image.new_with_id(image_id, @client)
|
|
316
|
+
else
|
|
317
|
+
name = disk['IMAGE']
|
|
318
|
+
uname = disk['IMAGE_UNAME']
|
|
319
|
+
uname ||= self['UNAME']
|
|
320
|
+
|
|
321
|
+
name.gsub!('"', '')
|
|
322
|
+
image = @image_lookup_cache.find do |v|
|
|
323
|
+
v['NAME'] == name && v['UNAME'] == uname
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
return Error.new("Image #{image} not found") if image.nil?
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
rc = image.info
|
|
330
|
+
|
|
331
|
+
return rc if OpenNebula.is_error? rc
|
|
332
|
+
|
|
333
|
+
image.extend(OpenNebula::WaitExt)
|
|
334
|
+
|
|
335
|
+
image
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
end
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
end
|
|
342
|
+
# rubocop:enable Style/ClassAndModuleChildren
|