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

Rubocop linting in vcenter library

This commit is contained in:
Tino Vazquez 2018-07-20 17:33:16 +02:00
parent 965c97949a
commit 974f2e4494
19 changed files with 182 additions and 203 deletions

View File

@ -16,16 +16,16 @@
# limitations under the License. #
# ---------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
@ -35,7 +35,7 @@ drv_action_enc = ARGV[4]
drv_action = OpenNebula::XMLElement.new
drv_action.initialize_xml(Base64.decode64(drv_action_enc), 'VMM_DRIVER_ACTION_DATA')
vc_cluster_name = drv_action["/VMM_DRIVER_ACTION_DATA/HOST"]
vc_cluster_name = drv_action['VMM_DRIVER_ACTION_DATA/HOST']
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
host_id = host['ID']
@ -43,16 +43,15 @@ begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
# Setting one_item with info with the vm_xml including DISK to be added
one_item = drv_action.retrieve_xmlelements("VM").first
one_item = drv_action.retrieve_xmlelements('VM').first
vm = VCenterDriver::VirtualMachine.new_one(vi_client, vm_ref, one_item)
vm.attach_disk
rescue Exception => e
rescue StandardError => e
message = "Attach image for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
"failed due to \"#{e.message}\"\n"
OpenNebula.log_error(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end

View File

@ -16,16 +16,16 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
@ -42,17 +42,16 @@ begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
# Setting one_item with info with the vm_xml including NIC to be added
one_item = drv_action.retrieve_xmlelements("VM").first
one_item = drv_action.retrieve_xmlelements('VM').first
vm = VCenterDriver::VirtualMachine.new_one(vi_client, vm_ref, one_item)
vm.attach_nic
rescue Exception => e
rescue StandardError => e
message = "Attach NIC for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
"failed due to \"#{e.message}\"\n"
OpenNebula.log_error(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end

View File

@ -16,16 +16,16 @@
# limitations under the License. #
# ---------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
@ -47,12 +47,11 @@ begin
vm.one_item = drv_action.retrieve_xmlelements('VM').first
vm.poweroff_hard
rescue Exception => e
rescue StandardError => e
message = "Cancel VM #{vm_ref} failed due to "\
"\"#{e.message}\"\n#{e.backtrace.join("\n")}"
OpenNebula.log_error(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end

View File

@ -36,7 +36,7 @@ vm_id = ARGV[2]
## Helpers
def deploy_id_valid?(deploy_id)
deploy_id && !deploy_id.empty?
deploy_id && !deploy_id.empty?
end
drv_action = OpenNebula::XMLElement.new
@ -46,8 +46,8 @@ deploy_id = drv_action['DEPLOY_ID']
host_id = drv_action['HISTORY_RECORDS/HISTORY/HID']
begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, vm_id)
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, vm_id)
if deploy_id_valid?(deploy_id)
# VM is not new, we just need to reconfigure it and to power it on

View File

@ -16,16 +16,16 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
@ -43,14 +43,15 @@ begin
vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref)
raise "vCenter doesn't allow to remove a virtual disk if it's part of a "\
"snapshot of the virtual machine." if vm.has_snapshots?
rescue Exception => e
if vm.has_snapshots?
raise 'vCenter doesn\'t allow to remove a virtual disk if it\'s part of a '\
'snapshot of the virtual machine.'
end
rescue StandardError => e
message = "Detach DISK for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
"failed due to \"#{e.message}\"\n#{e.backtrace.join("\n")}"
OpenNebula.log_error(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end

View File

@ -16,16 +16,16 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
@ -42,16 +42,15 @@ begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
# Setting one_item with info with the vm_xml including NIC to be added
one_item = drv_action.retrieve_xmlelements("VM").first
one_item = drv_action.retrieve_xmlelements('VM').first
vm = VCenterDriver::VirtualMachine.new_one(vi_client, vm_ref, one_item)
vm.detach_nic
rescue Exception => e
rescue StandardError => e
message = "Detach NIC for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
"failed due to \"#{e.message}\"\n"
OpenNebula.log_error(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end

View File

@ -15,17 +15,17 @@
# See the License for the specific language governing permissions and #
# limitations under the License. #
# ---------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
@ -34,7 +34,6 @@ src_host = ARGV[-3]
dst_host = ARGV[-4]
begin
one_client = OpenNebula::Client.new
pool = OpenNebula::HostPool.new(one_client)
@ -43,7 +42,7 @@ begin
src_id = pool["/HOST_POOL/HOST[NAME='#{src_host}']/ID"].to_i
dst_id = pool["/HOST_POOL/HOST[NAME='#{dst_host}']/ID"].to_i
vi_client = VCenterDriver::VIClient.new_from_host(src_id)
vi_client = VCenterDriver::VIClient.new_from_host(src_id)
# required one objects
vm = OpenNebula::VirtualMachine.new_with_id(vm_id, one_client)
@ -54,21 +53,21 @@ begin
dst_host.info
# required vcenter objects
vc_vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm["/VM/DEPLOY_ID"])
vc_host = VCenterDriver::ClusterComputeResource.new_from_ref(dst_host["/HOST/TEMPLATE/VCENTER_CCR_REF"],vi_client).item
vc_vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm['/VM/DEPLOY_ID'])
ccr_ref = dst_host['/HOST/TEMPLATE/VCENTER_CCR_REF']
esx_host = dst_host['HOST/TEMPLATE/HOST/HOSTNAME']
vc_host = VCenterDriver::ClusterComputeResource.new_from_ref(ccr_ref, vi_client).item
config = {:cluster => vc_host }
config = { :cluster => vc_host }
vc_vm.migrate(config)
vm.replace({"VCENTER_CCR_REF" => dst_host["/HOST/TEMPLATE/VCENTER_CCR_REF"], "VCENTER_ESX_HOST" => dst_host["/HOST/TEMPLATE/HOST/HOSTNAME"]})
rescue Exception => e
vm.replace({ 'VCENTER_CCR_REF' => ccr_ref, 'VCENTER_ESX_HOST' => esx_host })
rescue StandardError => e
message = "Cannot migrate for VM #{vm_id}"\
"failed due to "\
'failed due to '\
"\"#{e.message}\"\n"
OpenNebula.log_error(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end
# raise "Cannot migrate VM #{e.message}\n#{e.backtrace.join("\n")}"
end

View File

@ -16,17 +16,16 @@
# limitations under the License. #
# ---------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
@ -34,24 +33,22 @@ vm_ref = ARGV[0]
vc_cluster_name = ARGV[1]
vm_id = ARGV[2]
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
host_id = host['ID']
begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
vm = VCenterDriver::VirtualMachine.new(vi_client, vm_ref, vi_client)
vm = VCenterDriver::VirtualMachine.new(vi_client, vm_ref, vm_id)
vm.monitor_poll_vm
puts vm.info
rescue Exception => e
message = "Cannot poll info for VM #{vm_ref} on vCenter cluster "\
rescue StandardError => e
message = "Cannot poll info for VM #{vm_ref} with OpenNebula id #{vm_id} on vCenter cluster "\
"#{vc_cluster_name} failed due to "\
"\"#{e.message}\"\n#{e.backtrace.join("\n")}"
OpenNebula.log_error(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end

View File

@ -15,6 +15,7 @@
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
STDIN=`cat -`
exit 0

View File

@ -16,16 +16,16 @@
# limitations under the License. #
# ---------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
@ -41,13 +41,12 @@ begin
vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref)
vm.reboot
rescue Exception => e
rescue StandardError => e
message = "Guest reboot of VM #{vm_ref} on vCenter cluster "\
"#{vc_cluster_name} failed due to "\
"\"#{e.message}\"\n#{e.backtrace.join("\n")}"
OpenNebula.log_error(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end

View File

@ -16,18 +16,19 @@
# limitations under the License. #
# ---------------------------------------------------------------------------- #
input = STDIN.read
# Avoid pipeline errors by reading and discarding stdin input
STDIN.read
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
@ -35,22 +36,20 @@ vm_ref = ARGV[0]
vc_cluster_name = ARGV[-1]
vm_id = ARGV[-2]
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
host_id = host['ID']
begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
vm = VCenterDriver::VirtualMachine.new(vi_client, vm_ref, vm_id)
vm = VCenterDriver::VirtualMachine.new(vi_client, vm_ref, vm_id)
vm.regenerate_context
rescue Exception => e
rescue StandardErrord => e
message = "Reconfiguration of VM #{vm_ref} on vCenter cluster "\
"#{vc_cluster_name} failed due to "\
"\"#{e.message}\"\n#{e.backtrace}"
STDERR.puts error_message(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end

View File

@ -16,16 +16,16 @@
# limitations under the License. #
# ---------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
@ -37,17 +37,15 @@ host_id = host['ID']
begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref)
vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref)
vm.reset
rescue Exception => e
rescue StandardError => e
message = "Reset of VM #{vm_ref} on vCenter cluster "\
"#{vc_cluster_name} failed due to "\
"\"#{e.message}\"\n#{e.backtrace.join("\n")}"
OpenNebula.log_error(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end

View File

@ -16,40 +16,37 @@
# limitations under the License. #
# ---------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
vm_ref = ARGV[2]
vc_cluster_name = ARGV[-1]
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
host_id = host['ID']
begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref)
vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref)
vm.poweron
vm.set_running(true)
rescue Exception => e
rescue StandardError => e
message = "Restore of VM #{vm_ref} on vCenter cluster "\
"#{vc_cluster_name} failed due to "\
"\"#{e.message}\"\n#{e.backtrace.join("\n")}"
OpenNebula.log_error(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end

View File

@ -16,16 +16,16 @@
# limitations under the License. #
# ---------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
@ -35,23 +35,23 @@ vc_cluster_name = ARGV[-1]
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
host_id = host['ID']
drv_action_enc = STDIN.read.gsub("\n","")
drv_action_enc = STDIN.read.delete("\n")
drv_action = OpenNebula::XMLElement.new
drv_action.initialize_xml(Base64.decode64(drv_action_enc),
'VMM_DRIVER_ACTION_DATA')
lcm_state = drv_action["/VMM_DRIVER_ACTION_DATA/VM/LCM_STATE"]
check_valid(lcm_state, "lcm_state")
lcm_state = drv_action['VMM_DRIVER_ACTION_DATA/VM/LCM_STATE']
check_valid(lcm_state, 'lcm_state')
lcm_state_str = OpenNebula::VirtualMachine::LCM_STATE[lcm_state.to_i]
if lcm_state_str == "SAVE_MIGRATE"
STDERR.puts "Migration between vCenters cluster not supported"
exit -1
if lcm_state_str == 'SAVE_MIGRATE'
STDERR.puts 'Migration between vCenters cluster not supported'
exit(-1)
end
if !["SAVE_SUSPEND", "SAVE_STOP"].include?(lcm_state_str)
STDERR.puts "Wrong lcm state when saving VM"
exit -1
if !(%{'SAVE_SUSPEND', 'SAVE_STOP'}).include?(lcm_state_str)
STDERR.puts "Wrong lcm state #{lcm_state_str} }when saving VM"
exit(-1)
end
begin
@ -61,12 +61,12 @@ begin
vm.suspend
rescue Exception => e
rescue StandardError => e
message = "Save of VM #{vm_ref} on vCenter cluster "\
"#{vc_cluster_name} failed due to "\
"\"#{e.message}\"\n#{e.backtrace.join("\n")}"
OpenNebula.log_error(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end

View File

@ -16,16 +16,16 @@
# limitations under the License. #
# ---------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
@ -36,22 +36,20 @@ vm_id = ARGV[2]
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
host_id = host['ID']
drv_action_enc = STDIN.read.gsub("\n","")
drv_action_enc = STDIN.read.delete("\n")
drv_action = OpenNebula::XMLElement.new
drv_action.initialize_xml(Base64.decode64(drv_action_enc),
'VMM_DRIVER_ACTION_DATA')
lcm_state = drv_action["/VMM_DRIVER_ACTION_DATA/VM/LCM_STATE"]
check_valid(lcm_state, "lcm_state")
lcm_state = drv_action['VMM_DRIVER_ACTION_DATA/VM/LCM_STATE']
check_valid(lcm_state, 'lcm_state')
lcm_state_str = OpenNebula::VirtualMachine::LCM_STATE[lcm_state.to_i]
if !["SHUTDOWN", "SHUTDOWN_POWEROFF", "SHUTDOWN_UNDEPLOY"].include?(lcm_state_str)
STDERR.puts "Wrong lcm state when shutting down VM"
exit -1
if !(%{'SHUTDOWN', 'SHUTDOWN_POWEROFF', 'SHUTDOWN_UNDEPLOY'}).include?(lcm_state_str)
STDERR.puts "Wrong lcm state #{lcm_state_str} when shutting down VM"
exit(-1)
end
## TODO copy_template
begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
@ -64,14 +62,13 @@ begin
vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref)
vm.shutdown #Undeploy, Poweroff or Terminate
rescue Exception => e
vm.shutdown # Undeploy, Poweroff or Terminate
rescue StandardError => e
message = "Shutdown of VM #{vm_ref} on vCenter cluster "\
"#{vc_cluster_name} failed due to "\
"\"#{e.message}\"\n#{e.backtrace.join("\n")}"
OpenNebula.log_error(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end

View File

@ -16,16 +16,16 @@
# limitations under the License. #
# ---------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
@ -44,27 +44,26 @@ snap_name = drv_action["VM/TEMPLATE/SNAPSHOT[ACTIVE='YES']/NAME"]
begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
one_vm = drv_action.retrieve_xmlelements("VM").first
one_vm = drv_action.retrieve_xmlelements('VM').first
vm = VCenterDriver::VirtualMachine.new_one(vi_client, vm_ref, one_vm)
persistent_disks = one_vm.retrieve_xmlelements("TEMPLATE/DISK[PERSISTENT=YES]")
persistent_disks = one_vm.retrieve_xmlelements('TEMPLATE/DISK[PERSISTENT=YES]')
if !persistent_disks.empty?
STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
"#{vc_cluster_name} cannot be performed if "\
"it contains persistent disks"
'it contains persistent disks.'
exit 1
end
puts vm.create_snapshot(snap_id, snap_name)
rescue Exception => e
rescue StandardError => e
message = "Snapshot of VM #{vm_ref} on vCenter cluster "\
"#{vc_cluster_name} failed due to "\
"\"#{e.message}\"\n"
OpenNebula.log_error(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end

View File

@ -16,16 +16,16 @@
# limitations under the License. #
# ---------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
@ -38,17 +38,15 @@ host_id = host['ID']
begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref)
vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref)
vm.delete_snapshot(snap_id)
rescue Exception => e
rescue StandardError => e
message = "Snapshot of VM #{vm_ref} on vCenter cluster "\
"#{vc_cluster_name} could not be deleted due to "\
"\"#{e.message}\"\n"
OpenNebula.log_error(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end

View File

@ -16,16 +16,16 @@
# limitations under the License. #
# ---------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
@ -42,13 +42,12 @@ begin
vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref)
vm.revert_snapshot(snap_id)
rescue Exception => e
rescue StandardError => e
message = "Snapshot of VM #{vm_ref} on vCenter cluster "\
"#{vc_cluster_name} could not be reverted due "\
"to \"#{e.message}\"\n"
OpenNebula.log_error(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end

View File

@ -18,25 +18,25 @@
# Set up the environment for the driver #
# ---------------------------------------------------------------------------- #
ONE_LOCATION = ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
BIN_LOCATION = "/usr/bin" if !defined?(BIN_LOCATION)
LIB_LOCATION = "/usr/lib/one" if !defined?(LIB_LOCATION)
ETC_LOCATION = "/etc/one/" if !defined?(ETC_LOCATION)
VAR_LOCATION = "/var/lib/one" if !defined?(VAR_LOCATION)
BIN_LOCATION = '/usr/bin' unless defined?(BIN_LOCATION)
LIB_LOCATION = '/usr/lib/one' unless defined?(LIB_LOCATION)
ETC_LOCATION = '/etc/one/' unless defined?(ETC_LOCATION)
VAR_LOCATION = '/var/lib/one' unless defined?(VAR_LOCATION)
else
BIN_LOCATION = ONE_LOCATION + "/bin" if !defined?(BIN_LOCATION)
LIB_LOCATION = ONE_LOCATION + "/lib" if !defined?(LIB_LOCATION)
ETC_LOCATION = ONE_LOCATION + "/etc/" if !defined?(ETC_LOCATION)
VAR_LOCATION = ONE_LOCATION + "/var/" if !defined?(VAR_LOCATION)
BIN_LOCATION = ONE_LOCATION + '/bin' unless defined?(BIN_LOCATION)
LIB_LOCATION = ONE_LOCATION + '/lib' unless defined?(LIB_LOCATION)
ETC_LOCATION = ONE_LOCATION + '/etc/' unless defined?(ETC_LOCATION)
VAR_LOCATION = ONE_LOCATION + '/var/' unless defined?(VAR_LOCATION)
end
ENV['LANG'] = 'C'
$: << LIB_LOCATION + '/ruby/vendors/rbvmomi/lib'
$: << LIB_LOCATION + '/ruby'
$: << LIB_LOCATION + '/ruby/vcenter_driver'
$LOAD_PATH << LIB_LOCATION + '/ruby/vendors/rbvmomi/lib'
$LOAD_PATH << LIB_LOCATION + '/ruby'
$LOAD_PATH << LIB_LOCATION + '/ruby/vcenter_driver'
require 'rbvmomi'
require 'yaml'
@ -70,13 +70,13 @@ def error_message(message)
error_str << message
error_str << "\nERROR MESSAGE ------>8--"
return error_str
error_str
end
def check_valid(parameter, label)
if parameter.nil? || parameter.empty?
STDERR.puts error_message("The parameter '#{label}' is required for this action.")
exit -1
exit(-1)
end
end
@ -85,12 +85,12 @@ def check_item(item, target_class)
item.name if CHECK_REFS
if target_class
if !item.instance_of?(target_class)
raise "Expecting type 'RbVmomi::VIM::#{target_class}'. " <<
raise "Expecting type 'RbVmomi::VIM::#{target_class}'. " \
"Got '#{item.class} instead."
end
end
rescue RbVmomi::Fault => e
raise "Reference \"#{item._ref}\" error. The reference does not exist"
raise "Reference \"#{item._ref}\" error [#{e.message}]. The reference does not exist"
end
end
@ -98,9 +98,8 @@ def wait_deploy_timeout(vm, timeout_deploy = 300)
time_start = Time.now
begin
time_running = Time.now - time_start
if time_running.to_i >= timeout_deploy
raise "reached deploy timeout"
end
raise 'reached deploy timeout' if time_running.to_i >= timeout_deploy
sleep(2)
state = vm.item.summary.runtime.powerState
end until(state == "poweredOn")