1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-04-01 06:50:25 +03:00

Make code more readable (#2229)

This commit is contained in:
jgarriuni 2018-06-28 12:24:54 +02:00 committed by Tino Vázquez
parent 7ab59e48be
commit 7d7a2a5921
4 changed files with 31 additions and 7 deletions

View File

@ -31,6 +31,18 @@ $: << File.dirname(__FILE__)
require 'vcenter_driver'
def is_the_file_location?(target_path, f)
return target_path == File.basename(f)
end
def is_last_file_to_upload?(index, files_to_upload)
return index == files_to_upload.size - 1
end
def there_is_not_system_error?(rc)
return !rc
end
drv_action_enc = ARGV[0]
id = ARGV[1]
@ -85,7 +97,7 @@ if VCenterDriver::FileHelper.is_remote_or_needs_unpack?(img_path)
rc = system("#{downloader} #{img_path} #{temp_file}")
if !rc
if there_is_not_system_error(rc)
STDERR.puts "Error downloading #{img_path}"
FileUtils.rm_rf(temp_file)
exit -1
@ -113,7 +125,7 @@ files_to_upload.each_with_index do |f, index|
path = "#{target_path}/#{File.basename(f)}"
# Change path for gzipped standalone file
if(target_path == File.basename(f))
if is_the_file_location?(target_path, f)
path = "#{target_path}/#{filename}"
# remove gz or bz2 if part of filename
@ -138,7 +150,7 @@ files_to_upload.each_with_index do |f, index|
extension = '.iso'
end
if index == files_to_upload.size - 1
if is_last_file_to_upload?(index, files_to_upload)
uploader_args = ds_id + " " + ds_ref + " " +
"#{path}#{extension}" + " " + f
else
@ -149,7 +161,7 @@ files_to_upload.each_with_index do |f, index|
cmd = "#{File.dirname(__FILE__)}/../vcenter_uploader.rb #{uploader_args}"
rc = system(cmd)
if !rc
if there_is_not_system_error?(rc)
STDERR.puts "Cannot upload file #{f}"
FileUtils.rm_rf(temp_file) if temp_file
exit(-1)

View File

@ -33,6 +33,10 @@ $: << File.dirname(__FILE__)
require 'vcenter_driver'
def is_not_dsid_or_dsref_valid?(ds_id, ds_ref)
return ds_id.nil? || ds_ref.nil?
end
drv_action_enc = ARGV[0]
id = ARGV[1]
@ -43,7 +47,7 @@ ds_id = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/ID"]
ds_ref = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VCENTER_DS_REF"]
check_valid ds_ref, "ds_ref"
if ds_id.nil? || ds_ref.nil?
if is_not_dsid_or_dsref_valid?(ds_id, ds_ref)
STDERR.puts "Not enough information to monitor the datastore."
exit -1
end

View File

@ -33,6 +33,10 @@ $: << File.dirname(__FILE__)
require 'vcenter_driver'
def was_img_imported?(imported)
return imported.nil? || imported.empty?
end
drv_action_enc = ARGV[0]
id = ARGV[1]
@ -50,7 +54,7 @@ check_valid img_src, "img_src"
CDROM = "1"
begin
if imported.nil? || imported.empty?
if !was_img_imported?(imported)
vi_client = VCenterDriver::VIClient.new_from_datastore(ds_id)
ds = VCenterDriver::Datastore.new_from_ref(ds_ref, vi_client)

View File

@ -29,6 +29,10 @@ $: << File.dirname(__FILE__)
require 'vcenter_driver'
def is_deploy_id_valid?(deploy_id)
return deploy_id && !deploy_id.empty?
end
dfile = ARGV[0]
cluster_name = ARGV[1]
vm_id = ARGV[2]
@ -44,7 +48,7 @@ begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, vm_id)
if deploy_id && !deploy_id.empty?
if is_deploy_id_valid?(deploy_id)
# VM is not new, we just need to reconfigure it and to power it on
vm = VCenterDriver::VirtualMachine.new_one(vi_client, deploy_id, one_vm)
else