opennebula 6.10.3 → 6.99.85.pre
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/cloud/CloudClient.rb +3 -3
- data/lib/models/role.rb +349 -823
- data/lib/models/service.rb +156 -80
- data/lib/models/vmrole.rb +703 -0
- data/lib/models/vrrole.rb +284 -0
- data/lib/models.rb +3 -1
- data/lib/opennebula/acl.rb +1 -1
- data/lib/opennebula/acl_pool.rb +1 -1
- data/lib/opennebula/backupjob.rb +1 -1
- data/lib/opennebula/backupjob_pool.rb +1 -1
- data/lib/opennebula/client.rb +1 -1
- data/lib/opennebula/cluster.rb +45 -2
- 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 +1 -1
- data/lib/opennebula/document_json.rb +1 -1
- data/lib/opennebula/document_pool.rb +1 -1
- data/lib/opennebula/document_pool_json.rb +1 -1
- data/lib/opennebula/error.rb +1 -1
- data/lib/opennebula/flow/grammar.rb +1 -1
- data/lib/opennebula/flow/service_pool.rb +1 -1
- data/lib/opennebula/flow/service_template.rb +353 -97
- data/lib/opennebula/flow/service_template_ext.rb +3 -3
- data/lib/opennebula/flow/service_template_pool.rb +1 -1
- data/lib/opennebula/flow/validator.rb +458 -410
- data/lib/opennebula/flow.rb +1 -1
- data/lib/opennebula/group.rb +1 -1
- data/lib/opennebula/group_pool.rb +1 -1
- data/lib/opennebula/hook.rb +1 -1
- data/lib/opennebula/hook_log.rb +1 -1
- data/lib/opennebula/hook_pool.rb +1 -1
- data/lib/opennebula/host.rb +1 -60
- data/lib/opennebula/host_pool.rb +1 -1
- data/lib/opennebula/image.rb +1 -1
- 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 +1 -1
- data/lib/opennebula/marketplace.rb +1 -1
- data/lib/opennebula/marketplace_pool.rb +1 -1
- data/lib/opennebula/marketplaceapp.rb +1 -1
- data/lib/opennebula/marketplaceapp_ext.rb +14 -211
- data/lib/opennebula/marketplaceapp_pool.rb +1 -1
- data/lib/opennebula/oneflow_client.rb +11 -9
- data/lib/opennebula/pool.rb +1 -1
- 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 +1 -1
- data/lib/opennebula/template_ext.rb +1 -1
- data/lib/opennebula/template_pool.rb +1 -1
- data/lib/opennebula/user.rb +1 -1
- data/lib/opennebula/user_pool.rb +1 -1
- data/lib/opennebula/utils.rb +2 -2
- data/lib/opennebula/vdc.rb +1 -1
- data/lib/opennebula/vdc_pool.rb +1 -1
- data/lib/opennebula/virtual_machine.rb +3 -12
- data/lib/opennebula/virtual_machine_ext.rb +2 -31
- data/lib/opennebula/virtual_machine_pool.rb +1 -1
- data/lib/opennebula/virtual_network.rb +1 -1
- data/lib/opennebula/virtual_network_pool.rb +1 -1
- data/lib/opennebula/virtual_router.rb +1 -1
- data/lib/opennebula/virtual_router_pool.rb +1 -1
- data/lib/opennebula/vm_group.rb +1 -1
- data/lib/opennebula/vm_group_pool.rb +1 -1
- data/lib/opennebula/vntemplate.rb +1 -1
- data/lib/opennebula/vntemplate_pool.rb +1 -1
- data/lib/opennebula/wait_ext.rb +1 -1
- data/lib/opennebula/x509_auth.rb +1 -1
- data/lib/opennebula/xml_element.rb +2 -2
- 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/opennebula.rb +2 -2
- metadata +6 -67
- data/lib/ActionManager.rb +0 -280
- data/lib/CommandManager.rb +0 -328
- data/lib/DriverExecHelper.rb +0 -213
- data/lib/HostSyncManager.rb +0 -111
- data/lib/OpenNebulaDriver.rb +0 -223
- data/lib/VirtualMachineDriver.rb +0 -404
- data/lib/datacenter.rb +0 -1319
- data/lib/datastore.rb +0 -1049
- data/lib/distributed_firewall.rb +0 -293
- data/lib/file_helper.rb +0 -374
- data/lib/host.rb +0 -1518
- data/lib/logical_port.rb +0 -50
- data/lib/logical_switch.rb +0 -77
- data/lib/memoize.rb +0 -74
- data/lib/network.rb +0 -705
- data/lib/nsx_client.rb +0 -157
- data/lib/nsx_component.rb +0 -28
- data/lib/nsx_constants.rb +0 -162
- data/lib/nsx_driver.rb +0 -91
- data/lib/nsx_error.rb +0 -77
- data/lib/nsx_rule.rb +0 -206
- data/lib/nsxt_client.rb +0 -189
- data/lib/nsxt_dfw.rb +0 -196
- data/lib/nsxt_logical_port.rb +0 -94
- data/lib/nsxt_rule.rb +0 -188
- data/lib/nsxt_tz.rb +0 -38
- data/lib/nsxv_client.rb +0 -189
- data/lib/nsxv_dfw.rb +0 -202
- data/lib/nsxv_logical_port.rb +0 -107
- data/lib/nsxv_rule.rb +0 -172
- data/lib/nsxv_tz.rb +0 -41
- data/lib/opaque_network.rb +0 -134
- data/lib/rest_client.rb +0 -191
- data/lib/scripts_common.rb +0 -176
- data/lib/transport_zone.rb +0 -43
- data/lib/vcenter_driver.rb +0 -152
- data/lib/vcenter_importer.rb +0 -626
- data/lib/vi_client.rb +0 -273
- data/lib/vi_helper.rb +0 -328
- data/lib/virtual_machine.rb +0 -3574
- data/lib/virtual_wire.rb +0 -158
- data/lib/vm_device.rb +0 -80
- data/lib/vm_disk.rb +0 -202
- data/lib/vm_folder.rb +0 -69
- data/lib/vm_helper.rb +0 -30
- data/lib/vm_monitor.rb +0 -305
- data/lib/vm_nic.rb +0 -70
- data/lib/vm_template.rb +0 -2112
- data/lib/vmm_importer.rb +0 -165
data/lib/distributed_firewall.rb
DELETED
@@ -1,293 +0,0 @@
|
|
1
|
-
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-2024, 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
|
-
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
|
19
|
-
|
20
|
-
if !ONE_LOCATION
|
21
|
-
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' \
|
22
|
-
unless defined?(RUBY_LIB_LOCATION)
|
23
|
-
GEMS_LOCATION = '/usr/share/one/gems' \
|
24
|
-
unless defined?(GEMS_LOCATION)
|
25
|
-
else
|
26
|
-
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' \
|
27
|
-
unless defined?(RUBY_LIB_LOCATION)
|
28
|
-
GEMS_LOCATION = ONE_LOCATION + '/share/gems' \
|
29
|
-
unless defined?(GEMS_LOCATION)
|
30
|
-
end
|
31
|
-
|
32
|
-
# rubocop: disable all
|
33
|
-
# %%RUBYGEMS_SETUP_BEGIN%%
|
34
|
-
if File.directory?(GEMS_LOCATION)
|
35
|
-
real_gems_path = File.realpath(GEMS_LOCATION)
|
36
|
-
if !defined?(Gem) || Gem.path != [real_gems_path]
|
37
|
-
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
38
|
-
|
39
|
-
# Suppress warnings from Rubygems
|
40
|
-
# https://github.com/OpenNebula/one/issues/5379
|
41
|
-
begin
|
42
|
-
verb = $VERBOSE
|
43
|
-
$VERBOSE = nil
|
44
|
-
require 'rubygems'
|
45
|
-
Gem.use_paths(real_gems_path)
|
46
|
-
ensure
|
47
|
-
$VERBOSE = verb
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
# %%RUBYGEMS_SETUP_END%%
|
52
|
-
# rubocop: enable all
|
53
|
-
|
54
|
-
$LOAD_PATH << RUBY_LIB_LOCATION
|
55
|
-
|
56
|
-
require 'nsx_rule'
|
57
|
-
|
58
|
-
# Class DistributedFirewall
|
59
|
-
# Naming convention for rules names:
|
60
|
-
# "<sg_id>-<sg_name>-<vm_id>-<vm_deploy_id>-<nic_id>"
|
61
|
-
# <sg_id> : Security Group ID
|
62
|
-
# <sg_name> : Security Group name
|
63
|
-
# <vm_id> : Virtual Machine ID
|
64
|
-
# <vm_deploy_id> : Vmware virtual machine reference ( vm-XXX )
|
65
|
-
# <nic_id> : NIC ID in the virtual machine
|
66
|
-
class DistributedFirewall < NSXComponent
|
67
|
-
|
68
|
-
include NSXDriver::NSXRule
|
69
|
-
|
70
|
-
# ATTRIBUTES
|
71
|
-
attr_reader :one_section_name
|
72
|
-
|
73
|
-
def self.new_child(nsx_client)
|
74
|
-
case nsx_client
|
75
|
-
when NSXTClient
|
76
|
-
NSXTdfw.new(nsx_client)
|
77
|
-
when NSXVClient
|
78
|
-
NSXVdfw.new(nsx_client)
|
79
|
-
else
|
80
|
-
error_msg = "Unknown object type: #{nsx_client}"
|
81
|
-
error = NSXError::UnknownObject.new(error_msg)
|
82
|
-
raise error
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# Sections
|
87
|
-
# Creates OpenNebula section if not exists and returns
|
88
|
-
# its section_id. Returns its section_id if OpenNebula
|
89
|
-
# section already exists
|
90
|
-
def init_section; end
|
91
|
-
|
92
|
-
# Get all sections
|
93
|
-
def sections; end
|
94
|
-
|
95
|
-
# Get section by id
|
96
|
-
def section_by_id(section_id); end
|
97
|
-
|
98
|
-
# Get section by name
|
99
|
-
def section_by_name(section_name); end
|
100
|
-
|
101
|
-
# Create new section
|
102
|
-
def create_section(section_name); end
|
103
|
-
|
104
|
-
# Delete section
|
105
|
-
def delete_section(section_id); end
|
106
|
-
|
107
|
-
# Rules
|
108
|
-
# Get all rules
|
109
|
-
def rules; end
|
110
|
-
|
111
|
-
# Get rule by id
|
112
|
-
def rule_by_id; end
|
113
|
-
|
114
|
-
# Get rule by name
|
115
|
-
def rules_by_name; end
|
116
|
-
|
117
|
-
# Create new rule
|
118
|
-
def create_rule; end
|
119
|
-
|
120
|
-
# Update rule
|
121
|
-
def update_rule; end
|
122
|
-
|
123
|
-
# Delete rule
|
124
|
-
def delete_rule; end
|
125
|
-
|
126
|
-
def extract_nic_data(nic, nsx_client, vm)
|
127
|
-
# Network attributes
|
128
|
-
nic_id = nic.xpath('NIC_ID').text
|
129
|
-
nic_name = nil
|
130
|
-
nic_lp = nil
|
131
|
-
network_id = nic.xpath('NETWORK_ID').text
|
132
|
-
network_name = nic.xpath('NETWORK').text
|
133
|
-
network_vcref = nic.xpath('VCENTER_NET_REF').text
|
134
|
-
network_pgtype = nic.xpath('VCENTER_PORTGROUP_TYPE').text
|
135
|
-
network_mac = nic.xpath('MAC').text
|
136
|
-
|
137
|
-
# Virtual Machine devices
|
138
|
-
vm_devices = vm.item.config.hardware.device
|
139
|
-
vm_devices.each do |device|
|
140
|
-
next unless VCenterDriver::Network.nic?(device)
|
141
|
-
|
142
|
-
next if device.macAddress != network_mac
|
143
|
-
|
144
|
-
device_label = device.deviceInfo.label
|
145
|
-
nic_name = "#{vm.item.name}-#{nic_id}-#{device_label}"
|
146
|
-
|
147
|
-
case network_pgtype
|
148
|
-
when NSXConstants::NSXT_LS_TYPE
|
149
|
-
lpid = device.externalId
|
150
|
-
nic_lp = LogicalPort.new_child(nsx_client, lpid)
|
151
|
-
raise "Logical port id: #{lpid} not found" unless nic_lp
|
152
|
-
when NSXConstants::NSXV_LS_TYPE
|
153
|
-
# lpid is vm instanceUuid.sufix
|
154
|
-
# sufix is device number but removing first number
|
155
|
-
suffix = device.key.to_s[1..-1]
|
156
|
-
lpid = "#{vm.item.config.instanceUuid}.#{suffix}"
|
157
|
-
nic_lp = lpid
|
158
|
-
else
|
159
|
-
error_msg = "Network type is: #{network_pgtype} \
|
160
|
-
and should be \
|
161
|
-
#{NSXConstants::NSXT_LS_TYPE} \
|
162
|
-
or #{NSXConstants::NSXV_LS_TYPE}"
|
163
|
-
error = NSXError::UnknownObject.new(error_msg)
|
164
|
-
raise error
|
165
|
-
end
|
166
|
-
break
|
167
|
-
end
|
168
|
-
|
169
|
-
{
|
170
|
-
:id => nic_id,
|
171
|
-
:name => nic_name,
|
172
|
-
:network_name => network_name,
|
173
|
-
:network_id => network_id,
|
174
|
-
:network_vcref => network_vcref,
|
175
|
-
:lp => nic_lp
|
176
|
-
}
|
177
|
-
end
|
178
|
-
|
179
|
-
# Create OpenNebula fw rules for an instance (given a template)
|
180
|
-
def create_rules(deploy_id, template, only_attached)
|
181
|
-
template_xml = Nokogiri::XML(template)
|
182
|
-
|
183
|
-
# OpenNebula host
|
184
|
-
host_name = template_xml
|
185
|
-
.xpath('//HISTORY_RECORDS/HISTORY[last()]/HOSTNAME')
|
186
|
-
.text
|
187
|
-
one_host = VCenterDriver::VIHelper
|
188
|
-
.find_by_name(OpenNebula::HostPool, host_name)
|
189
|
-
rc = one_host.info
|
190
|
-
if OpenNebula.is_error?(rc)
|
191
|
-
err_msg = rc.message
|
192
|
-
raise err_msg
|
193
|
-
end
|
194
|
-
host_id = one_host['ID']
|
195
|
-
|
196
|
-
# OpenNebula VM
|
197
|
-
one_vm = VCenterDriver::VIHelper
|
198
|
-
.one_item(OpenNebula::VirtualMachine, deploy_id)
|
199
|
-
|
200
|
-
vm_data = {
|
201
|
-
:id => template_xml.xpath('/VM/ID').text,
|
202
|
-
:deploy_id => deploy_id
|
203
|
-
}
|
204
|
-
|
205
|
-
# vCenter VirtualMachine
|
206
|
-
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
|
207
|
-
vm = VCenterDriver::VirtualMachine
|
208
|
-
.new_one(vi_client, deploy_id, one_vm)
|
209
|
-
|
210
|
-
# Search NSX Nics
|
211
|
-
# First try to search only new attached NSX Nics
|
212
|
-
nsx_nics = NSXDriver::LogicalSwitch.nsx_nics(template_xml,
|
213
|
-
only_attached)
|
214
|
-
# If there is no NSX Nics
|
215
|
-
return if nsx_nics.empty?
|
216
|
-
|
217
|
-
# Create rules for each NSX Nic
|
218
|
-
nsx_nics.each do |nic|
|
219
|
-
# Extract NIC data
|
220
|
-
nic_data = extract_nic_data(nic, @nsx_client, vm)
|
221
|
-
# Get all Security Groups belonging to each NIC.
|
222
|
-
sec_groups = nic.xpath('SECURITY_GROUPS').text.split(',')
|
223
|
-
sec_groups.each do |sec_group|
|
224
|
-
sg_rules_array = []
|
225
|
-
# Get all rules belonging to this Security Group.
|
226
|
-
xp = "//SECURITY_GROUP_RULE[SECURITY_GROUP_ID=#{sec_group}]"
|
227
|
-
sg_rules = template_xml.xpath(xp)
|
228
|
-
sg_rules.each do |sg_rule|
|
229
|
-
# Create rules spec
|
230
|
-
rule_data = extract_rule_data(sg_rule)
|
231
|
-
rule_spec = rule_spec(rule_data,
|
232
|
-
vm_data,
|
233
|
-
nic_data,
|
234
|
-
@nsx_client)
|
235
|
-
sg_rules_array.push(rule_spec)
|
236
|
-
end
|
237
|
-
# Create NSX rules
|
238
|
-
sg_rules_array.each do |sg_spec|
|
239
|
-
create_rule(sg_spec)
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
def clear_all_rules(template)
|
246
|
-
template_xml = Nokogiri::XML(template)
|
247
|
-
vm_id = template_xml.xpath('/VM/ID').text
|
248
|
-
vm_deploy_id = template_xml.xpath('/VM/DEPLOY_ID').text
|
249
|
-
regex = "-#{vm_id}-#{vm_deploy_id}-"
|
250
|
-
rules = rules_by_regex(regex, @one_section_id)
|
251
|
-
rules.each do |rule|
|
252
|
-
delete_rule(rule['id'], @one_section_id) if rule
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
# Remove OpenNebula created fw rules for an instance (given a template)
|
257
|
-
def clear_rules(template, only_detached)
|
258
|
-
template_xml = Nokogiri::XML(template)
|
259
|
-
# OpenNebula Instance IDs
|
260
|
-
vm_id = template_xml.xpath('/VM/ID').text
|
261
|
-
vm_deploy_id = template_xml.xpath('/VM/DEPLOY_ID').text
|
262
|
-
|
263
|
-
# First try to search only new attached NSX Nics
|
264
|
-
nsx_nics = NSXDriver::LogicalSwitch.nsx_nics(template_xml,
|
265
|
-
only_detached)
|
266
|
-
|
267
|
-
# If there is no NSX Nics
|
268
|
-
return if nsx_nics.empty?
|
269
|
-
|
270
|
-
nsx_nics.each do |nic|
|
271
|
-
nic_id = nic.xpath('NIC_ID').text
|
272
|
-
# network_id = nic.xpath('NETWORK_ID').text
|
273
|
-
sec_groups = nic.xpath('SECURITY_GROUPS').text.split(',')
|
274
|
-
sec_groups.each do |sec_group|
|
275
|
-
# Get Security Group ID and NAME
|
276
|
-
xp = "//SECURITY_GROUP_RULE[SECURITY_GROUP_ID=#{sec_group}]"
|
277
|
-
sg_id = template_xml.xpath(xp)[0]
|
278
|
-
.xpath('SECURITY_GROUP_ID').text
|
279
|
-
sg_name = template_xml.xpath(xp)[0]
|
280
|
-
.xpath('SECURITY_GROUP_NAME').text
|
281
|
-
rule_name = "#{sg_id}-#{sg_name}-#{vm_id}"
|
282
|
-
rule_name << "-#{vm_deploy_id}-#{nic_id}"
|
283
|
-
rules = rules_by_name(rule_name, @one_section_id)
|
284
|
-
rules.each do |rule|
|
285
|
-
delete_rule(rule['id'], @one_section_id) if rule
|
286
|
-
end
|
287
|
-
end
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
end
|
292
|
-
|
293
|
-
end
|
data/lib/file_helper.rb
DELETED
@@ -1,374 +0,0 @@
|
|
1
|
-
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-2024, 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 'fileutils'
|
18
|
-
require 'tempfile'
|
19
|
-
|
20
|
-
##############################################################################
|
21
|
-
# Module VCenterDriver
|
22
|
-
##############################################################################
|
23
|
-
module VCenterDriver
|
24
|
-
|
25
|
-
##########################################################################
|
26
|
-
# Class FileHelper
|
27
|
-
##########################################################################
|
28
|
-
class FileHelper
|
29
|
-
|
30
|
-
def self.sanitize(text)
|
31
|
-
# Bad as defined by wikipedia:
|
32
|
-
# https://en.wikipedia.org/wiki/Filename in
|
33
|
-
# Reserved_characters_and_words
|
34
|
-
# Also have to escape the backslash
|
35
|
-
bad_chars = ['/', '\\', '?', '%', '*', ':',
|
36
|
-
'|', '"', '<', '>', '.', ' ']
|
37
|
-
bad_chars.each do |bad_char|
|
38
|
-
text.gsub!(bad_char, '_')
|
39
|
-
end
|
40
|
-
text
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.get_img_name(
|
44
|
-
disk,
|
45
|
-
vm_id,
|
46
|
-
_vm_name,
|
47
|
-
instantiate_as_persistent = false
|
48
|
-
)
|
49
|
-
if disk['PERSISTENT'] == 'YES' || disk['TYPE'] == 'CDROM'
|
50
|
-
disk['SOURCE']
|
51
|
-
else
|
52
|
-
disk_id = disk['DISK_ID']
|
53
|
-
if disk['SOURCE']
|
54
|
-
if instantiate_as_persistent &&
|
55
|
-
disk['OPENNEBULA_MANAGED'] &&
|
56
|
-
disk['OPENNEBULA_MANAGED'].upcase == 'NO'
|
57
|
-
disk['SOURCE'] # Treat this disk as if was persistent
|
58
|
-
else
|
59
|
-
image_name = disk['SOURCE'].split('.').first
|
60
|
-
"#{image_name}-#{vm_id}-#{disk_id}.vmdk"
|
61
|
-
end
|
62
|
-
else
|
63
|
-
ds_volatile_dir =
|
64
|
-
disk['VCENTER_DS_VOLATILE_DIR'] || 'one-volatile'
|
65
|
-
"#{ds_volatile_dir}/#{vm_id}/one-#{vm_id}-#{disk_id}.vmdk"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# REMOVE: no need to change...
|
71
|
-
def self.get_img_name_from_path(path, vm_id, disk_id)
|
72
|
-
# NOTE: This will probably fail if the basename contains '.'
|
73
|
-
"#{path.split('.').first}-#{vm_id}-#{disk_id}.vmdk"
|
74
|
-
end
|
75
|
-
|
76
|
-
def self.remote_or_needs_unpack?(file)
|
77
|
-
!remote?(file).nil? || needs_unpack?(file)
|
78
|
-
end
|
79
|
-
|
80
|
-
def self.remote?(file)
|
81
|
-
file.match(%r{^https?://}) || file.match(%r{^s3?://})
|
82
|
-
end
|
83
|
-
|
84
|
-
def self.from_s3?(file)
|
85
|
-
file.match(%r{^s3?://})
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.vmdk?(file)
|
89
|
-
type = `file #{file}`
|
90
|
-
|
91
|
-
type.include? 'VMware'
|
92
|
-
end
|
93
|
-
|
94
|
-
def self.iso?(file)
|
95
|
-
type = `file #{file}`
|
96
|
-
|
97
|
-
type.include? 'ISO'
|
98
|
-
end
|
99
|
-
|
100
|
-
def self.get_type(file)
|
101
|
-
type = `file -P bytes=256 -b --mime-type #{file}`
|
102
|
-
if $?.exitstatus != 0 # rubocop:disable Style/SpecialGlobalVars
|
103
|
-
STDERR.puts "Can not read file #{file}"
|
104
|
-
exit(-1)
|
105
|
-
end
|
106
|
-
type.strip
|
107
|
-
end
|
108
|
-
|
109
|
-
def self.needs_unpack?(file_path)
|
110
|
-
type = get_type(file_path)
|
111
|
-
type.gsub!(%r{^application/(x-)?}, '')
|
112
|
-
['bzip2', 'gzip', 'tar'].include?(type)
|
113
|
-
end
|
114
|
-
|
115
|
-
def self.vcenter_file_info(file_path)
|
116
|
-
if File.directory?(file_path)
|
117
|
-
files = Dir["#{file_path}/*.vmdk"]
|
118
|
-
found = false
|
119
|
-
count = 0
|
120
|
-
last = nil
|
121
|
-
|
122
|
-
files.each do |f|
|
123
|
-
if get_type(f).strip == 'text/plain'
|
124
|
-
file_path = f
|
125
|
-
found = true
|
126
|
-
break
|
127
|
-
else
|
128
|
-
count += 1
|
129
|
-
last = f
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
if !found
|
134
|
-
if count == 1
|
135
|
-
file_path = last
|
136
|
-
found = true
|
137
|
-
else
|
138
|
-
STDERR.puts 'Could not find vmdk'
|
139
|
-
exit(-1)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
case get_type(file_path).strip
|
145
|
-
when 'application/octet-stream'
|
146
|
-
{
|
147
|
-
:type => :standalone,
|
148
|
-
:file => file_path,
|
149
|
-
:dir => File.dirname(file_path)
|
150
|
-
}
|
151
|
-
when 'application/x-iso9660-image'
|
152
|
-
{
|
153
|
-
:type => :standalone,
|
154
|
-
:file => file_path,
|
155
|
-
:dir => File.dirname(file_path),
|
156
|
-
:extension => '.iso'
|
157
|
-
}
|
158
|
-
when 'text/plain'
|
159
|
-
info = {
|
160
|
-
:type => :flat,
|
161
|
-
:file => file_path,
|
162
|
-
:dir => File.dirname(file_path)
|
163
|
-
}
|
164
|
-
|
165
|
-
files_list = []
|
166
|
-
descriptor = File.read(file_path).split("\n")
|
167
|
-
flat_files = descriptor.select {|l| l.start_with?('RW') }
|
168
|
-
|
169
|
-
flat_files.each do |f|
|
170
|
-
files_list <<
|
171
|
-
info[:dir] +
|
172
|
-
'/' +
|
173
|
-
f
|
174
|
-
.split(' ')[3]
|
175
|
-
.chomp
|
176
|
-
.chomp('"')
|
177
|
-
.reverse
|
178
|
-
.chomp('"')
|
179
|
-
.reverse
|
180
|
-
end
|
181
|
-
|
182
|
-
info[:flat_files] = files_list
|
183
|
-
|
184
|
-
info
|
185
|
-
else
|
186
|
-
STDERR.puts 'Unrecognized file type'
|
187
|
-
exit(-1)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
def self.escape_path(path)
|
192
|
-
path.gsub(' ', '%20')
|
193
|
-
end
|
194
|
-
|
195
|
-
def self.unescape_path(path)
|
196
|
-
path.gsub('%20', ' ')
|
197
|
-
end
|
198
|
-
|
199
|
-
# Recursively downloads vmdk related files and returns filenames
|
200
|
-
def self.get_all_filenames_in_descriptor(descriptor_url, ds)
|
201
|
-
descriptor_filename = File.basename descriptor_url.path
|
202
|
-
# Build array of files to download
|
203
|
-
files_to_download = [descriptor_filename]
|
204
|
-
image_source = descriptor_url.host + descriptor_url.path
|
205
|
-
descriptor_content = ds.get_text_file image_source
|
206
|
-
flat_files = descriptor_content.select {|l| l.start_with?('RW') }
|
207
|
-
flat_files.each do |file|
|
208
|
-
# Get the filename from lines of type
|
209
|
-
# RW 2048000 VMFS "filename-flat.vdmdk"
|
210
|
-
file_to_download = file.split(' ')[3][1..-2]
|
211
|
-
files_to_download << file_to_download
|
212
|
-
image_path =
|
213
|
-
File
|
214
|
-
.dirname(
|
215
|
-
descriptor_url.host+descriptor_url.path
|
216
|
-
)
|
217
|
-
next unless ds.descriptor?(
|
218
|
-
image_path + '/' + file_to_download
|
219
|
-
)
|
220
|
-
|
221
|
-
files_to_download <<
|
222
|
-
download_all_filenames_in_descriptor(
|
223
|
-
image_path + '/' + file_to_download
|
224
|
-
)
|
225
|
-
end
|
226
|
-
|
227
|
-
files_to_download
|
228
|
-
end
|
229
|
-
|
230
|
-
def self.download_vmdks(files_to_download, url_prefix, temp_folder, ds)
|
231
|
-
# Download files
|
232
|
-
url_prefix += '/'
|
233
|
-
|
234
|
-
VCenterDriver::VIClient.in_silence do
|
235
|
-
files_to_download.each do |file|
|
236
|
-
ds.download_file(url_prefix + file, temp_folder + file)
|
237
|
-
end
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
# Receives a VMDK descriptor or file, downloads all
|
242
|
-
# related files, creates a tar.gz and dumps it in stdout
|
243
|
-
def self.dump_vmdk_tar_gz(vcenter_url, ds)
|
244
|
-
image_source = vcenter_url.host + vcenter_url.path
|
245
|
-
if ds.descriptor?(image_source)
|
246
|
-
files_to_download =
|
247
|
-
get_all_filenames_in_descriptor(
|
248
|
-
vcenter_url,
|
249
|
-
ds
|
250
|
-
)
|
251
|
-
|
252
|
-
descriptor_name = File.basename vcenter_url.path
|
253
|
-
temp_folder = VAR_LOCATION + '/vcenter/' + descriptor_name + '/'
|
254
|
-
unless File.directory?(temp_folder)
|
255
|
-
FileUtils
|
256
|
-
.mkdir_p(
|
257
|
-
temp_folder
|
258
|
-
)
|
259
|
-
end
|
260
|
-
|
261
|
-
image_path = File.dirname(vcenter_url.host+vcenter_url.path)
|
262
|
-
download_vmdks(files_to_download, image_path, temp_folder, ds)
|
263
|
-
|
264
|
-
# Create tar.gz
|
265
|
-
rs = system(
|
266
|
-
"cd #{temp_folder} \&& tar czf #{descriptor_name}.tar.gz \
|
267
|
-
#{files_to_download.join(' ')} > /dev/null 2>&1"
|
268
|
-
)
|
269
|
-
unless rs
|
270
|
-
FileUtils.rm_rf temp_folder
|
271
|
-
raise "Error creating tar file for #{descriptor_name}"
|
272
|
-
end
|
273
|
-
|
274
|
-
# Cat file to stdout
|
275
|
-
rs = system("cat #{temp_folder + descriptor_name}.tar.gz")
|
276
|
-
unless rs
|
277
|
-
FileUtils.rm_rf temp_folder
|
278
|
-
raise "Error reading tar for #{descriptor_name}"
|
279
|
-
end
|
280
|
-
|
281
|
-
# Delete tar.gz
|
282
|
-
rs = system(
|
283
|
-
"cd #{temp_folder} \
|
284
|
-
&& rm #{descriptor_name}.tar.gz #{
|
285
|
-
files_to_download
|
286
|
-
.join(' ')}"
|
287
|
-
)
|
288
|
-
unless rs
|
289
|
-
FileUtils.rm_rf temp_folder
|
290
|
-
raise "Error removing tar for #{descriptor_name}"
|
291
|
-
end
|
292
|
-
else
|
293
|
-
# Setting "." as the source will read from the stdin
|
294
|
-
VCenterDriver::VIClient.in_stderr_silence do
|
295
|
-
descriptor_name = File.basename vcenter_url.path
|
296
|
-
file_to_download = [vcenter_url.path]
|
297
|
-
temp_folder =
|
298
|
-
VAR_LOCATION + '/vcenter/' + descriptor_name + '/'
|
299
|
-
|
300
|
-
unless File
|
301
|
-
.directory?(
|
302
|
-
temp_folder + File
|
303
|
-
.dirname(
|
304
|
-
vcenter_url
|
305
|
-
.path
|
306
|
-
) + '/'
|
307
|
-
)
|
308
|
-
FileUtils
|
309
|
-
.mkdir_p(temp_folder + File
|
310
|
-
.dirname(
|
311
|
-
vcenter_url
|
312
|
-
.path
|
313
|
-
) + '/')
|
314
|
-
end
|
315
|
-
|
316
|
-
download_vmdks(
|
317
|
-
file_to_download,
|
318
|
-
vcenter_url.host,
|
319
|
-
temp_folder,
|
320
|
-
ds
|
321
|
-
)
|
322
|
-
|
323
|
-
temp_folder += File.dirname(vcenter_url.path)
|
324
|
-
|
325
|
-
# Create tar.gz
|
326
|
-
rs = system(
|
327
|
-
"cd #{temp_folder} && tar czf #{descriptor_name}.tar.gz\
|
328
|
-
#{descriptor_name} > /dev/null 2>&1"
|
329
|
-
)
|
330
|
-
unless rs
|
331
|
-
(
|
332
|
-
FileUtils
|
333
|
-
.rm_rf(
|
334
|
-
temp_folder
|
335
|
-
)
|
336
|
-
raise "Error creating tar \
|
337
|
-
file for #{descriptor_name}")
|
338
|
-
end
|
339
|
-
|
340
|
-
# Cat file to stdout
|
341
|
-
rs = system(
|
342
|
-
"cat #{temp_folder + '/' + descriptor_name}.tar.gz"
|
343
|
-
)
|
344
|
-
unless rs
|
345
|
-
(
|
346
|
-
FileUtils
|
347
|
-
.rm_rf(
|
348
|
-
temp_folder
|
349
|
-
)
|
350
|
-
raise "Error reading tar for #{descriptor_name}")
|
351
|
-
end # rubocop:disable Style/Semicolon
|
352
|
-
|
353
|
-
# Delete tar.gz
|
354
|
-
rs = system(
|
355
|
-
"cd #{temp_folder} \
|
356
|
-
&& rm #{descriptor_name}.tar.gz #{descriptor_name}"
|
357
|
-
)
|
358
|
-
unless rs
|
359
|
-
(
|
360
|
-
FileUtils
|
361
|
-
.rm_rf(
|
362
|
-
temp_folder
|
363
|
-
)
|
364
|
-
raise "Error removing tar for #{descriptor_name}")
|
365
|
-
end # rubocop:disable Style/Semicolon
|
366
|
-
end
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
end
|
371
|
-
# class FileHelper
|
372
|
-
|
373
|
-
end
|
374
|
-
# module VCenterDriver
|