mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-28 17:57:22 +03:00
L #~: Refactor vcenter driver (#110)
Signed-off-by: Carlos Herrera <cherrera@opennebula.io>
This commit is contained in:
parent
a5041b4dee
commit
3f973e5a44
@ -123,7 +123,7 @@ def create_dpg(one_vnet, dc, cluster, vi_client)
|
||||
if dvs
|
||||
pnics_available = nil
|
||||
if pnics && !pnics.empty?
|
||||
pnics_available = esx_host.get_available_pnics
|
||||
pnics_available = esx_host.available_pnics
|
||||
end
|
||||
esx_host.assign_proxy_switch(dvs,
|
||||
sw_name,
|
||||
@ -164,7 +164,7 @@ def create_pg(one_vnet, esx_host)
|
||||
esx_host.lock # Exclusive lock for ESX host operation
|
||||
|
||||
pnics_available = nil
|
||||
pnics_available = esx_host.get_available_pnics if pnics
|
||||
pnics_available = esx_host.available_pnics if pnics
|
||||
|
||||
# Get port group if it exists
|
||||
pg = esx_host.pg_exists(pg_name)
|
||||
|
@ -88,6 +88,7 @@ AllCops:
|
||||
- src/im_mad/remotes/one.d/poll
|
||||
- src/im_mad/remotes/az.d/poll
|
||||
- src/im_mad/remotes/lib/vcenter_cluster.rb
|
||||
- src/im_mad/remotes/lib/vcenter_monitor.rb
|
||||
- src/vnm_mad/remotes/ovswitch/post
|
||||
- src/vnm_mad/remotes/ovswitch/clean
|
||||
- src/vnm_mad/remotes/ovswitch/pre
|
||||
@ -386,17 +387,8 @@ AllCops:
|
||||
- src/oca/ruby/deprecated/OpenNebula.rb
|
||||
- src/vmm_mad/dummy/one_vmm_dummy.rb
|
||||
- src/vmm_mad/remotes/one/opennebula_driver.rb
|
||||
- src/vmm_mad/remotes/lib/vcenter_driver/datastore.rb
|
||||
- src/vmm_mad/remotes/lib/vcenter_driver/vcenter_importer.rb
|
||||
- src/vmm_mad/remotes/lib/vcenter_driver/vi_helper.rb
|
||||
- src/vmm_mad/remotes/lib/vcenter_driver/network.rb
|
||||
- src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb
|
||||
- src/vmm_mad/remotes/lib/vcenter_driver/vm_template.rb
|
||||
- src/vmm_mad/remotes/lib/vcenter_driver/file_helper.rb
|
||||
- src/vmm_mad/remotes/lib/vcenter_driver/vi_client.rb
|
||||
- src/vmm_mad/remotes/lib/vcenter_driver/host.rb
|
||||
- src/vmm_mad/remotes/lib/vcenter_driver/datacenter.rb
|
||||
- src/vmm_mad/remotes/lib/vcenter_driver/memoize.rb
|
||||
- src/vmm_mad/remotes/lib/lxd/mapper/qcow2.rb
|
||||
- src/vmm_mad/remotes/lib/lxd/mapper/mapper.rb
|
||||
- src/vmm_mad/remotes/lib/lxd/mapper/rbd.rb
|
||||
|
@ -86,7 +86,7 @@ target_path = "#{ds_image_dir}/#{id}"
|
||||
# If image is in a remote http location it has to be downloaded
|
||||
# or if is a zipped file it has to be unzipped in a temp folder
|
||||
|
||||
if VCenterDriver::FileHelper.is_remote_or_needs_unpack?(img_path)
|
||||
if VCenterDriver::FileHelper.remote_or_needs_unpack?(img_path)
|
||||
temp_folder = File.join(VAR_LOCATION, "vcenter/#{target_path}")
|
||||
temp_file = File.join(temp_folder, File.basename(img_path))
|
||||
# if the original file doesnt have the vmdk extension, add it
|
||||
@ -140,25 +140,25 @@ files_to_upload.each_with_index do |f, index|
|
||||
path = "#{target_path}/#{filename}"
|
||||
|
||||
# remove gz or bz2 if part of filename
|
||||
if path.end_with?('gz') && VCenterDriver::FileHelper.is_vmdk?(f)
|
||||
if path.end_with?('gz') && VCenterDriver::FileHelper.vmdk?(f)
|
||||
path.gsub!(/gz$/, '')
|
||||
end
|
||||
|
||||
if path.end_with?('bz2') && VCenterDriver::FileHelper.is_vmdk?(f)
|
||||
if path.end_with?('bz2') && VCenterDriver::FileHelper.vmdk?(f)
|
||||
path.gsub!(/bz2$/, '')
|
||||
end
|
||||
end
|
||||
|
||||
# Change path if vmdk is part of filename but it's not the extension
|
||||
# rubocop:disable Style/DoubleNegation
|
||||
if !!/[^.]+vmdk$/.match(path) && VCenterDriver::FileHelper.is_vmdk?(f)
|
||||
if !!/[^.]+vmdk$/.match(path) && VCenterDriver::FileHelper.vmdk?(f)
|
||||
path.gsub!(/vmdk$/, '')
|
||||
extension = '.vmdk'
|
||||
end
|
||||
# rubocop:enable Style/DoubleNegation
|
||||
|
||||
# Add iso extension if file is an ISO file
|
||||
if VCenterDriver::FileHelper.is_iso?(f)
|
||||
if VCenterDriver::FileHelper.iso?(f)
|
||||
path = "#{File.dirname(path)}/#{File.basename(path, '.*')}"
|
||||
extension = '.iso'
|
||||
end
|
||||
|
@ -76,7 +76,7 @@ begin
|
||||
|
||||
vm = VCenterDriver::VirtualMachine.new(vi_client, vm_ref, vmid)
|
||||
|
||||
if vm.has_snapshots?
|
||||
if vm.snapshots?
|
||||
raise "'disk-saveas' not supported in VMs with system snapshots."
|
||||
end
|
||||
|
||||
|
@ -97,10 +97,10 @@ begin
|
||||
vm.destroy_disk(disk)
|
||||
else
|
||||
@error_message = "Error unregistering vm #{vmid} (#{vm_ref})."
|
||||
vm.poweroff_hard if vm.is_powered_on?
|
||||
vm.poweroff_hard if vm.powered_on?
|
||||
|
||||
if vm.instantiated_as_persistent?
|
||||
vm.remove_all_snapshots if vm.has_snapshots?
|
||||
vm.remove_all_snapshots if vm.snapshots?
|
||||
vm.convert_to_template
|
||||
else
|
||||
vm.destroy
|
||||
|
@ -71,7 +71,7 @@ begin
|
||||
vm = VCenterDriver::VirtualMachine.new(vi_client, vm_ref, vmid)
|
||||
vmperst = vm.instantiated_as_persistent?
|
||||
|
||||
vm.remove_all_snapshots if vm.has_snapshots?
|
||||
vm.remove_all_snapshots if vm.snapshots?
|
||||
disk = vm.disk(disk_id)
|
||||
|
||||
# Don't detach persistent disks if the VM has snapshots
|
||||
|
@ -63,7 +63,7 @@ begin
|
||||
vm = VCenterDriver::VirtualMachine.new(vi_client, vm_ref, vmid)
|
||||
|
||||
# Cannot resize if VM has snapshots
|
||||
if vm.has_snapshots?
|
||||
if vm.snapshots?
|
||||
raise "'disk-resize' operation not supported for VMs with snapshots."
|
||||
end
|
||||
|
||||
|
@ -126,7 +126,7 @@ module NSXDriver
|
||||
# Virtual Machine devices
|
||||
vm_devices = vm.item.config.hardware.device
|
||||
vm_devices.each do |device|
|
||||
next unless vm.is_nic?(device)
|
||||
next unless VCenterDriver::Network.nic?(device)
|
||||
|
||||
next if device.macAddress != network_mac
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -17,235 +17,339 @@
|
||||
require 'fileutils'
|
||||
require 'tempfile'
|
||||
|
||||
##############################################################################
|
||||
# Module VCenterDriver
|
||||
##############################################################################
|
||||
module VCenterDriver
|
||||
|
||||
class FileHelper
|
||||
##########################################################################
|
||||
# Class FileHelper
|
||||
##########################################################################
|
||||
class FileHelper
|
||||
|
||||
def self.get_img_name(disk, vm_id, vm_name, instantiate_as_persistent=false)
|
||||
if disk["PERSISTENT"] == "YES" || disk["TYPE"] == "CDROM"
|
||||
return disk["SOURCE"]
|
||||
else
|
||||
disk_id = disk["DISK_ID"]
|
||||
if disk["SOURCE"]
|
||||
if instantiate_as_persistent &&
|
||||
disk["OPENNEBULA_MANAGED"] &&
|
||||
disk["OPENNEBULA_MANAGED"].upcase == "NO"
|
||||
return disk["SOURCE"] # Treat this disk as if was persistent
|
||||
else
|
||||
image_name = disk["SOURCE"].split(".").first
|
||||
return "#{image_name}-#{vm_id}-#{disk_id}.vmdk"
|
||||
end
|
||||
def self.get_img_name(
|
||||
disk,
|
||||
vm_id,
|
||||
_vm_name,
|
||||
instantiate_as_persistent = false
|
||||
)
|
||||
if disk['PERSISTENT'] == 'YES' || disk['TYPE'] == 'CDROM'
|
||||
disk['SOURCE']
|
||||
else
|
||||
ds_volatile_dir = disk["VCENTER_DS_VOLATILE_DIR"] || "one-volatile"
|
||||
return "#{ds_volatile_dir}/#{vm_id}/one-#{vm_id}-#{disk_id}.vmdk"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# REMOVE: no need to change...
|
||||
def self.get_img_name_from_path(path, vm_id, disk_id)
|
||||
# Note: This will probably fail if the basename contains '.'
|
||||
return "#{path.split(".").first}-#{vm_id}-#{disk_id}.vmdk"
|
||||
end
|
||||
|
||||
def self.is_remote_or_needs_unpack?(file)
|
||||
return !is_remote?(file).nil? || needs_unpack?(file)
|
||||
end
|
||||
|
||||
def self.is_remote?(file)
|
||||
file.match(%r{^https?://})
|
||||
end
|
||||
|
||||
def self.is_vmdk?(file)
|
||||
type = %x{file #{file}}
|
||||
|
||||
type.include? "VMware"
|
||||
end
|
||||
|
||||
def self.is_iso?(file)
|
||||
type = %x{file #{file}}
|
||||
|
||||
type.include? "ISO"
|
||||
end
|
||||
|
||||
def self.get_type(file)
|
||||
type = %x{file -b --mime-type #{file}}
|
||||
if $?.exitstatus != 0
|
||||
STDERR.puts "Can not read file #{file}"
|
||||
exit(-1)
|
||||
end
|
||||
type.strip
|
||||
end
|
||||
|
||||
def self.needs_unpack?(file_path)
|
||||
type = get_type(file_path)
|
||||
type.gsub!(%r{^application/(x-)?}, '')
|
||||
return %w{bzip2 gzip tar}.include?(type)
|
||||
end
|
||||
|
||||
def self.vcenter_file_info(file_path)
|
||||
if File.directory?(file_path)
|
||||
files = Dir["#{file_path}/*.vmdk"]
|
||||
found = false
|
||||
count = 0
|
||||
last = nil
|
||||
|
||||
files.each do |f|
|
||||
if get_type(f).strip == "text/plain"
|
||||
file_path = f
|
||||
found = true
|
||||
break
|
||||
disk_id = disk['DISK_ID']
|
||||
if disk['SOURCE']
|
||||
if instantiate_as_persistent &&
|
||||
disk['OPENNEBULA_MANAGED'] &&
|
||||
disk['OPENNEBULA_MANAGED'].upcase == 'NO'
|
||||
disk['SOURCE'] # Treat this disk as if was persistent
|
||||
else
|
||||
image_name = disk['SOURCE'].split('.').first
|
||||
"#{image_name}-#{vm_id}-#{disk_id}.vmdk"
|
||||
end
|
||||
else
|
||||
count += 1
|
||||
last = f
|
||||
end
|
||||
end
|
||||
|
||||
if !found
|
||||
if count == 1
|
||||
file_path = last
|
||||
found = true
|
||||
else
|
||||
STDERR.puts "Could not find vmdk"
|
||||
exit(-1)
|
||||
ds_volatile_dir =
|
||||
disk['VCENTER_DS_VOLATILE_DIR'] || 'one-volatile'
|
||||
"#{ds_volatile_dir}/#{vm_id}/one-#{vm_id}-#{disk_id}.vmdk"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
case get_type(file_path).strip
|
||||
when "application/octet-stream"
|
||||
return {
|
||||
:type => :standalone,
|
||||
:file => file_path,
|
||||
:dir => File.dirname(file_path)
|
||||
}
|
||||
when "application/x-iso9660-image"
|
||||
return {
|
||||
:type => :standalone,
|
||||
:file => file_path,
|
||||
:dir => File.dirname(file_path),
|
||||
:extension => '.iso'
|
||||
}
|
||||
when "text/plain"
|
||||
info = {
|
||||
:type => :flat,
|
||||
:file => file_path,
|
||||
:dir => File.dirname(file_path)
|
||||
}
|
||||
# REMOVE: no need to change...
|
||||
def self.get_img_name_from_path(path, vm_id, disk_id)
|
||||
# Note: This will probably fail if the basename contains '.'
|
||||
"#{path.split('.').first}-#{vm_id}-#{disk_id}.vmdk"
|
||||
end
|
||||
|
||||
files_list = []
|
||||
descriptor = File.read(file_path).split("\n")
|
||||
flat_files = descriptor.select {|l| l.start_with?("RW")}
|
||||
def self.remote_or_needs_unpack?(file)
|
||||
!remote?(file).nil? || needs_unpack?(file)
|
||||
end
|
||||
|
||||
flat_files.each do |f|
|
||||
files_list << info[:dir] + "/" +
|
||||
f.split(" ")[3].chomp.chomp('"').reverse.chomp('"').reverse
|
||||
def self.remote?(file)
|
||||
file.match(%r{^https?://})
|
||||
end
|
||||
|
||||
def self.vmdk?(file)
|
||||
type = `file #{file}`
|
||||
|
||||
type.include? 'VMware'
|
||||
end
|
||||
|
||||
def self.iso?(file)
|
||||
type = `file #{file}`
|
||||
|
||||
type.include? 'ISO'
|
||||
end
|
||||
|
||||
def self.get_type(file)
|
||||
type = `file -b --mime-type #{file}`
|
||||
if $?.exitstatus != 0 # rubocop:disable Style/SpecialGlobalVars
|
||||
STDERR.puts "Can not read file #{file}"
|
||||
exit(-1)
|
||||
end
|
||||
type.strip
|
||||
end
|
||||
|
||||
def self.needs_unpack?(file_path)
|
||||
type = get_type(file_path)
|
||||
type.gsub!(%r{^application/(x-)?}, '')
|
||||
%w[bzip2 gzip tar].include?(type)
|
||||
end
|
||||
|
||||
def self.vcenter_file_info(file_path)
|
||||
if File.directory?(file_path)
|
||||
files = Dir["#{file_path}/*.vmdk"]
|
||||
found = false
|
||||
count = 0
|
||||
last = nil
|
||||
|
||||
files.each do |f|
|
||||
if get_type(f).strip == 'text/plain'
|
||||
file_path = f
|
||||
found = true
|
||||
break
|
||||
else
|
||||
count += 1
|
||||
last = f
|
||||
end
|
||||
end
|
||||
|
||||
if !found
|
||||
if count == 1
|
||||
file_path = last
|
||||
found = true
|
||||
else
|
||||
STDERR.puts 'Could not find vmdk'
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
info[:flat_files] = files_list
|
||||
case get_type(file_path).strip
|
||||
when 'application/octet-stream'
|
||||
{
|
||||
:type => :standalone,
|
||||
:file => file_path,
|
||||
:dir => File.dirname(file_path)
|
||||
}
|
||||
when 'application/x-iso9660-image'
|
||||
{
|
||||
:type => :standalone,
|
||||
:file => file_path,
|
||||
:dir => File.dirname(file_path),
|
||||
:extension => '.iso'
|
||||
}
|
||||
when 'text/plain'
|
||||
info = {
|
||||
:type => :flat,
|
||||
:file => file_path,
|
||||
:dir => File.dirname(file_path)
|
||||
}
|
||||
|
||||
return info
|
||||
else
|
||||
STDERR.puts "Unrecognized file type"
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
files_list = []
|
||||
descriptor = File.read(file_path).split("\n")
|
||||
flat_files = descriptor.select {|l| l.start_with?('RW') }
|
||||
|
||||
def self.escape_path(path)
|
||||
return path.gsub(" ", "%20")
|
||||
end
|
||||
flat_files.each do |f|
|
||||
files_list <<
|
||||
info[:dir] +
|
||||
'/' +
|
||||
f
|
||||
.split(' ')[3]
|
||||
.chomp
|
||||
.chomp('"')
|
||||
.reverse
|
||||
.chomp('"')
|
||||
.reverse
|
||||
end
|
||||
|
||||
def self.unescape_path(path)
|
||||
return path.gsub("%20", " ")
|
||||
end
|
||||
info[:flat_files] = files_list
|
||||
|
||||
# Recursively downloads vmdk related files and returns filenames
|
||||
def self.get_all_filenames_in_descriptor(descriptor_url, ds)
|
||||
descriptor_filename = File.basename descriptor_url.path
|
||||
# Build array of files to download
|
||||
files_to_download = [descriptor_filename]
|
||||
image_source = descriptor_url.host + descriptor_url.path
|
||||
descriptor_content = ds.get_text_file image_source
|
||||
flat_files = descriptor_content.select{|l| l.start_with?("RW")}
|
||||
flat_files.each do |file|
|
||||
# Get the filename from lines of type
|
||||
# RW 2048000 VMFS "filename-flat.vdmdk"
|
||||
file_to_download = file.split(" ")[3][1..-2]
|
||||
files_to_download << file_to_download
|
||||
image_path = File.dirname(descriptor_url.host+descriptor_url.path)
|
||||
if ds.is_descriptor?(image_path + "/" + file_to_download)
|
||||
files_to_download << download_all_filenames_in_descriptor(image_path + "/" + file_to_download)
|
||||
info
|
||||
else
|
||||
STDERR.puts 'Unrecognized file type'
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
|
||||
return files_to_download
|
||||
end
|
||||
|
||||
|
||||
def self.download_vmdks(files_to_download, url_prefix, temp_folder, ds)
|
||||
# Download files
|
||||
url_prefix = url_prefix + "/"
|
||||
|
||||
VCenterDriver::VIClient.in_silence do
|
||||
files_to_download.each{|file|
|
||||
ds.download_file(url_prefix + file, temp_folder + file)
|
||||
}
|
||||
def self.escape_path(path)
|
||||
path.gsub(' ', '%20')
|
||||
end
|
||||
end
|
||||
|
||||
# Receives a VMDK descriptor or file, downloads all
|
||||
# related files, creates a tar.gz and dumps it in stdout
|
||||
def self.dump_vmdk_tar_gz(vcenter_url, ds)
|
||||
image_source = vcenter_url.host + vcenter_url.path
|
||||
if ds.is_descriptor?(image_source)
|
||||
files_to_download = self.get_all_filenames_in_descriptor(vcenter_url, ds)
|
||||
def self.unescape_path(path)
|
||||
path.gsub('%20', ' ')
|
||||
end
|
||||
|
||||
descriptor_name = File.basename vcenter_url.path
|
||||
temp_folder = VAR_LOCATION + "/vcenter/" + descriptor_name + "/"
|
||||
FileUtils.mkdir_p(temp_folder) if !File.directory?(temp_folder)
|
||||
|
||||
image_path = File.dirname(vcenter_url.host+vcenter_url.path)
|
||||
self.download_vmdks(files_to_download, image_path, temp_folder, ds)
|
||||
# Recursively downloads vmdk related files and returns filenames
|
||||
def self.get_all_filenames_in_descriptor(descriptor_url, ds)
|
||||
descriptor_filename = File.basename descriptor_url.path
|
||||
# Build array of files to download
|
||||
files_to_download = [descriptor_filename]
|
||||
image_source = descriptor_url.host + descriptor_url.path
|
||||
descriptor_content = ds.get_text_file image_source
|
||||
flat_files = descriptor_content.select {|l| l.start_with?('RW') }
|
||||
flat_files.each do |file|
|
||||
# Get the filename from lines of type
|
||||
# RW 2048000 VMFS "filename-flat.vdmdk"
|
||||
file_to_download = file.split(' ')[3][1..-2]
|
||||
files_to_download << file_to_download
|
||||
image_path =
|
||||
File
|
||||
.dirname(
|
||||
descriptor_url.host+descriptor_url.path
|
||||
)
|
||||
next unless ds.descriptor?(image_path + '/' + file_to_download)
|
||||
|
||||
# Create tar.gz
|
||||
rs = system("cd #{temp_folder} && tar czf #{descriptor_name}.tar.gz #{files_to_download.join(' ')} > /dev/null 2>&1")
|
||||
(FileUtils.rm_rf(temp_folder) ; raise "Error creating tar file for #{descriptor_name}") unless rs
|
||||
files_to_download <<
|
||||
download_all_filenames_in_descriptor(
|
||||
image_path + '/' + file_to_download
|
||||
)
|
||||
end
|
||||
|
||||
# Cat file to stdout
|
||||
rs = system("cat #{temp_folder + descriptor_name}.tar.gz")
|
||||
(FileUtils.rm_rf(temp_folder) ; raise "Error reading tar for #{descriptor_name}") unless rs
|
||||
files_to_download
|
||||
end
|
||||
|
||||
def self.download_vmdks(files_to_download, url_prefix, temp_folder, ds)
|
||||
# Download files
|
||||
url_prefix += '/'
|
||||
|
||||
VCenterDriver::VIClient.in_silence do
|
||||
files_to_download.each do |file|
|
||||
ds.download_file(url_prefix + file, temp_folder + file)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Receives a VMDK descriptor or file, downloads all
|
||||
# related files, creates a tar.gz and dumps it in stdout
|
||||
def self.dump_vmdk_tar_gz(vcenter_url, ds)
|
||||
image_source = vcenter_url.host + vcenter_url.path
|
||||
if ds.descriptor?(image_source)
|
||||
files_to_download =
|
||||
get_all_filenames_in_descriptor(
|
||||
vcenter_url,
|
||||
ds
|
||||
)
|
||||
|
||||
# Delete tar.gz
|
||||
rs = system("cd #{temp_folder} && rm #{descriptor_name}.tar.gz #{files_to_download.join(' ')}")
|
||||
(FileUtils.rm_rf(temp_folder) ; raise "Error removing tar for #{descriptor_name}") unless rs
|
||||
else
|
||||
# Setting "." as the source will read from the stdin
|
||||
VCenterDriver::VIClient.in_stderr_silence do
|
||||
descriptor_name = File.basename vcenter_url.path
|
||||
file_to_download = [vcenter_url.path]
|
||||
temp_folder = VAR_LOCATION + "/vcenter/" + descriptor_name + "/"
|
||||
temp_folder = VAR_LOCATION + '/vcenter/' + descriptor_name + '/'
|
||||
unless File.directory?(temp_folder)
|
||||
FileUtils
|
||||
.mkdir_p(
|
||||
temp_folder
|
||||
)
|
||||
end
|
||||
|
||||
FileUtils.mkdir_p(temp_folder + File.dirname(vcenter_url.path) + "/") if !File.directory?(temp_folder + File.dirname(vcenter_url.path) + "/")
|
||||
|
||||
self.download_vmdks(file_to_download, vcenter_url.host, temp_folder, ds)
|
||||
|
||||
temp_folder = temp_folder + File.dirname(vcenter_url.path)
|
||||
image_path = File.dirname(vcenter_url.host+vcenter_url.path)
|
||||
download_vmdks(files_to_download, image_path, temp_folder, ds)
|
||||
|
||||
# Create tar.gz
|
||||
rs = system("cd #{temp_folder} && tar czf #{descriptor_name}.tar.gz #{descriptor_name} > /dev/null 2>&1")
|
||||
(FileUtils.rm_rf(temp_folder) ; raise "Error creating tar file for #{descriptor_name}") unless rs
|
||||
rs = system(
|
||||
"cd #{temp_folder} \&& tar czf #{descriptor_name}.tar.gz \
|
||||
#{files_to_download.join(' ')} > /dev/null 2>&1"
|
||||
)
|
||||
unless rs
|
||||
FileUtils.rm_rf temp_folder
|
||||
raise "Error creating tar file for #{descriptor_name}"
|
||||
end
|
||||
|
||||
# Cat file to stdout
|
||||
rs = system("cat #{temp_folder + "/" + descriptor_name}.tar.gz")
|
||||
(FileUtils.rm_rf(temp_folder) ; raise "Error reading tar for #{descriptor_name}") unless rs
|
||||
rs = system("cat #{temp_folder + descriptor_name}.tar.gz")
|
||||
unless rs
|
||||
FileUtils.rm_rf temp_folder
|
||||
raise "Error reading tar for #{descriptor_name}"
|
||||
end
|
||||
|
||||
# Delete tar.gz
|
||||
rs = system("cd #{temp_folder} && rm #{descriptor_name}.tar.gz #{descriptor_name}")
|
||||
(FileUtils.rm_rf(temp_folder) ; raise "Error removing tar for #{descriptor_name}") unless rs
|
||||
rs = system(
|
||||
"cd #{temp_folder} \
|
||||
&& rm #{descriptor_name}.tar.gz #{
|
||||
files_to_download
|
||||
.join(' ')}"
|
||||
)
|
||||
unless rs
|
||||
FileUtils.rm_rf temp_folder
|
||||
raise "Error removing tar for #{descriptor_name}"
|
||||
end
|
||||
else
|
||||
# Setting "." as the source will read from the stdin
|
||||
VCenterDriver::VIClient.in_stderr_silence do
|
||||
descriptor_name = File.basename vcenter_url.path
|
||||
file_to_download = [vcenter_url.path]
|
||||
temp_folder =
|
||||
VAR_LOCATION + '/vcenter/' + descriptor_name + '/'
|
||||
|
||||
unless File
|
||||
.directory?(
|
||||
temp_folder + File
|
||||
.dirname(
|
||||
vcenter_url
|
||||
.path
|
||||
) + '/'
|
||||
)
|
||||
FileUtils
|
||||
.mkdir_p(temp_folder + File
|
||||
.dirname(
|
||||
vcenter_url
|
||||
.path
|
||||
) + '/')
|
||||
end
|
||||
|
||||
download_vmdks(
|
||||
file_to_download,
|
||||
vcenter_url.host,
|
||||
temp_folder,
|
||||
ds
|
||||
)
|
||||
|
||||
temp_folder += File.dirname(vcenter_url.path)
|
||||
|
||||
# Create tar.gz
|
||||
rs = system(
|
||||
"cd #{temp_folder} && tar czf #{descriptor_name}.tar.gz\
|
||||
#{descriptor_name} > /dev/null 2>&1"
|
||||
)
|
||||
unless rs
|
||||
(
|
||||
FileUtils
|
||||
.rm_rf(
|
||||
temp_folder
|
||||
)
|
||||
raise "Error creating tar \
|
||||
file for #{descriptor_name}")
|
||||
end
|
||||
|
||||
# Cat file to stdout
|
||||
rs = system(
|
||||
"cat #{temp_folder + '/' + descriptor_name}.tar.gz"
|
||||
)
|
||||
unless rs
|
||||
(
|
||||
FileUtils
|
||||
.rm_rf(
|
||||
temp_folder
|
||||
)
|
||||
raise "Error reading tar for #{descriptor_name}")
|
||||
end # rubocop:disable Style/Semicolon
|
||||
|
||||
# Delete tar.gz
|
||||
rs = system(
|
||||
"cd #{temp_folder} \
|
||||
&& rm #{descriptor_name}.tar.gz #{descriptor_name}"
|
||||
)
|
||||
unless rs
|
||||
(
|
||||
FileUtils
|
||||
.rm_rf(
|
||||
temp_folder
|
||||
)
|
||||
raise "Error \ removing tar for #{descriptor_name}")
|
||||
end # rubocop:disable Style/Semicolon
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
# class FileHelper
|
||||
|
||||
end # class FileHelper
|
||||
|
||||
end # module VCenterDriver
|
||||
end
|
||||
# module VCenterDriver
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -14,10 +14,13 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Module Memoize
|
||||
##############################################################################
|
||||
module Memoize
|
||||
|
||||
def [](property)
|
||||
@memoize = {} if !defined?(@memoize)
|
||||
@memoize = {} unless defined?(@memoize)
|
||||
|
||||
if (value = @memoize[property])
|
||||
return value
|
||||
@ -25,13 +28,13 @@ module Memoize
|
||||
|
||||
current_item = @item
|
||||
|
||||
property_path = ""
|
||||
property_path = ''
|
||||
|
||||
property.split(".").each do |elem|
|
||||
property.split('.').each do |elem|
|
||||
if property_path.empty?
|
||||
property_path << elem
|
||||
else
|
||||
property_path << "." << elem
|
||||
property_path << '.' << elem
|
||||
end
|
||||
|
||||
if (val = @memoize[property_path])
|
||||
@ -39,7 +42,7 @@ module Memoize
|
||||
else
|
||||
begin
|
||||
current_item = current_item.send(elem)
|
||||
rescue Exception => e
|
||||
rescue StandardError
|
||||
current_item = nil
|
||||
end
|
||||
end
|
||||
@ -47,14 +50,13 @@ module Memoize
|
||||
break if current_item.nil?
|
||||
|
||||
@memoize[property_path] = current_item
|
||||
|
||||
end
|
||||
|
||||
@memoize[property] = current_item
|
||||
end
|
||||
|
||||
def clear(property)
|
||||
@memoize = {} if !defined?(@memoize)
|
||||
@memoize = {} unless defined?(@memoize)
|
||||
@memoize.clear[property] if @memoize[property]
|
||||
end
|
||||
|
||||
@ -63,8 +65,10 @@ module Memoize
|
||||
end
|
||||
|
||||
def []=(property, value)
|
||||
@memoize = {} if !defined?(@memoize)
|
||||
@memoize = {} unless defined?(@memoize)
|
||||
|
||||
@memoize[property] = value
|
||||
end
|
||||
end # module Memoize
|
||||
|
||||
end
|
||||
# module Memoize
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -14,7 +14,9 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
##############################################################################
|
||||
# Module VCenterDriver
|
||||
##############################################################################
|
||||
module VCenterDriver
|
||||
|
||||
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
|
||||
@ -35,14 +37,16 @@ module VCenterDriver
|
||||
unless defined?(HOOK_LOCATION)
|
||||
end
|
||||
|
||||
# class VCImporter
|
||||
##########################################################################
|
||||
# Class VcImporter
|
||||
##########################################################################
|
||||
class VcImporter
|
||||
|
||||
attr_accessor :list
|
||||
|
||||
#######################################################################
|
||||
######################################################################
|
||||
# Constructors
|
||||
#######################################################################
|
||||
######################################################################
|
||||
#
|
||||
#
|
||||
|
||||
@ -120,7 +124,6 @@ module VCenterDriver
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Importer return value
|
||||
#
|
||||
# @ return [Hash{:sucess =>[[]] , :error => {}}
|
||||
|
@ -16,232 +16,264 @@
|
||||
require 'openssl'
|
||||
require 'yaml'
|
||||
|
||||
##############################################################################
|
||||
# Module VCenterDriver
|
||||
##############################################################################
|
||||
module VCenterDriver
|
||||
|
||||
class VIClient
|
||||
attr_accessor :vim
|
||||
attr_accessor :rp
|
||||
attr_accessor :vc_name
|
||||
attr_accessor :ccr_ref
|
||||
##########################################################################
|
||||
# Class VIClient
|
||||
##########################################################################
|
||||
class VIClient
|
||||
|
||||
def initialize(opts, host_id = -1)
|
||||
opts = {:insecure => true}.merge(opts)
|
||||
@host_id = host_id
|
||||
@vim = RbVmomi::VIM.connect(opts)
|
||||
@vc_name = opts[:host] if opts[:host]
|
||||
attr_accessor :vim
|
||||
attr_accessor :rp
|
||||
attr_accessor :vc_name
|
||||
attr_accessor :ccr_ref
|
||||
|
||||
def initialize(opts, host_id = -1)
|
||||
opts = { :insecure => true }.merge(opts)
|
||||
@host_id = host_id
|
||||
@vim = RbVmomi::VIM.connect(opts)
|
||||
@vc_name = opts[:host] if opts[:host]
|
||||
|
||||
# Get ccr and get rp
|
||||
@ccr_ref = opts.delete(:ccr)
|
||||
|
||||
return unless @ccr_ref
|
||||
|
||||
# Get ccr and get rp
|
||||
@ccr_ref = opts.delete(:ccr)
|
||||
if @ccr_ref
|
||||
ccr = RbVmomi::VIM::ClusterComputeResource.new(@vim, @ccr_ref)
|
||||
|
||||
#Get ref for rp
|
||||
if ccr
|
||||
rp = opts.delete(:rp)
|
||||
if rp
|
||||
rp_list = get_resource_pools(ccr)
|
||||
rp_ref = rp_list.select { |r| r[:name] == rp }.first[:ref] rescue nil
|
||||
@rp = RbVmomi::VIM::ResourcePool(@vim, rp_ref) if rp_ref
|
||||
# Get ref for rp
|
||||
|
||||
return unless ccr
|
||||
|
||||
rp = opts.delete(:rp)
|
||||
|
||||
return unless rp
|
||||
|
||||
rp_list = get_resource_pools(ccr)
|
||||
rp_ref =
|
||||
rp_list
|
||||
.select {|r| r[:name] == rp }.first[:ref] rescue nil
|
||||
@rp = RbVmomi::VIM::ResourcePool(@vim, rp_ref) if rp_ref
|
||||
end
|
||||
|
||||
def rp_confined?
|
||||
!!@rp
|
||||
end
|
||||
|
||||
def host_credentials
|
||||
raise 'no host id defined!' if @host_id == -1
|
||||
|
||||
host =
|
||||
OpenNebula::Host
|
||||
.new_with_id(
|
||||
@host_id,
|
||||
OpenNebula::Client.new
|
||||
)
|
||||
rc = host.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
raise "Could not get host info \
|
||||
for ID: #{host_id} - #{rc.message}"
|
||||
end
|
||||
|
||||
{ :pass => host['TEMPLATE/VCENTER_PASSWORD'],
|
||||
:user => host['TEMPLATE/VCENTER_USER'],
|
||||
:host => @vc_name }
|
||||
end
|
||||
|
||||
def get_resource_pools(ccr, rp = nil, parent_prefix = '', rp_array = [])
|
||||
current_rp = ''
|
||||
|
||||
if !rp
|
||||
rp = ccr.resourcePool
|
||||
else
|
||||
if !parent_prefix.empty?
|
||||
current_rp << parent_prefix
|
||||
current_rp << '/'
|
||||
end
|
||||
current_rp << rp.name
|
||||
end
|
||||
|
||||
if rp.resourcePool.empty?
|
||||
rp_info = {}
|
||||
rp_info[:name] = current_rp
|
||||
rp_info[:ref] = rp._ref
|
||||
rp_array << rp_info
|
||||
else
|
||||
rp.resourcePool.each do |child_rp|
|
||||
get_resource_pools(ccr, child_rp, current_rp, rp_array)
|
||||
end
|
||||
rp_info = {}
|
||||
rp_info[:name] = current_rp
|
||||
rp_info[:ref] = rp._ref
|
||||
rp_array << rp_info unless current_rp.empty?
|
||||
end
|
||||
|
||||
rp_array
|
||||
end
|
||||
|
||||
def close_connection
|
||||
@vim.close
|
||||
end
|
||||
|
||||
# @return RbVmomi::VIM::<type> objects
|
||||
def self.get_entities(folder, type, entities = [])
|
||||
if folder == []
|
||||
return
|
||||
end
|
||||
|
||||
folder.childEntity.each do |child|
|
||||
the_name, _junk = child.to_s.split('(')
|
||||
case the_name
|
||||
when 'Folder'
|
||||
get_entities(child, type, entities)
|
||||
when type
|
||||
entities.push(child)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def rp_confined?
|
||||
!!@rp
|
||||
end
|
||||
|
||||
def get_host_credentials()
|
||||
raise "no host id defined!" if @host_id == -1
|
||||
|
||||
host = OpenNebula::Host.new_with_id(@host_id, OpenNebula::Client.new)
|
||||
rc = host.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
raise "Could not get host info for ID: #{host_id} - #{rc.message}"
|
||||
entities
|
||||
end
|
||||
|
||||
{pass: host["TEMPLATE/VCENTER_PASSWORD"],
|
||||
user: host["TEMPLATE/VCENTER_USER"],
|
||||
host: @vc_name }
|
||||
def self.new_from_host(host_id)
|
||||
begin
|
||||
client = OpenNebula::Client.new
|
||||
host = OpenNebula::Host.new_with_id(host_id, client)
|
||||
rc = host.info(true)
|
||||
if OpenNebula.is_error?(rc)
|
||||
raise "Could not get host info for \
|
||||
ID: #{host_id} - #{rc.message}"
|
||||
end
|
||||
|
||||
end
|
||||
connection = {
|
||||
:host => host['TEMPLATE/VCENTER_HOST'],
|
||||
:user => host['TEMPLATE/VCENTER_USER'],
|
||||
:rp => host['TEMPLATE/VCENTER_RESOURCE_POOL'],
|
||||
:ccr => host['TEMPLATE/VCENTER_CCR_REF'],
|
||||
:password => host['TEMPLATE/VCENTER_PASSWORD']
|
||||
}
|
||||
|
||||
def get_resource_pools(ccr, rp = nil, parent_prefix = "", rp_array = [])
|
||||
vc_port = host['TEMPLATE/VCENTER_PORT']
|
||||
connection[:port] = vc_port unless vc_port.nil?
|
||||
|
||||
current_rp = ""
|
||||
|
||||
if !rp
|
||||
rp = ccr.resourcePool
|
||||
else
|
||||
if !parent_prefix.empty?
|
||||
current_rp << parent_prefix
|
||||
current_rp << "/"
|
||||
end
|
||||
current_rp << rp.name
|
||||
end
|
||||
|
||||
if rp.resourcePool.size == 0
|
||||
rp_info = {}
|
||||
rp_info[:name] = current_rp
|
||||
rp_info[:ref] = rp._ref
|
||||
rp_array << rp_info
|
||||
else
|
||||
rp.resourcePool.each do |child_rp|
|
||||
get_resource_pools(ccr, child_rp, current_rp, rp_array)
|
||||
end
|
||||
rp_info = {}
|
||||
rp_info[:name] = current_rp
|
||||
rp_info[:ref] = rp._ref
|
||||
rp_array << rp_info if !current_rp.empty?
|
||||
end
|
||||
|
||||
rp_array
|
||||
end
|
||||
|
||||
def close_connection
|
||||
@vim.close
|
||||
end
|
||||
|
||||
# @return RbVmomi::VIM::<type> objects
|
||||
def self.get_entities(folder, type, entities=[])
|
||||
if folder == []
|
||||
return nil
|
||||
end
|
||||
|
||||
folder.childEntity.each do |child|
|
||||
the_name, junk = child.to_s.split('(')
|
||||
case the_name
|
||||
when "Folder"
|
||||
get_entities(child, type, entities)
|
||||
when type
|
||||
entities.push(child)
|
||||
new(connection, host_id)
|
||||
rescue StandardError => e
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
return entities
|
||||
end
|
||||
def self.new_from_datastore(datastore_id)
|
||||
begin
|
||||
client = OpenNebula::Client.new
|
||||
datastore =
|
||||
OpenNebula::Datastore
|
||||
.new_with_id(
|
||||
datastore_id,
|
||||
client
|
||||
)
|
||||
rc = datastore.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
raise "Could not get datastore info \
|
||||
for ID: #{datastore_id} - #{rc.message}"
|
||||
end
|
||||
|
||||
def self.new_from_host(host_id)
|
||||
begin
|
||||
client = OpenNebula::Client.new
|
||||
host = OpenNebula::Host.new_with_id(host_id, client)
|
||||
rc = host.info(true)
|
||||
if OpenNebula.is_error?(rc)
|
||||
raise "Could not get host info for ID: #{host_id} - #{rc.message}"
|
||||
vcenter_id = datastore['TEMPLATE/VCENTER_INSTANCE_ID']
|
||||
|
||||
host_pool = OpenNebula::HostPool.new(client)
|
||||
rc = host_pool.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
raise "Could not get hosts information - #{rc.message}"
|
||||
end
|
||||
|
||||
user = ''
|
||||
password = ''
|
||||
port = 0
|
||||
host_pool.each do |host|
|
||||
vc_instance_id = host['TEMPLATE/VCENTER_INSTANCE_ID']
|
||||
next unless vc_instance_id == vcenter_id
|
||||
|
||||
host_decrypted =
|
||||
OpenNebula::Host
|
||||
.new_with_id(
|
||||
host['ID'],
|
||||
client
|
||||
)
|
||||
host_decrypted.info(true)
|
||||
user = host_decrypted['TEMPLATE/VCENTER_USER']
|
||||
password = host_decrypted['TEMPLATE/VCENTER_PASSWORD']
|
||||
port = host_decrypted['TEMPLATE/VCENTER_PORT']
|
||||
end
|
||||
if password.empty? || user.empty?
|
||||
raise "Error getting \
|
||||
credentials for datastore #{datastore_id}"
|
||||
end
|
||||
|
||||
connection = {
|
||||
:host => datastore['TEMPLATE/VCENTER_HOST'],
|
||||
:user => user,
|
||||
:password => password
|
||||
}
|
||||
|
||||
connection[:port] = port unless port.nil?
|
||||
|
||||
new(connection)
|
||||
rescue StandardError => e
|
||||
raise e
|
||||
end
|
||||
|
||||
connection = {
|
||||
:host => host["TEMPLATE/VCENTER_HOST"],
|
||||
:user => host["TEMPLATE/VCENTER_USER"],
|
||||
:rp => host["TEMPLATE/VCENTER_RESOURCE_POOL"],
|
||||
:ccr => host["TEMPLATE/VCENTER_CCR_REF"],
|
||||
:password => host["TEMPLATE/VCENTER_PASSWORD"]
|
||||
}
|
||||
|
||||
connection[:port] = host["TEMPLATE/VCENTER_PORT"] unless host["TEMPLATE/VCENTER_PORT"].nil?
|
||||
|
||||
self.new(connection, host_id)
|
||||
|
||||
rescue Exception => e
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
def self.new_from_datastore(datastore_id)
|
||||
begin
|
||||
client = OpenNebula::Client.new
|
||||
datastore = OpenNebula::Datastore.new_with_id(datastore_id, client)
|
||||
rc = datastore.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
raise "Could not get datastore info for ID: #{datastore_id} - #{rc.message}"
|
||||
def self.decrypt(msg, token)
|
||||
begin
|
||||
cipher = OpenSSL::Cipher.new('aes-256-cbc')
|
||||
|
||||
cipher.decrypt
|
||||
|
||||
# Truncate for Ruby 2.4 (in previous versions this was being
|
||||
# automatically truncated)
|
||||
cipher.key = token[0..31]
|
||||
|
||||
msg = cipher.update(Base64.decode64(msg))
|
||||
msg << cipher.final
|
||||
rescue StandardError
|
||||
raise 'Error decrypting secret.'
|
||||
end
|
||||
vcenter_id = datastore["TEMPLATE/VCENTER_INSTANCE_ID"]
|
||||
end
|
||||
|
||||
host_pool = OpenNebula::HostPool.new(client)
|
||||
rc = host_pool.info
|
||||
if OpenNebula.is_error?(rc)
|
||||
raise "Could not get hosts information - #{rc.message}"
|
||||
def self.in_silence
|
||||
begin
|
||||
orig_stderr = $stderr.clone
|
||||
orig_stdout = $stdout.clone
|
||||
$stderr.reopen File.new('/dev/null', 'w')
|
||||
$stdout.reopen File.new('/dev/null', 'w')
|
||||
retval = yield
|
||||
rescue StandardError => e
|
||||
$stdout.reopen orig_stdout
|
||||
$stderr.reopen orig_stderr
|
||||
raise e
|
||||
ensure
|
||||
$stdout.reopen orig_stdout
|
||||
$stderr.reopen orig_stderr
|
||||
end
|
||||
retval
|
||||
end
|
||||
|
||||
user = ""
|
||||
password = ""
|
||||
port = 0
|
||||
host_pool.each do |host|
|
||||
if host["TEMPLATE/VCENTER_INSTANCE_ID"] == vcenter_id
|
||||
host_decrypted = OpenNebula::Host.new_with_id(host["ID"], client)
|
||||
host_decrypted.info(true)
|
||||
user = host_decrypted["TEMPLATE/VCENTER_USER"]
|
||||
password = host_decrypted["TEMPLATE/VCENTER_PASSWORD"]
|
||||
port = host_decrypted["TEMPLATE/VCENTER_PORT"]
|
||||
end
|
||||
def self.in_stderr_silence
|
||||
begin
|
||||
orig_stderr = $stderr.clone
|
||||
$stderr.reopen File.new('/dev/null', 'w')
|
||||
retval = yield
|
||||
rescue StandardError => e
|
||||
$stderr.reopen orig_stderr
|
||||
raise e
|
||||
ensure
|
||||
$stderr.reopen orig_stderr
|
||||
end
|
||||
if password.empty? or user.empty?
|
||||
raise "Error getting credentials for datastore #{datastore_id}"
|
||||
end
|
||||
|
||||
connection = {
|
||||
:host => datastore["TEMPLATE/VCENTER_HOST"],
|
||||
:user => user,
|
||||
:password => password
|
||||
}
|
||||
|
||||
connection[:port] = port unless port.nil?
|
||||
|
||||
self.new(connection)
|
||||
|
||||
rescue Exception => e
|
||||
raise e
|
||||
retval
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def self.decrypt(msg, token)
|
||||
begin
|
||||
cipher = OpenSSL::Cipher.new("aes-256-cbc")
|
||||
|
||||
cipher.decrypt
|
||||
|
||||
# Truncate for Ruby 2.4 (in previous versions this was being
|
||||
# automatically truncated)
|
||||
cipher.key = token[0..31]
|
||||
|
||||
msg = cipher.update(Base64::decode64(msg))
|
||||
msg << cipher.final
|
||||
rescue
|
||||
raise "Error decrypting secret."
|
||||
end
|
||||
end
|
||||
|
||||
def self.in_silence
|
||||
begin
|
||||
orig_stderr = $stderr.clone
|
||||
orig_stdout = $stdout.clone
|
||||
$stderr.reopen File.new('/dev/null', 'w')
|
||||
$stdout.reopen File.new('/dev/null', 'w')
|
||||
retval = yield
|
||||
rescue Exception => e
|
||||
$stdout.reopen orig_stdout
|
||||
$stderr.reopen orig_stderr
|
||||
raise e
|
||||
ensure
|
||||
$stdout.reopen orig_stdout
|
||||
$stderr.reopen orig_stderr
|
||||
end
|
||||
retval
|
||||
end
|
||||
|
||||
def self.in_stderr_silence
|
||||
begin
|
||||
orig_stderr = $stderr.clone
|
||||
$stderr.reopen File.new('/dev/null', 'w')
|
||||
retval = yield
|
||||
rescue Exception => e
|
||||
$stderr.reopen orig_stderr
|
||||
raise e
|
||||
ensure
|
||||
$stderr.reopen orig_stderr
|
||||
end
|
||||
retval
|
||||
end
|
||||
end
|
||||
|
||||
end # module VCenterDriver
|
||||
# module VCenterDriver
|
||||
|
@ -14,258 +14,279 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
########################################################################
|
||||
# Module VCenterDriver
|
||||
########################################################################
|
||||
module VCenterDriver
|
||||
|
||||
class VIHelper
|
||||
########################################################################
|
||||
# Class VIHelper
|
||||
########################################################################
|
||||
class VIHelper
|
||||
|
||||
ETC_LOCATION = "/etc/one/" if !defined?(ETC_LOCATION)
|
||||
VCENTER_DRIVER_DEFAULT = "#{ETC_LOCATION}/vcenter_driver.default"
|
||||
VM_PREFIX_DEFAULT = "one-$i-"
|
||||
ETC_LOCATION = '/etc/one/' unless defined?(ETC_LOCATION)
|
||||
VCENTER_DRIVER_DEFAULT = "#{ETC_LOCATION}/vcenter_driver.default"
|
||||
VM_PREFIX_DEFAULT = 'one-$i-'
|
||||
|
||||
def self.client
|
||||
@@client ||= OpenNebula::Client.new
|
||||
end
|
||||
|
||||
def self.return_if_error(rc, item, exit_if_fail)
|
||||
if OpenNebula::is_error?(rc)
|
||||
raise rc.message if !exit_if_fail
|
||||
|
||||
STDERR.puts rc.message
|
||||
exit 1
|
||||
else
|
||||
item
|
||||
def self.client
|
||||
@@client ||= OpenNebula::Client.new # rubocop:disable Style/ClassVars
|
||||
end
|
||||
end
|
||||
|
||||
require 'scripts_common'
|
||||
def self.check_error(rc, message, _exit=false)
|
||||
if OpenNebula::is_error?(rc)
|
||||
OpenNebula::error_message("\n Error #{message}: #{rc.message}\n")
|
||||
exit 1 if (_exit)
|
||||
def self.return_if_error(rc, item, exit_if_fail)
|
||||
if OpenNebula.is_error?(rc)
|
||||
raise rc.message unless exit_if_fail
|
||||
|
||||
STDERR.puts rc.message
|
||||
exit 1
|
||||
else
|
||||
item
|
||||
end
|
||||
end
|
||||
|
||||
require 'scripts_common'
|
||||
def self.check_error(rc, message, exit_condition = false)
|
||||
return unless OpenNebula.is_error?(rc)
|
||||
|
||||
OpenNebula.error_message("\n Error #{message}: #{rc.message}\n")
|
||||
exit 1 if exit_condition
|
||||
|
||||
raise rc.message
|
||||
end
|
||||
end
|
||||
|
||||
def self.get_cluster_id(clusters)
|
||||
clusters.each do |id|
|
||||
return id unless id == -1
|
||||
def self.get_cluster_id(clusters)
|
||||
clusters.each do |id|
|
||||
return id unless id == -1
|
||||
end
|
||||
-1
|
||||
end
|
||||
return -1
|
||||
end
|
||||
|
||||
def self.one_managed?(object)
|
||||
if object.class.ancestors.include?(OpenNebula::XMLElement)
|
||||
managed = object["TEMPLATE/OPENNEBULA_MANAGED"] || object["USER_TEMPLATE/OPENNEBULA_MANAGED"]
|
||||
return managed != "NO"
|
||||
def self.one_managed?(object)
|
||||
if object.class.ancestors.include?(OpenNebula::XMLElement)
|
||||
managed =
|
||||
object['TEMPLATE/OPENNEBULA_MANAGED'] ||
|
||||
object['USER_TEMPLATE/OPENNEBULA_MANAGED']
|
||||
return managed != 'NO'
|
||||
end
|
||||
false
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def self.check_opts(opts, att_list)
|
||||
att_list.each do |att|
|
||||
raise "#{att} option is mandatory" if opts[att].nil?
|
||||
def self.check_opts(opts, att_list)
|
||||
att_list.each do |att|
|
||||
raise "#{att} option is mandatory" if opts[att].nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.one_item(the_class, id, exit_if_fail = true)
|
||||
item = the_class.new_with_id(id, client)
|
||||
rc = item.info
|
||||
return_if_error(rc, item, exit_if_fail)
|
||||
end
|
||||
|
||||
def self.new_one_item(the_class)
|
||||
item = the_class.new(the_class.build_xml, client)
|
||||
return item
|
||||
end
|
||||
|
||||
def self.one_pool(the_class, exit_if_fail = true)
|
||||
item = the_class.new(client)
|
||||
|
||||
rc = nil
|
||||
begin
|
||||
rc = item.info_all
|
||||
rescue
|
||||
def self.one_item(the_class, id, exit_if_fail = true)
|
||||
item = the_class.new_with_id(id, client)
|
||||
rc = item.info
|
||||
return_if_error(rc, item, exit_if_fail)
|
||||
end
|
||||
|
||||
return_if_error(rc, item, exit_if_fail)
|
||||
end
|
||||
def self.new_one_item(the_class)
|
||||
the_class.new(the_class.build_xml, client)
|
||||
end
|
||||
|
||||
def self.one_pool(the_class, exit_if_fail = true)
|
||||
item = the_class.new(client)
|
||||
|
||||
rc = nil
|
||||
begin
|
||||
rc = item.info_all
|
||||
rescue StandardError
|
||||
rc = item.info
|
||||
end
|
||||
|
||||
return_if_error(rc, item, exit_if_fail)
|
||||
end
|
||||
|
||||
def self.find_by_name(the_class, name, pool = nil, raise_if_fail = true)
|
||||
pool = one_pool(the_class, raise_if_fail) if pool.nil?
|
||||
element = pool.find {|e| e['NAME'] == name.to_s }
|
||||
if element.nil? && raise_if_fail
|
||||
raise "Could not find element '#{name}' in pool '#{the_class}'"
|
||||
end
|
||||
|
||||
def self.find_by_name(the_class, name, pool = nil, raise_if_fail = true)
|
||||
pool = one_pool(the_class, raise_if_fail) if pool.nil?
|
||||
element = pool.find{|e| e['NAME'] == "#{name}" }
|
||||
if element.nil? && raise_if_fail
|
||||
raise "Could not find element '#{name}' in pool '#{the_class}'"
|
||||
else
|
||||
element
|
||||
end
|
||||
end
|
||||
|
||||
def self.generate_name(opts, nbytes)
|
||||
def self.generate_name(opts, nbytes)
|
||||
return opts[:name] if nbytes <= 0
|
||||
|
||||
return opts[:name] if nbytes <= 0
|
||||
@sha256 ||= Digest::SHA256.new
|
||||
chain = opts[:key]
|
||||
hash = @sha256.hexdigest(chain)[0..nbytes-1]
|
||||
|
||||
@sha256 ||= Digest::SHA256.new
|
||||
chain = opts[:key]
|
||||
hash = @sha256.hexdigest(chain)[0..nbytes-1]
|
||||
|
||||
return "#{opts[:name]}-#{hash}"
|
||||
end
|
||||
|
||||
def self.one_name(the_class, name, key, pool = nil, bytes = 0)
|
||||
|
||||
# Remove \u007F character that comes from vcenter
|
||||
name = name.tr("\u007F", "")
|
||||
pool = one_pool(the_class) if pool.nil?
|
||||
|
||||
import_name = generate_name({name: name, key: key}, bytes)
|
||||
|
||||
begin
|
||||
find_by_name(the_class, import_name, pool)
|
||||
rescue RuntimeError => e
|
||||
return import_name
|
||||
"#{opts[:name]}-#{hash}"
|
||||
end
|
||||
|
||||
one_name(the_class, name, key, pool, bytes+2)
|
||||
end
|
||||
def self.one_name(the_class, name, key, pool = nil, bytes = 0)
|
||||
# Remove \u007F character that comes from vcenter
|
||||
name = name.tr("\u007F", '')
|
||||
pool = one_pool(the_class) if pool.nil?
|
||||
|
||||
def self.get_ref_key(element, attribute, vcenter_uuid = nil)
|
||||
key = element[attribute]
|
||||
import_name = generate_name({ :name => name, :key => key }, bytes)
|
||||
|
||||
return nil if key.nil?
|
||||
begin
|
||||
find_by_name(the_class, import_name, pool)
|
||||
rescue StandardError
|
||||
return import_name
|
||||
end
|
||||
|
||||
tvid = element["TEMPLATE/VCENTER_INSTANCE_ID"]
|
||||
uvid = element["USER_TEMPLATE/VCENTER_INSTANCE_ID"]
|
||||
|
||||
if tvid
|
||||
key += tvid
|
||||
elsif uvid
|
||||
key += uvid
|
||||
elsif vcenter_uuid
|
||||
key += vcenter_uuid
|
||||
one_name(the_class, name, key, pool, bytes+2)
|
||||
end
|
||||
|
||||
return key
|
||||
end
|
||||
def self.get_ref_key(element, attribute, vcenter_uuid = nil)
|
||||
key = element[attribute]
|
||||
|
||||
def self.create_ref_hash(attribute, pool, vcenter_uuid = nil)
|
||||
hash = {}
|
||||
return if key.nil?
|
||||
|
||||
pool.each_element(Proc.new do |e|
|
||||
refkey = get_ref_key(e, attribute, vcenter_uuid)
|
||||
hash[refkey] = e
|
||||
end)
|
||||
tvid = element['TEMPLATE/VCENTER_INSTANCE_ID']
|
||||
uvid = element['USER_TEMPLATE/VCENTER_INSTANCE_ID']
|
||||
|
||||
hash
|
||||
end
|
||||
if tvid
|
||||
key += tvid
|
||||
elsif uvid
|
||||
key += uvid
|
||||
elsif vcenter_uuid
|
||||
key += vcenter_uuid
|
||||
end
|
||||
|
||||
def self.clean_ref_hash
|
||||
@ref_hash = {}
|
||||
end
|
||||
key
|
||||
end
|
||||
|
||||
def self.add_ref_hash(attr, one_object)
|
||||
raise "cache is empty!" unless @ref_hash
|
||||
def self.create_ref_hash(attribute, pool, vcenter_uuid = nil)
|
||||
hash = {}
|
||||
|
||||
refkey = get_ref_key(one_object, attr)
|
||||
pool.each_element(proc do |e|
|
||||
refkey = get_ref_key(e, attribute, vcenter_uuid)
|
||||
hash[refkey] = e
|
||||
end)
|
||||
|
||||
hash
|
||||
end
|
||||
|
||||
def self.clean_ref_hash
|
||||
@ref_hash = {}
|
||||
end
|
||||
|
||||
def self.add_ref_hash(attr, one_object)
|
||||
raise 'cache is empty!' unless @ref_hash
|
||||
|
||||
refkey = get_ref_key(one_object, attr)
|
||||
|
||||
return unless @ref_hash[attr]
|
||||
|
||||
if @ref_hash[attr]
|
||||
@ref_hash[attr][refkey] = one_object
|
||||
end
|
||||
end
|
||||
|
||||
def self.remove_ref_hash(attr, one_object)
|
||||
raise "cache is empty!" unless @ref_hash
|
||||
def self.remove_ref_hash(attr, one_object)
|
||||
raise 'cache is empty!' unless @ref_hash
|
||||
|
||||
refkey = get_ref_key(one_object, attr)
|
||||
refkey = get_ref_key(one_object, attr)
|
||||
|
||||
return unless @ref_hash[attr]
|
||||
|
||||
if @ref_hash[attr]
|
||||
@ref_hash[attr].delete(refkey)
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_by_ref(the_class, attribute, ref, vcenter_uuid, pool = nil)
|
||||
pool = one_pool(the_class, false) if pool.nil?
|
||||
@ref_hash ||= {}
|
||||
def self.find_by_ref(
|
||||
the_class,
|
||||
attribute,
|
||||
ref,
|
||||
vcenter_uuid,
|
||||
pool = nil
|
||||
)
|
||||
pool = one_pool(the_class, false) if pool.nil?
|
||||
@ref_hash ||= {}
|
||||
|
||||
if @ref_hash[attribute].nil? || @ref_hash[attribute] == {}
|
||||
@ref_hash[attribute] = create_ref_hash(attribute,
|
||||
pool,
|
||||
vcenter_uuid)
|
||||
end
|
||||
|
||||
refkey = ""
|
||||
refkey = ref if ref
|
||||
refkey += vcenter_uuid if vcenter_uuid
|
||||
|
||||
return @ref_hash[attribute][refkey]
|
||||
end
|
||||
|
||||
def self.find_image_by(att, the_class, path, ds_id, pool = nil)
|
||||
pool = one_pool(the_class, false) if pool.nil?
|
||||
element = pool.find{|e|
|
||||
e[att] == path &&
|
||||
e["DATASTORE_ID"] == ds_id}
|
||||
return element
|
||||
end
|
||||
|
||||
def self.find_persistent_image_by_source(source, pool)
|
||||
element = pool.find{|e|
|
||||
e["SOURCE"] == source &&
|
||||
e["PERSISTENT"] == "1"
|
||||
}
|
||||
|
||||
return element
|
||||
end
|
||||
|
||||
def self.find_vcenter_vm_by_name(one_vm, host, vi_client)
|
||||
# Let's try to find the VM object only by its name
|
||||
# Let's build the VM name
|
||||
vm_prefix = host['TEMPLATE/VM_PREFIX']
|
||||
vm_prefix = VM_PREFIX_DEFAULT if vm_prefix.nil? || vm_prefix.empty?
|
||||
vm_prefix.gsub!("$i", one_vm['ID'])
|
||||
vm_name = vm_prefix + one_vm['NAME']
|
||||
|
||||
# We have no DEPLOY_ID, the VM has never been deployed
|
||||
# let's use a view to try to find the VM from the root folder
|
||||
view = vi_client.vim.serviceContent.viewManager.CreateContainerView({
|
||||
container: vi_client.vim.rootFolder,
|
||||
type: ['VirtualMachine'],
|
||||
recursive: true
|
||||
})
|
||||
|
||||
vcenter_vm = view.view.find{ |v| v.name == vm_name } if !!view.view && !view.view.empty?
|
||||
|
||||
view.DestroyView # Destroy the view
|
||||
|
||||
return vcenter_vm
|
||||
end
|
||||
|
||||
def self.get_default(xpath)
|
||||
begin
|
||||
xml = OpenNebula::XMLElement.new
|
||||
xml.initialize_xml(File.read(VCENTER_DRIVER_DEFAULT), 'VCENTER')
|
||||
return xml[xpath]
|
||||
rescue
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def self.get_location(item)
|
||||
folders = []
|
||||
while !item.instance_of? RbVmomi::VIM::Datacenter
|
||||
item = item.parent
|
||||
if !item.instance_of? RbVmomi::VIM::Datacenter
|
||||
folders << item.name if item.name != "host"
|
||||
if @ref_hash[attribute].nil? || @ref_hash[attribute] == {}
|
||||
@ref_hash[attribute] = create_ref_hash(attribute,
|
||||
pool,
|
||||
vcenter_uuid)
|
||||
end
|
||||
raise "Could not find the location" if item.nil?
|
||||
|
||||
refkey = ''
|
||||
refkey = ref if ref
|
||||
refkey += vcenter_uuid if vcenter_uuid
|
||||
|
||||
@ref_hash[attribute][refkey]
|
||||
end
|
||||
|
||||
def self.find_image_by(att, the_class, path, ds_id, pool = nil)
|
||||
pool = one_pool(the_class, false) if pool.nil?
|
||||
pool.find do |e|
|
||||
e[att] == path &&
|
||||
e['DATASTORE_ID'] == ds_id
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_persistent_image_by_source(source, pool)
|
||||
pool.find do |e|
|
||||
e['SOURCE'] == source &&
|
||||
e['PERSISTENT'] == '1'
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_vcenter_vm_by_name(one_vm, host, vi_client)
|
||||
# Let's try to find the VM object only by its name
|
||||
# Let's build the VM name
|
||||
vm_prefix = host['TEMPLATE/VM_PREFIX']
|
||||
vm_prefix = VM_PREFIX_DEFAULT if vm_prefix.nil? || vm_prefix.empty?
|
||||
vm_prefix.gsub!('$i', one_vm['ID'])
|
||||
vm_name = vm_prefix + one_vm['NAME']
|
||||
|
||||
# We have no DEPLOY_ID, the VM has never been deployed
|
||||
# let's use a view to try to find the VM from the root folder
|
||||
view = vi_client
|
||||
.vim
|
||||
.serviceContent
|
||||
.viewManager
|
||||
.CreateContainerView(
|
||||
{
|
||||
:container => vi_client.vim.rootFolder,
|
||||
:type => ['VirtualMachine'],
|
||||
:recursive => true
|
||||
}
|
||||
)
|
||||
|
||||
if !view.view.nil? && !view.view.empty?
|
||||
vcenter_vm = view
|
||||
.view
|
||||
.find {|v| v.name == vm_name }
|
||||
end
|
||||
|
||||
view.DestroyView # Destroy the view
|
||||
|
||||
vcenter_vm
|
||||
end
|
||||
|
||||
def self.get_default(xpath)
|
||||
begin
|
||||
xml = OpenNebula::XMLElement.new
|
||||
xml.initialize_xml(File.read(VCENTER_DRIVER_DEFAULT), 'VCENTER')
|
||||
xml[xpath]
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def self.get_location(item)
|
||||
folders = []
|
||||
until item.instance_of? RbVmomi::VIM::Datacenter
|
||||
item = item.parent
|
||||
if !item.instance_of? RbVmomi::VIM::Datacenter
|
||||
folders << item.name if item.name != 'host'
|
||||
end
|
||||
raise 'Could not find the location' if item.nil?
|
||||
end
|
||||
location = folders.reverse.join('/')
|
||||
location = '/' if location.empty?
|
||||
|
||||
location
|
||||
end
|
||||
location = folders.reverse.join("/")
|
||||
location = "/" if location.empty?
|
||||
|
||||
return location
|
||||
end
|
||||
# class VIHelper
|
||||
|
||||
end # class VIHelper
|
||||
|
||||
end # module VCenterDriver
|
||||
end
|
||||
# module VCenterDriver
|
||||
|
@ -198,7 +198,7 @@ module VCenterDriver
|
||||
############################################################################
|
||||
|
||||
# @return Boolean whether the VM exists in vCenter
|
||||
def is_new?
|
||||
def new?
|
||||
one_item["DEPLOY_ID"].empty?
|
||||
end
|
||||
|
||||
@ -237,7 +237,7 @@ module VCenterDriver
|
||||
@vi_client.vim.serviceContent.about.instanceUuid
|
||||
end
|
||||
|
||||
def get_disk_keys
|
||||
def disk_keys_get
|
||||
unmanaged_keys = {}
|
||||
@item.config.extraConfig.each do |val|
|
||||
u = val[:key].include?("opennebula.disk")
|
||||
@ -672,7 +672,7 @@ module VCenterDriver
|
||||
end
|
||||
|
||||
# Queries to OpenNebula the machine nics xml representation
|
||||
def get_one_nics
|
||||
def one_nics_get
|
||||
one_item.info if one_item.instance_of?(OpenNebula::VirtualMachine)
|
||||
one_item.retrieve_xmlelements("TEMPLATE/NIC")
|
||||
end
|
||||
@ -682,7 +682,7 @@ module VCenterDriver
|
||||
# @param one_disk [XMLelement] The OpenNebula object representation of the disk
|
||||
# @param keys [Hash (String => String)] Hashmap with the unmanaged keys
|
||||
# @param vc_disks [Array (vcenter_disks)] Array of the machine real disks
|
||||
# see get_vcenter_disks method
|
||||
# see vcenter_disks_get method
|
||||
#
|
||||
# @return [vCenter_disk] the proper disk
|
||||
def query_disk(one_disk, keys, vc_disks)
|
||||
@ -738,8 +738,8 @@ module VCenterDriver
|
||||
def info_nics
|
||||
@nics = {macs: {}}
|
||||
|
||||
vc_nics = get_vcenter_nics
|
||||
one_nics = get_one_nics
|
||||
vc_nics = vcenter_nics_get
|
||||
one_nics = one_nics_get
|
||||
|
||||
one_nics.each do |one_nic|
|
||||
index = one_nic["NIC_ID"]
|
||||
@ -785,8 +785,8 @@ module VCenterDriver
|
||||
def info_disks
|
||||
@disks = {}
|
||||
|
||||
keys = get_disk_keys
|
||||
vc_disks = get_vcenter_disks
|
||||
keys = disk_keys_get
|
||||
vc_disks = vcenter_disks_get
|
||||
one_disks = get_one_disks
|
||||
|
||||
one_disks.each do |one_disk|
|
||||
@ -834,7 +834,7 @@ module VCenterDriver
|
||||
|
||||
raise "nic #{index} not found" unless one_nic
|
||||
|
||||
vc_nics = get_vcenter_nics
|
||||
vc_nics = vcenter_nics_get
|
||||
vc_nic = query_nic(mac, vc_nics)
|
||||
|
||||
if vc_nic
|
||||
@ -858,8 +858,8 @@ module VCenterDriver
|
||||
|
||||
raise "disk #{index} not found" unless one_disk
|
||||
|
||||
keys = opts[:keys].nil? ? get_disk_keys : opts[:keys]
|
||||
vc_disks = opts[:disks].nil? ? get_vcenter_disks : opts[:disks]
|
||||
keys = opts[:keys].nil? ? disk_keys_get : opts[:keys]
|
||||
vc_disks = opts[:disks].nil? ? vcenter_disks_get : opts[:disks]
|
||||
vc_disk = query_disk(one_disk, keys, vc_disks)
|
||||
|
||||
if vc_disk
|
||||
@ -892,7 +892,7 @@ module VCenterDriver
|
||||
# for unmanaged nics
|
||||
begin
|
||||
if !unmanaged_nics.empty?
|
||||
nics = get_vcenter_nics
|
||||
nics = vcenter_nics_get
|
||||
|
||||
select_net =->(ref){
|
||||
device = nil
|
||||
@ -1042,16 +1042,16 @@ module VCenterDriver
|
||||
key_prefix = managed ? "opennebula.mdisk" : "opennebula.disk"
|
||||
|
||||
# Get vcenter VM disks to know real path of cloned disk
|
||||
vcenter_disks = get_vcenter_disks
|
||||
vcenter_disks = vcenter_disks_get
|
||||
|
||||
# Create an array with the paths of the disks in vcenter template
|
||||
if !template_ref.nil?
|
||||
template = VCenterDriver::Template.new_from_ref(template_ref, vi_client)
|
||||
template_disks = template.get_vcenter_disks
|
||||
template_disks = template.vcenter_disks_get
|
||||
else
|
||||
# If we are dealing with a Wild VM, we simply use
|
||||
# what is available in the vCenter VM
|
||||
template_disks = get_vcenter_disks
|
||||
template_disks = vcenter_disks_get
|
||||
end
|
||||
template_disks_vector = []
|
||||
template_disks.each do |d|
|
||||
@ -1386,7 +1386,7 @@ module VCenterDriver
|
||||
# start in one, we want the next avaliable id
|
||||
card_num = 1
|
||||
@item["config.hardware.device"].each do |dv|
|
||||
card_num += 1 if is_nic?(dv)
|
||||
card_num += 1 if VCenterDriver::Network.nic?(dv)
|
||||
end
|
||||
|
||||
nic_card = Nic.nic_model_class(model)
|
||||
@ -1413,7 +1413,7 @@ module VCenterDriver
|
||||
|
||||
# grab the last unitNumber to ensure the nic to be added at the end
|
||||
if !unumber
|
||||
@unic = @unic || get_vcenter_nics.map{|d| d.unitNumber}.max || 0
|
||||
@unic = @unic || vcenter_nics_get.map{|d| d.unitNumber}.max || 0
|
||||
unumber = @unic += 1
|
||||
else
|
||||
@unic = unumber
|
||||
@ -1487,7 +1487,7 @@ module VCenterDriver
|
||||
card_num = 1 # start in one, we want the next available id
|
||||
|
||||
@item["config.hardware.device"].each do |dv|
|
||||
card_num += 1 if is_nic?(dv)
|
||||
card_num += 1 if VCenterDriver::Network.nic?(dv)
|
||||
end
|
||||
|
||||
nic_card = Nic.nic_model_class(model)
|
||||
@ -1644,7 +1644,7 @@ module VCenterDriver
|
||||
def detach_disks_specs()
|
||||
detach_disk_array = []
|
||||
extra_config = []
|
||||
keys = get_disk_keys.invert
|
||||
keys = disk_keys_get.invert
|
||||
ipool = VCenterDriver::VIHelper.one_pool(OpenNebula::ImagePool)
|
||||
disks_each(:detached?) do |d|
|
||||
key = d.key.to_s
|
||||
@ -1675,7 +1675,7 @@ module VCenterDriver
|
||||
extraconfig_new = []
|
||||
# vCenter mob disks
|
||||
vc_disks = @item["config.hardware.device"].select do |vc_device|
|
||||
is_disk?(vc_device)
|
||||
disk?(vc_device)
|
||||
end
|
||||
return unless vc_disks
|
||||
# For each changed disk, compare with vcenter mob disk
|
||||
@ -1740,8 +1740,8 @@ module VCenterDriver
|
||||
device_change = []
|
||||
|
||||
# Extract unmanaged_keys
|
||||
unmanaged_keys = get_disk_keys
|
||||
vc_disks = get_vcenter_disks
|
||||
unmanaged_keys = disk_keys_get
|
||||
vc_disks = vcenter_disks_get
|
||||
|
||||
# Check if we're dealing with a StoragePod SYSTEM ds
|
||||
storpod = disk["VCENTER_DS_REF"].start_with?('group-')
|
||||
@ -1832,7 +1832,7 @@ module VCenterDriver
|
||||
end
|
||||
|
||||
vm.config.hardware.device.each do |disk|
|
||||
if is_disk_or_cdrom?(disk)
|
||||
if disk_or_cdrom?(disk)
|
||||
# Let's try to find if disks is persistent
|
||||
source_unescaped = disk.backing.fileName.sub(/^\[(.*?)\] /, "") rescue next
|
||||
source = VCenterDriver::FileHelper.escape_path(source_unescaped)
|
||||
@ -1922,10 +1922,10 @@ module VCenterDriver
|
||||
@used_keys = [] unless @used_keys
|
||||
|
||||
if type == "CDROM"
|
||||
bound = "is_cdrom?"
|
||||
bound = "cdrom?"
|
||||
key = 3000
|
||||
else
|
||||
bound = "is_disk?"
|
||||
bound = "disk?"
|
||||
key = 2000
|
||||
end
|
||||
|
||||
@ -2395,7 +2395,7 @@ module VCenterDriver
|
||||
############################################################################
|
||||
|
||||
def shutdown
|
||||
if !is_powered_off?
|
||||
if !powered_off?
|
||||
begin
|
||||
if vm_tools?
|
||||
@item.ShutdownGuest
|
||||
@ -2407,7 +2407,7 @@ module VCenterDriver
|
||||
raise e.message if error != 'InvalidPowerState'
|
||||
end
|
||||
timeout = CONFIG[:vm_poweron_wait_default]
|
||||
wait_timeout(:is_powered_off?, timeout)
|
||||
wait_timeout(:powered_off?, timeout)
|
||||
end
|
||||
end
|
||||
|
||||
@ -2442,14 +2442,14 @@ module VCenterDriver
|
||||
set_running(true, true) if set_running
|
||||
|
||||
timeout = CONFIG[:vm_poweron_wait_default]
|
||||
wait_timeout(:is_powered_on?, timeout)
|
||||
wait_timeout(:powered_on?, timeout)
|
||||
end
|
||||
|
||||
def is_powered_on?
|
||||
def powered_on?
|
||||
return @item.runtime.powerState == "poweredOn"
|
||||
end
|
||||
|
||||
def is_powered_off?
|
||||
def powered_off?
|
||||
return @item.runtime.powerState == "poweredOff"
|
||||
end
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -92,7 +92,7 @@ begin
|
||||
end
|
||||
end
|
||||
|
||||
if vm.is_powered_off?
|
||||
if vm.powered_off?
|
||||
vm.sync(deploy)
|
||||
# Only mark the VM as running if we are deploying it for the first time
|
||||
set_running = !deploy_id_valid?(deploy_id)
|
||||
|
Loading…
x
Reference in New Issue
Block a user