mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
vCenter driver ruby linting with new rubocop rules
This commit is contained in:
parent
8a34b06b93
commit
9a0a840e4a
@ -18,7 +18,9 @@ require 'set'
|
||||
require 'digest'
|
||||
|
||||
module VCenterDriver
|
||||
|
||||
class DatacenterFolder
|
||||
|
||||
attr_accessor :items
|
||||
|
||||
def initialize(vi_client)
|
||||
@ -32,7 +34,7 @@ class DatacenterFolder
|
||||
# { dc_ref [Symbol] => Datacenter object }
|
||||
########################################################################
|
||||
def fetch!
|
||||
VIClient.get_entities(@vi_client.vim.root, "Datacenter").each do |item|
|
||||
VIClient.get_entities(@vi_client.vim.root, 'Datacenter').each do |item|
|
||||
item_name = item._ref
|
||||
@items[item_name.to_sym] = Datacenter.new(item)
|
||||
end
|
||||
|
@ -171,8 +171,6 @@ class Network
|
||||
template += "VCENTER_FROM_WILD=\"#{template_id}\"\n"
|
||||
end
|
||||
|
||||
#template += "VCENTER_CCR_REF=\"#{ccr_ref}\"\n" if !unmanaged
|
||||
|
||||
template += "VCENTER_TEMPLATE_REF=\"#{template_ref}\"\n" if template_ref
|
||||
|
||||
return template
|
||||
@ -389,9 +387,5 @@ class NetImporter < VCenterDriver::VcImporter
|
||||
|
||||
return res
|
||||
end
|
||||
|
||||
def attr
|
||||
"TEMPLATE/VCENTER_NET_REF"
|
||||
end
|
||||
end
|
||||
end # module VCenterDriver
|
||||
|
@ -42,10 +42,6 @@ module VCenterDriver
|
||||
end
|
||||
end
|
||||
|
||||
def attr
|
||||
false
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# ABSTRACT INTERFACE
|
||||
#######################################################################
|
||||
@ -304,12 +300,6 @@ module VCenterDriver
|
||||
id = resource['ID']
|
||||
@rollback << Raction.new(resource, :delete)
|
||||
rc = block.call(resource, id)
|
||||
|
||||
# update vCenter cache (future work)
|
||||
#if attr
|
||||
# VCenterDriver::VIHelper.add_ref_hash(attr, resource)
|
||||
# @rollback << Raction.new(VCenterDriver::VIHelper, :remove_ref_hash, [attr, resource])
|
||||
#end
|
||||
end
|
||||
|
||||
#
|
||||
|
@ -33,10 +33,12 @@ vm_ref = ARGV[0]
|
||||
drv_action_enc = ARGV[4]
|
||||
|
||||
drv_action = OpenNebula::XMLElement.new
|
||||
drv_action.initialize_xml(Base64.decode64(drv_action_enc), 'VMM_DRIVER_ACTION_DATA')
|
||||
drv_action.initialize_xml(Base64.decode64(drv_action_enc),
|
||||
'VMM_DRIVER_ACTION_DATA')
|
||||
|
||||
vc_cluster_name = drv_action['/VMM_DRIVER_ACTION_DATA/HOST']
|
||||
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
|
||||
@ -48,8 +50,8 @@ begin
|
||||
vm = VCenterDriver::VirtualMachine.new_one(vi_client, vm_ref, one_item)
|
||||
vm.attach_disk
|
||||
rescue StandardError => e
|
||||
message = "Attach image for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
|
||||
"failed due to \"#{e.message}\"\n"
|
||||
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)
|
||||
ensure
|
||||
|
@ -35,7 +35,8 @@ vc_cluster_name = ARGV[-1]
|
||||
drv_action = OpenNebula::XMLElement.new
|
||||
drv_action.initialize_xml(Base64.decode64(STDIN.read), 'VMM_DRIVER_ACTION_DATA')
|
||||
|
||||
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
|
||||
@ -48,8 +49,8 @@ begin
|
||||
|
||||
vm.attach_nic
|
||||
rescue StandardError => e
|
||||
message = "Attach NIC for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
|
||||
"failed due to \"#{e.message}\"\n"
|
||||
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)
|
||||
ensure
|
||||
|
@ -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,24 +46,25 @@ 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
|
||||
vm = VCenterDriver::VirtualMachine.new_one(vi_client, deploy_id, one_vm)
|
||||
else
|
||||
vc_template_ref = drv_action['USER_TEMPLATE/VCENTER_TEMPLATE_REF']
|
||||
# VM is new
|
||||
# Clone the VM from template and provide XML info
|
||||
vm = VCenterDriver::VirtualMachine.new_from_clone(vi_client, drv_action, vm_id)
|
||||
# VM is new, clone the VM from template
|
||||
vm = VCenterDriver::VirtualMachine.new_from_clone(vi_client,
|
||||
drv_action,
|
||||
vm_id)
|
||||
# Set reference to template disks and nics in VM template for detach ops
|
||||
vm.reference_unmanaged_devices(vc_template_ref)
|
||||
end
|
||||
|
||||
# Resize unmanaged disks
|
||||
vm.resize_unmanaged_disks
|
||||
|
||||
# Synchronize the OpenNebula VM representation with vCenter VM
|
||||
vm.reconfigure
|
||||
vm.poweron
|
||||
vm.set_running(true)
|
||||
@ -73,7 +74,7 @@ begin
|
||||
puts vm['_ref']
|
||||
rescue StandardError => e
|
||||
message = "Deploy of VM #{vm_id} on vCenter cluster #{cluster_name} " \
|
||||
"with #{dfile} failed due to \"#{e.message}\"\n#{e.backtrace}"
|
||||
"with #{dfile} failed due to \"#{e.message}\"."
|
||||
OpenNebula.log_error(message)
|
||||
exit(-1)
|
||||
ensure
|
||||
|
@ -35,7 +35,8 @@ vc_cluster_name = ARGV[-1]
|
||||
drv_action = OpenNebula::XMLElement.new
|
||||
drv_action.initialize_xml(Base64.decode64(STDIN.read), 'VMM_DRIVER_ACTION_DATA')
|
||||
|
||||
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
|
||||
@ -44,12 +45,12 @@ begin
|
||||
vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref)
|
||||
|
||||
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.'
|
||||
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")}"
|
||||
message = "Detach DISK for VM #{vm_ref} on vCenter cluster " \
|
||||
"#{vc_cluster_name} failed due to \"#{e.message}\"."
|
||||
OpenNebula.log_error(message)
|
||||
exit(-1)
|
||||
ensure
|
||||
|
@ -35,7 +35,8 @@ vc_cluster_name = ARGV[3]
|
||||
drv_action = OpenNebula::XMLElement.new
|
||||
drv_action.initialize_xml(Base64.decode64(STDIN.read), 'VMM_DRIVER_ACTION_DATA')
|
||||
|
||||
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
|
||||
@ -47,8 +48,8 @@ begin
|
||||
|
||||
vm.detach_nic
|
||||
rescue StandardError => e
|
||||
message = "Detach NIC for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
|
||||
"failed due to \"#{e.message}\"\n"
|
||||
message = "Detach NIC for VM #{vm_ref} on vCenter cluster " \
|
||||
"#{vc_cluster_name} failed due to \"#{e.message}\"."
|
||||
OpenNebula.log_error(message)
|
||||
exit(-1)
|
||||
ensure
|
||||
|
@ -34,11 +34,13 @@ src_host = ARGV[-3]
|
||||
dst_host = ARGV[-4]
|
||||
|
||||
begin
|
||||
VCenterDriver::VirtualMachine.migrate_routine(vm_id, src_host, dst_host)
|
||||
VCenterDriver::VirtualMachine.migrate_routine(vm_id,
|
||||
src_host,
|
||||
dst_host)
|
||||
rescue StandardError => e
|
||||
message = "Cannot migrate for VM #{vm_id}"\
|
||||
'failed due to '\
|
||||
"\"#{e.message}\"\n"
|
||||
"\"#{e.message}\"."
|
||||
OpenNebula.log_error(message)
|
||||
exit(-1)
|
||||
end
|
||||
|
@ -33,7 +33,8 @@ 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
|
||||
@ -44,9 +45,9 @@ begin
|
||||
|
||||
puts vm.info
|
||||
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")}"
|
||||
message = "Cannot poll info for VM #{vm_ref} with OpenNebula id #{vm_id}" \
|
||||
" on vCenter cluster #{vc_cluster_name} failed due to " \
|
||||
"\"#{e.message}\"."
|
||||
OpenNebula.log_error(message)
|
||||
exit(-1)
|
||||
ensure
|
||||
|
@ -32,7 +32,8 @@ require 'vcenter_driver'
|
||||
vm_ref = ARGV[0]
|
||||
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
|
||||
|
@ -36,7 +36,8 @@ 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
|
||||
@ -47,7 +48,7 @@ begin
|
||||
rescue StandardErrord => e
|
||||
message = "Reconfiguration of VM #{vm_ref} on vCenter cluster "\
|
||||
"#{vc_cluster_name} failed due to "\
|
||||
"\"#{e.message}\"\n#{e.backtrace}"
|
||||
"\"#{e.message}\"."
|
||||
STDERR.puts error_message(message)
|
||||
exit(-1)
|
||||
ensure
|
||||
|
@ -32,7 +32,8 @@ require 'vcenter_driver'
|
||||
vm_ref = ARGV[0]
|
||||
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
|
||||
@ -43,7 +44,7 @@ begin
|
||||
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")}"
|
||||
"\"#{e.message}\"."
|
||||
OpenNebula.log_error(message)
|
||||
exit(-1)
|
||||
ensure
|
||||
|
@ -32,7 +32,8 @@ 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
|
||||
@ -44,7 +45,7 @@ begin
|
||||
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")}"
|
||||
"\"#{e.message}\"."
|
||||
OpenNebula.log_error(message)
|
||||
exit(-1)
|
||||
ensure
|
||||
|
Loading…
x
Reference in New Issue
Block a user