1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

L #-: Changes for rubocop linting

In all vcenter VMM driver scripts

(cherry picked from commit d0e8d214c61533f1937f59021d2c2a725a43d377)
This commit is contained in:
Tino Vazquez 2019-12-04 19:43:16 +01:00
parent 95ff3fc88e
commit 9128a58ede
No known key found for this signature in database
GPG Key ID: 2FE9C32E94AEABBE
18 changed files with 170 additions and 233 deletions

View File

@ -102,21 +102,6 @@ AllCops:
- src/vnm_mad/remotes/ovswitch_vxlan/post
- src/vnm_mad/remotes/ovswitch_vxlan/clean
- src/vnm_mad/remotes/ovswitch_vxlan/pre
- src/vmm_mad/remotes/vcenter/attach_nic
- src/vmm_mad/remotes/vcenter/cancel
- src/vmm_mad/remotes/vcenter/snapshot_revert
- src/vmm_mad/remotes/vcenter/detach_nic
- src/vmm_mad/remotes/vcenter/snapshot_delete
- src/vmm_mad/remotes/vcenter/detach_disk
- src/vmm_mad/remotes/vcenter/shutdown
- src/vmm_mad/remotes/vcenter/attach_disk
- src/vmm_mad/remotes/vcenter/reboot
- src/vmm_mad/remotes/vcenter/reset
- src/vmm_mad/remotes/vcenter/reconfigure
- src/vmm_mad/remotes/vcenter/save
- src/vmm_mad/remotes/vcenter/restore
- src/vmm_mad/remotes/vcenter/snapshot_create
- src/vmm_mad/remotes/vcenter/poll
- src/vmm_mad/remotes/lxd/attach_nic
- src/vmm_mad/remotes/lxd/detach_nic
- src/vmm_mad/remotes/lxd/detach_disk

View File

@ -16,26 +16,24 @@
# 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__)
require 'vcenter_driver'
vm_ref = ARGV[0]
vm_ref = ARGV[0]
drv_action = OpenNebula::XMLElement.new
@ -59,8 +57,9 @@ 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)
STDERR.puts "#{message} #{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"
end
exit(-1)
ensure
vi_client.close_connection if vi_client

View File

@ -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__)
@ -59,8 +57,9 @@ 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)
STDERR.puts "#{message} #{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"
end
exit(-1)
ensure
vi_client.close_connection if vi_client

View File

@ -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,7 +36,6 @@ require 'vcenter_driver'
CONFIG = VCenterConf.new
vm_ref = ARGV[0]
host = ARGV[1]
vm_id = ARGV[-2]
drv_action = OpenNebula::XMLElement.new
@ -46,10 +43,6 @@ drv_action.initialize_xml(Base64.decode64(STDIN.read), 'VMM_DRIVER_ACTION_DATA')
host_id = drv_action['VM/HISTORY_RECORDS/HISTORY/HID']
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]
begin
retries ||= 0
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
@ -58,17 +51,12 @@ begin
vm.poweroff_hard
rescue StandardError => e
if (retries += 1) < CONFIG[:retries]
message = "Cancel VM #{vm_ref} failed due to "\
"\"#{e.message}\"\n#{e.backtrace.join("\n")} "\
"on the attempt \##{retries}\n#{e.backtrace.join("\n")}"
else
message = "Cancel VM #{vm_ref} failed due to "\
"\"#{e.message}\"\n#{e.backtrace.join("\n")} "\
"on the final attempt\n#{e.backtrace.join("\n")}"
end
message = "Cancel VM #{vm_ref} failed due to \"#{e.message}\""\
"on attempt \##{retries}"
OpenNebula.log_error(message)
STDERR.puts "#{message} #{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"
end
sleep CONFIG[:retry_interval].to_i
retry if retries < CONFIG[:retries]

View File

@ -16,25 +16,17 @@
# limitations under the License. #
# ---------------------------------------------------------------------------- #
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
ONE_LOCATION ||= ENV['ONE_LOCATION']
if !ONE_LOCATION
unless defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
end
GEMS_LOCATION = '/usr/share/one/gems' unless defined?(GEMS_LOCATION)
RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby'
GEMS_LOCATION ||= '/usr/share/one/gems'
else
unless defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
end
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__)
@ -84,14 +76,10 @@ begin
puts vm['_ref']
rescue StandardError => e
if (retries += 1) < CONFIG[:retries]
message = "Deploy of VM #{vm_id} on vCenter cluster #{cluster_name} " \
"with #{dfile} failed due to \"#{e.message}\"" \
"on the attempt \##{retries}."
else
message = "Deploy of VM #{vm_id} on vCenter cluster #{cluster_name} " \
"with #{dfile} failed due to \"#{e.message}\"" \
'on the final attempt.'
message = "Deploy of VM #{vm_id} on vCenter cluster #{cluster_name} " \
"with #{dfile} failed due to \"#{e.message}\"" \
"on attempt \##{retries}."
unless (retries += 1) < CONFIG[:retries]
if e.message.include?('ManagedObjectNotFound')
template_id = drv_action['TEMPLATE/TEMPLATE_ID'].to_i
@ -105,7 +93,7 @@ rescue StandardError => e
template_name = resource.name
message << "\nVerify inside vCenter cluster #{cluster_name} " \
"that the template #{template_name} currently " \
"that template #{template_name} currently " \
'exists and has not been deleted'
end
end

