mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
L #-: Linting vCenter DS mad drivers
This commit is contained in:
parent
7e4ea10b2e
commit
dc9be09721
@ -28,7 +28,6 @@ AllCops:
|
||||
- share/rubygems/generate
|
||||
- share/hooks/raft/follower_cleanup
|
||||
- share/esx-fw-vnc/Vagrantfile
|
||||
- share/vendor/ruby/gems/rbvmomi/Rakefile
|
||||
- share/vendor/ruby/gems/packethost/Rakefile
|
||||
- share/vendor/ruby/gems/packethost/Gemfile
|
||||
- share/vendor/ruby/gems/packethost/packethost.gemspec
|
||||
@ -62,12 +61,6 @@ AllCops:
|
||||
- src/pm_mad/remotes/ec2/reset
|
||||
- src/pm_mad/remotes/ec2/poll
|
||||
- src/onegate/config.ru
|
||||
- src/datastore_mad/remotes/vcenter/mkfs
|
||||
- src/datastore_mad/remotes/vcenter/stat
|
||||
- src/datastore_mad/remotes/vcenter/clone
|
||||
- src/datastore_mad/remotes/vcenter/cp
|
||||
- src/datastore_mad/remotes/vcenter/export
|
||||
- src/datastore_mad/remotes/vcenter/rm
|
||||
- src/im_mad/remotes/lxd-probes.d/pci.rb
|
||||
- src/im_mad/remotes/kvm-probes.d/pci.rb
|
||||
- src/im_mad/remotes/kvm.d/collectd-client.rb
|
||||
|
@ -16,19 +16,17 @@
|
||||
# limitations under the License. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
|
||||
ONE_LOCATION ||= ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
|
||||
GEMS_LOCATION = '/usr/share/one/gems' unless defined?(GEMS_LOCATION)
|
||||
RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby'
|
||||
GEMS_LOCATION ||= '/usr/share/one/gems'
|
||||
else
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
|
||||
GEMS_LOCATION = ONE_LOCATION + '/share/gems' unless defined?(GEMS_LOCATION)
|
||||
RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby'
|
||||
GEMS_LOCATION ||= ONE_LOCATION + '/share/gems'
|
||||
end
|
||||
|
||||
if File.directory?(GEMS_LOCATION)
|
||||
Gem.use_paths(GEMS_LOCATION)
|
||||
end
|
||||
Gem.use_paths(GEMS_LOCATION) if File.directory?(GEMS_LOCATION)
|
||||
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << File.dirname(__FILE__)
|
||||
@ -38,24 +36,29 @@ require 'vcenter_driver'
|
||||
drv_action_enc = ARGV[0]
|
||||
id = ARGV[1]
|
||||
|
||||
drv_action = OpenNebula::XMLElement.new
|
||||
drv_action.initialize_xml(Base64.decode64(drv_action_enc), 'DS_DRIVER_ACTION_DATA')
|
||||
DRV_ACTION_DS = '/DS_DRIVER_ACTION_DATA/DATASTORE/'
|
||||
|
||||
target_ds_ref = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VCENTER_DS_REF"]
|
||||
ds_image_dir = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VCENTER_DS_IMAGE_DIR"].match(%r{^/*(.*?)/*$})[1] rescue "one"
|
||||
src_path_escaped = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/PATH"]
|
||||
src_img_id = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/CLONING_ID"]
|
||||
drv_action = OpenNebula::XMLElement.new
|
||||
drv_action.initialize_xml(Base64.decode64(drv_action_enc),
|
||||
'DS_DRIVER_ACTION_DATA')
|
||||
|
||||
target_ds_ref = drv_action[DRV_ACTION_DS + 'TEMPLATE/VCENTER_DS_REF']
|
||||
ds_image_dir = drv_action[DRV_ACTION_DS + 'TEMPLATE/VCENTER_DS_IMAGE_DIR']
|
||||
.match(%r{^/*(.*?)/*$})[1] rescue 'one'
|
||||
src_path_escaped = drv_action['/DS_DRIVER_ACTION_DATA/IMAGE/PATH']
|
||||
src_img_id = drv_action['/DS_DRIVER_ACTION_DATA/IMAGE/CLONING_ID']
|
||||
|
||||
src_path = VCenterDriver::FileHelper.unescape_path(src_path_escaped)
|
||||
|
||||
check_valid src_img_id, "cloning id"
|
||||
check_valid src_path, "image path"
|
||||
check_valid target_ds_ref, "target ds ref"
|
||||
check_valid src_img_id, 'cloning id'
|
||||
check_valid src_path, 'image path'
|
||||
check_valid target_ds_ref, 'target ds ref'
|
||||
|
||||
# Get source ds_ref
|
||||
source_img = VCenterDriver::VIHelper.one_item(OpenNebula::Image, src_img_id)
|
||||
source_ds_id = source_img['DATASTORE_ID']
|
||||
source_ds = VCenterDriver::VIHelper.one_item(OpenNebula::Datastore, source_ds_id)
|
||||
source_ds = VCenterDriver::VIHelper.one_item(OpenNebula::Datastore,
|
||||
source_ds_id)
|
||||
source_ds_ref = source_ds['TEMPLATE/VCENTER_DS_REF']
|
||||
|
||||
# Generate target path
|
||||
@ -66,7 +69,8 @@ begin
|
||||
|
||||
ds = VCenterDriver::Datastore.new_from_ref(source_ds_ref, vi_client)
|
||||
|
||||
target_ds_vc = VCenterDriver::Datastore.new_from_ref(target_ds_ref, vi_client)
|
||||
target_ds_vc = VCenterDriver::Datastore.new_from_ref(target_ds_ref,
|
||||
vi_client)
|
||||
|
||||
target_ds_name = target_ds_vc['name']
|
||||
|
||||
@ -75,14 +79,14 @@ begin
|
||||
target_path << ext
|
||||
|
||||
puts ds.copy_virtual_disk(src_path, target_ds_vc, target_path)
|
||||
|
||||
rescue Exception => e
|
||||
rescue StandardError => e
|
||||
message = "Error cloning img #{src_path} to #{target_ds_name}"\
|
||||
" Reason: \"#{e.message}\"\n#{e.backtrace}"
|
||||
" Reason: \"#{e.message}\"."
|
||||
OpenNebula.log_error(message)
|
||||
STDERR.puts "#{message} #{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
|
||||
|
||||
exit -1
|
||||
if VCenterDriver::CONFIG[:debug_information]
|
||||
STDERR.puts "#{message} #{e.backtrace}"
|
||||
end
|
||||
exit(-1)
|
||||
ensure
|
||||
vi_client.close_connection if vi_client
|
||||
end
|
||||
|
@ -16,59 +16,59 @@
|
||||
# limitations under the License. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
|
||||
ONE_LOCATION ||= ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
|
||||
GEMS_LOCATION = '/usr/share/one/gems' unless defined?(GEMS_LOCATION)
|
||||
VAR_LOCATION = '/var/lib/one' unless defined?(VAR_LOCATION)
|
||||
RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby'
|
||||
GEMS_LOCATION ||= '/usr/share/one/gems'
|
||||
else
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
|
||||
GEMS_LOCATION = ONE_LOCATION + '/share/gems' unless defined?(GEMS_LOCATION)
|
||||
VAR_LOCATION = ONE_LOCATION + '/var' unless defined?(VAR_LOCATION)
|
||||
RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby'
|
||||
GEMS_LOCATION ||= ONE_LOCATION + '/share/gems'
|
||||
end
|
||||
|
||||
if File.directory?(GEMS_LOCATION)
|
||||
Gem.use_paths(GEMS_LOCATION)
|
||||
end
|
||||
Gem.use_paths(GEMS_LOCATION) if File.directory?(GEMS_LOCATION)
|
||||
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << File.dirname(__FILE__)
|
||||
|
||||
require 'vcenter_driver'
|
||||
|
||||
def is_the_file_location?(target_path, f)
|
||||
return target_path == File.basename(f)
|
||||
def file_location?(target_path, f)
|
||||
target_path == File.basename(f)
|
||||
end
|
||||
|
||||
def is_last_file_to_upload?(index, files_to_upload)
|
||||
return index == files_to_upload.size - 1
|
||||
def last_file_to_upload?(index, files_to_upload)
|
||||
index == files_to_upload.size - 1
|
||||
end
|
||||
|
||||
def there_is_not_system_error?(rc)
|
||||
return !rc
|
||||
!rc
|
||||
end
|
||||
|
||||
drv_action_enc = ARGV[0]
|
||||
id = ARGV[1]
|
||||
|
||||
drv_action = OpenNebula::XMLElement.new
|
||||
drv_action.initialize_xml(Base64.decode64(drv_action_enc), 'DS_DRIVER_ACTION_DATA')
|
||||
drv_action.initialize_xml(Base64.decode64(drv_action_enc),
|
||||
'DS_DRIVER_ACTION_DATA')
|
||||
|
||||
img_path = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/PATH"]
|
||||
ds_id = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/ID"]
|
||||
ds_ref = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VCENTER_DS_REF"]
|
||||
ds_image_dir = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VCENTER_DS_IMAGE_DIR"].match(%r{^/*(.*?)/*$})[1] rescue "one"
|
||||
md5 = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/MD5"]
|
||||
sha1 = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/SHA1"]
|
||||
nodecomp = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/NO_DECOMPRESS"]
|
||||
limit_bw = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/LIMIT_TRANSFER_BW"]
|
||||
DRV_ACTION_DS = '/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/'
|
||||
|
||||
check_valid img_path, "img_path"
|
||||
img_path = drv_action['/DS_DRIVER_ACTION_DATA/IMAGE/PATH']
|
||||
ds_id = drv_action['/DS_DRIVER_ACTION_DATA/DATASTORE/ID']
|
||||
ds_ref = drv_action[DRV_ACTION_DS + 'VCENTER_DS_REF']
|
||||
ds_image_dir = drv_action[DRV_ACTION_DS + 'VCENTER_DS_IMAGE_DIR']
|
||||
.match(%r{^/*(.*?)/*$})[1] rescue 'one'
|
||||
md5 = drv_action['/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/MD5']
|
||||
sha1 = drv_action['/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/SHA1']
|
||||
nodecomp = drv_action[DRV_ACTION_DS + 'NO_DECOMPRESS']
|
||||
limit_bw = drv_action[DRV_ACTION_DS + 'LIMIT_TRANSFER_BW']
|
||||
|
||||
check_valid img_path, 'img_path'
|
||||
|
||||
# if image is already in a vCenter datastore return the path
|
||||
if img_path.start_with? "vcenter://"
|
||||
img_path = img_path.sub("vcenter://", "")
|
||||
if img_path.start_with? 'vcenter://'
|
||||
img_path = img_path.sub('vcenter://', '')
|
||||
img_path = VCenterDriver::FileHelper.escape_path(img_path)
|
||||
puts img_path
|
||||
exit(0)
|
||||
@ -84,19 +84,19 @@ target_path = "#{ds_image_dir}/#{id}"
|
||||
if VCenterDriver::FileHelper.is_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 doesn't have the .vmdk extension, add it
|
||||
# if the original file doesnt have the vmdk extension, add it
|
||||
if !temp_file.match(/\.vmdk$/) && !temp_file.match(/\.iso$/)
|
||||
temp_file += ".vmdk"
|
||||
temp_file += '.vmdk'
|
||||
end
|
||||
|
||||
# Create tmp directory
|
||||
FileUtils.mkdir_p(temp_folder)
|
||||
|
||||
# Specify downloader args
|
||||
downsh_args = " "
|
||||
downsh_args << "--md5 #{md5} " if md5 && !md5.empty? && !md5.eql?("-")
|
||||
downsh_args = ' '
|
||||
downsh_args << "--md5 #{md5} " if md5 && !md5.empty? && !md5.eql?('-')
|
||||
downsh_args << "--sha1 #{sha1} " if sha1 && !sha1.empty?
|
||||
downsh_args << "--nodecomp " if nodecomp && !nodecomp.empty?
|
||||
downsh_args << '--nodecomp ' if nodecomp && !nodecomp.empty?
|
||||
downsh_args << "--limit #{limit_bw} " if limit_bw && !limit_bw.empty?
|
||||
downsh_args << '--convert vmdk'
|
||||
|
||||
@ -107,7 +107,7 @@ if VCenterDriver::FileHelper.is_remote_or_needs_unpack?(img_path)
|
||||
if there_is_not_system_error?(rc)
|
||||
STDERR.puts "Error downloading #{img_path}"
|
||||
FileUtils.rm_rf(temp_file)
|
||||
exit -1
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
img_path = temp_file
|
||||
@ -128,36 +128,37 @@ when :flat
|
||||
end
|
||||
|
||||
files_to_upload.each_with_index do |f, index|
|
||||
|
||||
path = "#{target_path}/#{File.basename(f)}"
|
||||
|
||||
# Change path for gzipped standalone file
|
||||
if is_the_file_location?(target_path, f)
|
||||
if file_location?(target_path, f)
|
||||
path = "#{target_path}/#{filename}"
|
||||
|
||||
# remove gz or bz2 if part of filename
|
||||
if path.end_with?("gz") && VCenterDriver::FileHelper.is_vmdk?(f)
|
||||
path.gsub!(/gz$/,'')
|
||||
if path.end_with?('gz') && VCenterDriver::FileHelper.is_vmdk?(f)
|
||||
path.gsub!(/gz$/, '')
|
||||
end
|
||||
|
||||
if path.end_with?("bz2") && VCenterDriver::FileHelper.is_vmdk?(f)
|
||||
path.gsub!(/bz2$/,'')
|
||||
if path.end_with?('bz2') && VCenterDriver::FileHelper.is_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)
|
||||
path.gsub!(/vmdk$/,'')
|
||||
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)
|
||||
path = "#{File.dirname(path)}/#{File.basename(path,".*")}"
|
||||
path = "#{File.dirname(path)}/#{File.basename(path, '.*')}"
|
||||
extension = '.iso'
|
||||
end
|
||||
|
||||
if is_last_file_to_upload?(index, files_to_upload)
|
||||
if last_file_to_upload?(index, files_to_upload)
|
||||
uploader_args = "#{ds_id} #{ds_ref} #{path}#{extension} #{f}"
|
||||
else
|
||||
uploader_args = "#{ds_id} #{ds_ref} #{path} #{f} &> /dev/null"
|
||||
@ -166,11 +167,11 @@ files_to_upload.each_with_index do |f, index|
|
||||
cmd = "#{File.dirname(__FILE__)}/../vcenter_uploader.rb #{uploader_args}"
|
||||
rc = system(cmd)
|
||||
|
||||
if there_is_not_system_error?(rc)
|
||||
STDERR.puts "Cannot upload file #{f}"
|
||||
FileUtils.rm_rf(temp_file) if temp_file
|
||||
exit(-1)
|
||||
end
|
||||
next unless there_is_not_system_error?(rc)
|
||||
|
||||
STDERR.puts "Cannot upload file #{f}"
|
||||
FileUtils.rm_rf(temp_file) if temp_file
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
FileUtils.rm_rf(temp_file) if temp_file
|
||||
|
@ -20,19 +20,17 @@
|
||||
# This script is used to export a VMDK from a vCenter DS to a Marketplace
|
||||
###############################################################################
|
||||
|
||||
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
|
||||
ONE_LOCATION ||= ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
|
||||
GEMS_LOCATION = '/usr/share/one/gems' unless defined?(GEMS_LOCATION)
|
||||
RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby'
|
||||
GEMS_LOCATION ||= '/usr/share/one/gems'
|
||||
else
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
|
||||
GEMS_LOCATION = ONE_LOCATION + '/share/gems' unless defined?(GEMS_LOCATION)
|
||||
RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby'
|
||||
GEMS_LOCATION ||= ONE_LOCATION + '/share/gems'
|
||||
end
|
||||
|
||||
if File.directory?(GEMS_LOCATION)
|
||||
Gem.use_paths(GEMS_LOCATION)
|
||||
end
|
||||
Gem.use_paths(GEMS_LOCATION) if File.directory?(GEMS_LOCATION)
|
||||
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << File.dirname(__FILE__)
|
||||
@ -40,24 +38,23 @@ $LOAD_PATH << File.dirname(__FILE__)
|
||||
require 'opennebula'
|
||||
|
||||
drv_action_enc = ARGV[0]
|
||||
id = ARGV[1]
|
||||
|
||||
drv_action = OpenNebula::XMLElement.new
|
||||
drv_action.initialize_xml(Base64.decode64(drv_action_enc), 'DS_DRIVER_ACTION_DATA')
|
||||
drv_action.initialize_xml(Base64.decode64(drv_action_enc),
|
||||
'DS_DRIVER_ACTION_DATA')
|
||||
|
||||
img_source = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/SOURCE"]
|
||||
img_size = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/SIZE"]
|
||||
md5 = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/MD5"]
|
||||
img_source = drv_action['/DS_DRIVER_ACTION_DATA/IMAGE/SOURCE']
|
||||
img_size = drv_action['/DS_DRIVER_ACTION_DATA/IMAGE/SIZE']
|
||||
md5 = drv_action['/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/MD5']
|
||||
md5 ||= '-'
|
||||
|
||||
md5 = md5.nil? ? "-" : md5
|
||||
|
||||
ds_id = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/ID"]
|
||||
ds_id = drv_action['/DS_DRIVER_ACTION_DATA/DATASTORE/ID']
|
||||
|
||||
if img_source.nil?
|
||||
message = "Not enough information to export the image,"\
|
||||
" missing image source."
|
||||
message = 'Not enough information to export the image, '\
|
||||
'missing image source.'
|
||||
STDERR.puts error_message(message)
|
||||
exit -1
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
# Create vcenter url with all needed information to extract the file from
|
||||
|
@ -20,19 +20,17 @@
|
||||
# This script is used retrieve the file size of a disk
|
||||
###############################################################################
|
||||
|
||||
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
|
||||
ONE_LOCATION ||= ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
|
||||
GEMS_LOCATION = '/usr/share/one/gems' unless defined?(GEMS_LOCATION)
|
||||
RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby'
|
||||
GEMS_LOCATION ||= '/usr/share/one/gems'
|
||||
else
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
|
||||
GEMS_LOCATION = ONE_LOCATION + '/share/gems' unless defined?(GEMS_LOCATION)
|
||||
RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby'
|
||||
GEMS_LOCATION ||= ONE_LOCATION + '/share/gems'
|
||||
end
|
||||
|
||||
if File.directory?(GEMS_LOCATION)
|
||||
Gem.use_paths(GEMS_LOCATION)
|
||||
end
|
||||
Gem.use_paths(GEMS_LOCATION) if File.directory?(GEMS_LOCATION)
|
||||
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << File.dirname(__FILE__)
|
||||
@ -40,34 +38,40 @@ $LOAD_PATH << File.dirname(__FILE__)
|
||||
require 'vcenter_driver'
|
||||
|
||||
drv_action_enc = ARGV[0]
|
||||
id = ARGV[1]
|
||||
|
||||
drv_action = OpenNebula::XMLElement.new
|
||||
drv_action.initialize_xml(Base64.decode64(drv_action_enc), 'DS_DRIVER_ACTION_DATA')
|
||||
drv_action.initialize_xml(Base64.decode64(drv_action_enc),
|
||||
'DS_DRIVER_ACTION_DATA')
|
||||
|
||||
ds_id = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/ID"]
|
||||
ds_ref = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VCENTER_DS_REF"]
|
||||
ds_image_dir = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VCENTER_DS_IMAGE_DIR"].match(%r{^/*(.*?)/*$})[1] rescue "one"
|
||||
img_id = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/ID"]
|
||||
adapter_type = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/VCENTER_ADAPTER_TYPE"] ||
|
||||
VCenterDriver::VIHelper.get_default("IMAGE/TEMPLATE/VCENTER_ADAPTER_TYPE")
|
||||
disk_type = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/VCENTER_DISK_TYPE"] ||
|
||||
VCenterDriver::VIHelper.get_default("IMAGE/TEMPLATE/VCENTER_DISK_TYPE")
|
||||
size = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/SIZE"]
|
||||
fs_type = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/FSTYPE"]
|
||||
DRV_ACTION_DS = '/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/'
|
||||
DRV_ACTION_IMG = '/DS_DRIVER_ACTION_DATA/IMAGE/'
|
||||
|
||||
check_valid img_id, "img_id"
|
||||
check_valid adapter_type, "adapter_type"
|
||||
check_valid disk_type, "disk_type"
|
||||
check_valid size, "size"
|
||||
check_valid ds_ref, "ds_ref"
|
||||
ds_id = drv_action['/DS_DRIVER_ACTION_DATA/DATASTORE/ID']
|
||||
ds_ref = drv_action[DRV_ACTION_DS + 'VCENTER_DS_REF']
|
||||
ds_image_dir = drv_action[DRV_ACTION_DS + 'VCENTER_DS_IMAGE_DIR']
|
||||
.match(%r{^/*(.*?)/*$})[1] rescue 'one'
|
||||
img_id = drv_action[DRV_ACTION_IMG + 'ID']
|
||||
adapter_type = drv_action[DRV_ACTION_IMG + 'TEMPLATE/VCENTER_ADAPTER_TYPE'] ||
|
||||
VCenterDriver::VIHelper
|
||||
.get_default('IMAGE/TEMPLATE/VCENTER_ADAPTER_TYPE')
|
||||
disk_type = drv_action[DRV_ACTION_IMG + 'TEMPLATE/VCENTER_DISK_TYPE'] ||
|
||||
VCenterDriver::VIHelper
|
||||
.get_default('IMAGE/TEMPLATE/VCENTER_DISK_TYPE')
|
||||
size = drv_action[DRV_ACTION_IMG + 'SIZE']
|
||||
fs_type = drv_action[DRV__ACTION_IMG + 'FSTYPE']
|
||||
|
||||
# TODO path in vCenter? choose a specific directory
|
||||
check_valid img_id, 'img_id'
|
||||
check_valid adapter_type, 'adapter_type'
|
||||
check_valid disk_type, 'disk_type'
|
||||
check_valid size, 'size'
|
||||
check_valid ds_ref, 'ds_ref'
|
||||
|
||||
# TODO: path in vCenter? choose a specific directory
|
||||
|
||||
img_name = "#{ds_image_dir}/#{img_id}/one-#{img_id}"
|
||||
|
||||
if fs_type == "save_as"
|
||||
puts img_name + ".vmdk"
|
||||
if fs_type == 'save_as'
|
||||
puts img_name + '.vmdk'
|
||||
exit 0
|
||||
end
|
||||
|
||||
@ -77,14 +81,14 @@ begin
|
||||
ds = VCenterDriver::Datastore.new_from_ref(ds_ref, vi_client)
|
||||
|
||||
puts ds.create_virtual_disk(img_name, size, adapter_type, disk_type)
|
||||
|
||||
rescue Exception => e
|
||||
rescue StandardError => e
|
||||
message = "Error creating virtual disk #{img_name}."\
|
||||
" Reason: \"#{e.message}\"\n#{e.backtrace}"
|
||||
" Reason: \"#{e.message}\"."
|
||||
OpenNebula.log_error(message)
|
||||
STDERR.puts "#{message} #{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
|
||||
|
||||
exit -1
|
||||
if VCenterDriver::CONFIG[:debug_information]
|
||||
STDERR.puts "#{message} #{e.backtrace}"
|
||||
end
|
||||
exit(-1)
|
||||
ensure
|
||||
vi_client.close_connection if vi_client
|
||||
end
|
||||
|
@ -41,10 +41,10 @@ $LOAD_PATH << File.dirname(__FILE__)
|
||||
|
||||
require 'vcenter_driver'
|
||||
|
||||
size = ARGV[0]
|
||||
path = ARGV[2]
|
||||
vmid = ARGV[3]
|
||||
dsid = ARGV[4]
|
||||
size = ARGV[0]
|
||||
path = ARGV[2]
|
||||
vmid = ARGV[3]
|
||||
dsid = ARGV[4]
|
||||
|
||||
check_valid size, 'size'
|
||||
check_valid path, 'path'
|
||||
|
Loading…
x
Reference in New Issue
Block a user