mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-23 13:15:14 +09:00
F #4913: Add explicit VIM close connection to avoid idle vcenter sessions
This commit is contained in:
1 parent
3220c468bc
commit
4b7f700d75
28 files changed
+47
-2
No files matched your search
@@ -75,6 +75,8 @@ begin
|
||||
target_ds_name = target_ds['name']
|
||||
|
||||
puts ds.copy_virtual_disk(src_path, target_ds_name, target_path)
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Error cloning img #{src_path}."\
|
||||
" Reason: \"#{e.message}\"\n#{e.backtrace}"
|
||||
|
||||
@@ -77,9 +77,12 @@ end
|
||||
|
||||
begin
|
||||
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
|
||||
|
||||
ds = VCenterDriver::Datastore.new_from_ref(ds_ref, vi_client)
|
||||
|
||||
puts ds.create_virtual_disk(img_name, size, adapter_type, disk_type)
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Error creating virtual disk #{img_src}."\
|
||||
" Reason: \"#{e.message}\"\n#{e.backtrace}"
|
||||
|
||||
@@ -51,3 +51,5 @@ vi_client = VCenterDriver::VIClient.new_from_host(host_id)
|
||||
ds = VCenterDriver::Datastore.new_from_ref(ds_ref, vi_client)
|
||||
|
||||
puts ds.monitor
|
||||
|
||||
vi_client.close_connection
|
||||
@@ -61,10 +61,12 @@ check_valid img_src, "img_src"
|
||||
|
||||
begin
|
||||
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
|
||||
|
||||
ds = VCenterDriver::Datastore.new_from_ref(ds_ref, vi_client)
|
||||
|
||||
ds.delete_virtual_disk(img_src)
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Error deleting virtual disk #{img_src}."\
|
||||
" Reason: \"#{e.message}\"\n#{e.backtrace}"
|
||||
|
||||
@@ -62,10 +62,12 @@ check_valid img_path, "img_path"
|
||||
if img_path.start_with? "vcenter://"
|
||||
begin
|
||||
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
|
||||
|
||||
ds = VCenterDriver::Datastore.new_from_ref(ds_ref, vi_client)
|
||||
|
||||
ds.stat(img_path)
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Error calculating image #{img_path} size."\
|
||||
" Reason: \"#{e.message}\"\n#{e.backtrace}"
|
||||
|
||||
@@ -90,6 +90,8 @@ begin
|
||||
ds.download_to_stdout(img_src)
|
||||
end
|
||||
end
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Cannot download image #{u.path} from datastore #{ds_name} "\
|
||||
"on #{hostname}. Reason: \"#{e.message}\"\n#{e.backtrace}"
|
||||
|
||||
@@ -48,6 +48,8 @@ begin
|
||||
end
|
||||
|
||||
puts target_path
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Cannot upload image to datastore #{ds_name} "\
|
||||
"Reason: \"#{e.message}\"\n#{e.backtrace}"
|
||||
|
||||
@@ -66,3 +66,5 @@ dc = cluster.get_dc
|
||||
ds_folder = dc.datastore_folder
|
||||
ds_folder.fetch!
|
||||
puts ds_folder.monitor
|
||||
|
||||
vi_client.close_connection
|
||||
@@ -97,6 +97,8 @@ begin
|
||||
target_ds_name_vc = target_ds_vc['name']
|
||||
|
||||
source_ds_vc.copy_virtual_disk(src_path, target_ds_name_vc, target_path)
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Error clone virtual disk #{src_path} in "\
|
||||
"datastore #{target_ds_ref}. "\
|
||||
|
||||
@@ -94,6 +94,8 @@ begin
|
||||
|
||||
source_ds_vc.copy_virtual_disk(src_path, source_ds,
|
||||
target_path, target_ds_name_vc)
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Error copying img #{src_path}. "\
|
||||
"Reason: #{e.message}\n#{e.backtrace}"
|
||||
|
||||
@@ -89,6 +89,7 @@ begin
|
||||
|
||||
ds_vc.create_virtual_disk(img_name, size, adapter_type, disk_type)
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Error creating virtual disk in #{ds_vc['name']}."\
|
||||
" Reason: #{e.message}\n#{e.backtrace}"
|
||||
|
||||
@@ -18,6 +18,10 @@ class VIClient
|
||||
!!@rp
|
||||
end
|
||||
|
||||
def close_connection
|
||||
@vim.close
|
||||
end
|
||||
|
||||
# @return RbVmomi::VIM::<type> objects
|
||||
def self.get_entities(folder, type, entities=[])
|
||||
if folder == []
|
||||
|
||||
@@ -48,6 +48,7 @@ begin
|
||||
|
||||
vm.attach_disk
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Attach image for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
|
||||
"failed due to \"#{e.message}\"\n#{e.backtrace}"
|
||||
|
||||
@@ -59,6 +59,7 @@ begin
|
||||
|
||||
vm.attach_nic(nic)
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Attach NIC for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
|
||||
"failed due to \"#{e.message}\"\n#{e.backtrace}"
|
||||
|
||||
@@ -47,6 +47,8 @@ begin
|
||||
vm.one_item = drv_action.retrieve_xmlelements('VM').first
|
||||
|
||||
vm.poweroff_hard
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Cancel VM #{vm_ref} failed due to "\
|
||||
"\"#{e.message}\"\n#{e.backtrace}"
|
||||
|
||||
@@ -39,9 +39,9 @@ drv_action.initialize_xml(Base64.decode64(STDIN.read), 'VM')
|
||||
deploy_id = drv_action["DEPLOY_ID"]
|
||||
host_id = drv_action["HISTORY_RECORDS/HISTORY/HID"]
|
||||
|
||||
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
|
||||
|
||||
begin
|
||||
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
|
||||
|
||||
if deploy_id && !deploy_id.empty?
|
||||
# VM is not new, we just need to reconfigure it and to power it on
|
||||
vm = VCenterDriver::VirtualMachine.new_from_ref(deploy_id, vi_client)
|
||||
@@ -62,6 +62,8 @@ begin
|
||||
vm.set_running(true)
|
||||
|
||||
puts vm['_ref']
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Deploy of VM #{vm_id} on vCenter cluster #{cluster_name} " +
|
||||
"with #{dfile} failed due to \"#{e.message}\"\n#{e.backtrace}"
|
||||
|
||||
@@ -53,6 +53,7 @@ begin
|
||||
|
||||
vm.detach_disk(disks.first)
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Detach image for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
|
||||
"failed due to \"#{e.message}\"\n#{e.backtrace}"
|
||||
|
||||
@@ -45,6 +45,7 @@ begin
|
||||
|
||||
vm.detach_nic(nic)
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Detach NIC for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\
|
||||
"failed due to \"#{e.message}\"\n#{e.backtrace}"
|
||||
|
||||
@@ -45,6 +45,7 @@ begin
|
||||
|
||||
puts vm.info
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Cannot poll info for VM #{vm_ref} on vCenter cluster "\
|
||||
"#{vc_cluster_name} failed due to "\
|
||||
|
||||
@@ -42,6 +42,7 @@ begin
|
||||
|
||||
vm.reboot
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Guest reboot of VM #{vm_ref} on vCenter cluster "\
|
||||
"#{vc_cluster_name} failed due to "\
|
||||
|
||||
@@ -42,6 +42,7 @@ begin
|
||||
|
||||
vm.regenerate_context
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Reconfiguration of VM #{vm_ref} on vCenter cluster "\
|
||||
"#{vc_cluster_name} failed due to "\
|
||||
|
||||
@@ -42,6 +42,7 @@ begin
|
||||
|
||||
vm.reset
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Reset of VM #{vm_ref} on vCenter cluster "\
|
||||
"#{vc_cluster_name} failed due to "\
|
||||
|
||||
@@ -42,6 +42,7 @@ begin
|
||||
|
||||
vm.poweron
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Restore of VM #{vm_ref} on vCenter cluster "\
|
||||
"#{vc_cluster_name} failed due to "\
|
||||
|
||||
@@ -73,6 +73,7 @@ begin
|
||||
|
||||
vm.suspend
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Save of VM #{vm_ref} on vCenter cluster "\
|
||||
"#{vc_cluster_name} failed due to "\
|
||||
|
||||
@@ -110,6 +110,8 @@ begin
|
||||
end
|
||||
end
|
||||
|
||||
vi_client.close_connection
|
||||
|
||||
rescue Exception => e
|
||||
STDERR.puts "Shutdown of VM #{vm_ref} on vCenter cluster "\
|
||||
"#{vc_cluster_name} failed due to "\
|
||||
|
||||
@@ -48,6 +48,7 @@ begin
|
||||
|
||||
vm.create_snapshot(snap_id, snap_name)
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
|
||||
"#{vc_cluster_name} failed due to "\
|
||||
|
||||
@@ -43,6 +43,7 @@ begin
|
||||
|
||||
vm.delete_snapshot(snap_id)
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
|
||||
"#{vc_cluster_name} could not be deleted due to "\
|
||||
|
||||
@@ -43,6 +43,7 @@ begin
|
||||
|
||||
vm.revert_snapshot(snap_id)
|
||||
|
||||
vi_client.close_connection
|
||||
rescue Exception => e
|
||||
STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
|
||||
"#{vc_cluster_name} could not be reverted due "\
|
||||
|
||||
Reference in new issue
Block a user