View File

@ -16,18 +16,14 @@
# 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)
end
if File.directory?(GEMS_LOCATION)
Gem.use_paths(GEMS_LOCATION)
RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby'
GEMS_LOCATION ||= ONE_LOCATION + '/share/gems'
end
$LOAD_PATH << RUBY_LIB_LOCATION
@ -46,14 +42,14 @@ host_id = drv_action['VM/HISTORY_RECORDS/HISTORY/HID']
begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref)
VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref)
rescue StandardError => e
message = "Detach DISK for VM #{vm_ref} on vCenter cluster " \
"#{vc_cluster_name} failed due to \"#{e.message}\"."
OpenNebula.log_error(message)
STDERR.puts "#{message} #{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"
end
exit(-1)
ensure
vi_client.close_connection if vi_client

View File

@ -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__)
@ -52,15 +50,16 @@ begin
# Extract nic from driver action
one_nic = one_item.retrieve_xmlelements("TEMPLATE/NIC[ATTACH='YES']").first
mac = one_nic["MAC"]
mac = one_nic['MAC']
vm.detach_nic(mac)
rescue StandardError => e
message = "Detach NIC for VM #{vm_ref} on vCenter cluster " \
"#{vc_cluster_name} failed due to \"#{e.message}\"."
OpenNebula.log_error(message)
STDERR.puts "#{message} #{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"
end
exit(-1)
ensure
vi_client.close_connection if vi_client

View File

@ -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'
GEMS_LOCATION = '/usr/share/one/gems' unless defined?(GEMS_LOCATION)
GEMS_LOCATION ||= '/usr/share/one/gems'
else
RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby'
GEMS_LOCATION = ONE_LOCATION + '/share/gems' unless defined?(GEMS_LOCATION)
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__)

View File

@ -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__)
@ -56,8 +54,9 @@ rescue StandardError => e
" on vCenter cluster #{vc_cluster_name} failed due to " \
"\"#{e.message}\"."
OpenNebula.log_error(message)
STDERR.puts "#{message} #{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"
end
exit(-1)
ensure
vi_client.close_connection if vi_client

View File

@ -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__)
@ -55,8 +53,9 @@ rescue StandardError => e
"#{vc_cluster_name} failed due to "\
"\"#{e.message}\"\n#{e.backtrace.join("\n")}"
OpenNebula.log_error(message)
STDERR.puts "#{message} #{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"
end
exit(-1)
ensure
vi_client.close_connection if vi_client

View File

@ -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__)
@ -42,7 +40,7 @@ vm_id = ARGV[-2]
drv_action = OpenNebula::XMLElement.new
drv_action.initialize_xml(Base64.decode64(STDIN.read), 'VMM_DRIVER_ACTION_DATA')
host_id = drv_action['VM/HISTORY_RECORDS/HISTORY[last()]/HID']
host_id = drv_action['VM/HISTORY_RECORDS/HISTORY[last()]/HID']
begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
@ -53,9 +51,10 @@ rescue StandardErrord => e
message = "Reconfiguration of VM #{vm_ref} on vCenter cluster "\
"#{vc_cluster_name} failed due to "\
"\"#{e.message}\"."
STDERR.puts error_message(message)
STDERR.puts "#{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
OpenNebula.log_error(message)
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"
end
exit(-1)
ensure
vi_client.close_connection if vi_client

View File

@ -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__)
@ -54,8 +52,9 @@ rescue StandardError => e
"#{vc_cluster_name} failed due to "\
"\"#{e.message}\"."
OpenNebula.log_error(message)
STDERR.puts "#{message} #{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"
end
exit(-1)
ensure
vi_client.close_connection if vi_client

View File

@ -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__)
@ -54,8 +52,9 @@ rescue StandardError => e
"#{vc_cluster_name} failed due to "\
"\"#{e.message}\"."
OpenNebula.log_error(message)
STDERR.puts "#{message} #{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"
end
exit(-1)
ensure
vi_client.close_connection if vi_client

View File

@ -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__)
@ -36,7 +34,6 @@ $LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
vm_ref = ARGV[0]
vm_id = ARGV[3]
vc_cluster_name = ARGV[-1]
drv_action_enc = STDIN.read.delete("\n")
@ -49,7 +46,7 @@ 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 !(%{'SAVE_SUSPEND', 'SAVE_STOP', 'SAVE_MIGRATE'}).include?(lcm_state_str)
if !%('SAVE_SUSPEND', 'SAVE_STOP', 'SAVE_MIGRATE').include?(lcm_state_str)
STDERR.puts "Wrong lcm state #{lcm_state_str} when saving VM"
exit(-1)
end
@ -65,8 +62,9 @@ rescue StandardError => e
"#{vc_cluster_name} failed due to "\
"\"#{e.message}\"\n#{e.backtrace.join("\n")}"
OpenNebula.log_error(message)
STDERR.puts "#{message} #{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"
end
exit(-1)
ensure
vi_client.close_connection if vi_client

View File

@ -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__)
@ -52,7 +50,8 @@ 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 !(%{'SAVE_MIGRATE', 'SHUTDOWN', 'SHUTDOWN_POWEROFF', 'SHUTDOWN_UNDEPLOY'}).include?(lcm_state_str)
if !%('SAVE_MIGRATE', 'SHUTDOWN', 'SHUTDOWN_POWEROFF', \
'SHUTDOWN_UNDEPLOY').include?(lcm_state_str)
STDERR.puts "Wrong lcm state #{lcm_state_str} when shutting down VM"
exit(-1)
end
@ -62,10 +61,14 @@ begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
if vm_ref.empty?
one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, vm_id)
host = OpenNebula::Host.new_with_id(host_id, OpenNebula::Client.new())
vcenter_vm = VCenterDriver::VIHelper.find_vcenter_vm_by_name(one_vm, host, vi_client)
raise "Could not find the undeployed VM in vCenter's inventory using it's name" if !vcenter_vm
one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine,
vm_id)
host = OpenNebula::Host.new_with_id(host_id, OpenNebula::Client.new)
vcenter_vm = VCenterDriver::VIHelper.find_vcenter_vm_by_name(one_vm,
host,
vi_client)
raise "Couldn't find the VM in vCenter by it's name" unless vcenter_vm
vm_ref = vcenter_vm._ref
end
@ -73,17 +76,12 @@ begin
vm.shutdown # Undeploy, Poweroff or Terminate
rescue StandardError => e
if (retries += 1) < CONFIG[:retries]
message = "Shutdown of VM #{vm_ref} on vCenter cluster "\
"#{vc_cluster_name} failed due to "\
"\"#{e.message}\" on the attempt \##{retries}\n#{e.backtrace.join("\n")}"
else
message = "Shutdown of VM #{vm_ref} on vCenter cluster "\
"#{vc_cluster_name} failed due to "\
"\"#{e.message}\" on the final attempt\n#{e.backtrace.join("\n")}"
end
message = "Shutdown of VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
"failed due to \"#{e.message}\" on attempt \##{retries}"
OpenNebula.log_error(message)
STDERR.puts "#{message} #{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"
end
sleep CONFIG[:retry_interval].to_i
retry if retries < CONFIG[:retries]

View File

@ -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__)
@ -52,9 +50,7 @@ begin
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]')
if !persistent_disks.empty?
unless one_vm.retrieve_xmlelements('TEMPLATE/DISK[PERSISTENT=YES]').empty?
STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
"#{vc_cluster_name} cannot be performed if "\
'it contains persistent disks.'
@ -62,14 +58,14 @@ begin
end
puts vm.create_snapshot(snap_id, snap_name)
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)
STDERR.puts "#{message} #{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"
end
exit(-1)
ensure
vi_client.close_connection if vi_client

View File

@ -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__)
@ -54,8 +52,9 @@ rescue StandardError => e
"#{vc_cluster_name} could not be deleted due to "\
"\"#{e.message}\"\n"
OpenNebula.log_error(message)
STDERR.puts "#{message} #{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"
end
exit(-1)
ensure
vi_client.close_connection if vi_client

View File

@ -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__)
@ -55,8 +53,9 @@ rescue StandardError => e
"#{vc_cluster_name} could not be reverted due "\
"to \"#{e.message}\"\n"
OpenNebula.log_error(message)
STDERR.puts "#{message} #{e.backtrace}" if VCenterDriver::CONFIG[:debug_information]
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"
end
exit(-1)
ensure
vi_client.close_connection if vi_client