mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
parent
fa1d39f69d
commit
ebb242a6ef
@ -520,59 +520,4 @@ class OneVcenterHelper < OpenNebulaHelper::OneHelper
|
||||
opts
|
||||
end
|
||||
|
||||
def clear_tags(vmid)
|
||||
client = Client.new
|
||||
|
||||
vm_pool = VirtualMachinePool.new(client, -1)
|
||||
host_pool = HostPool.new(client)
|
||||
deploy_id = -1
|
||||
host_id = -1
|
||||
hostname = ''
|
||||
|
||||
rc = vm_pool.info
|
||||
raise rc.message if OpenNebula.is_error?(rc)
|
||||
|
||||
rc = host_pool.info
|
||||
raise rc.message if OpenNebula.is_error?(rc)
|
||||
|
||||
vm_pool.each do |vm|
|
||||
next if vm.id.to_s != vmid
|
||||
|
||||
deploy_id = vm.deploy_id
|
||||
vm_history = vm.to_hash['VM']['HISTORY_RECORDS']['HISTORY']
|
||||
hostname = vm_history['HOSTNAME']
|
||||
break
|
||||
end
|
||||
|
||||
host_pool.each do |host|
|
||||
if host.name == hostname
|
||||
host_id = host.id
|
||||
end
|
||||
end
|
||||
|
||||
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
|
||||
vm = VCenterDriver::VirtualMachine
|
||||
.new(vi_client, deploy_id, vmid)
|
||||
|
||||
keys_to_remove = []
|
||||
vm['config.extraConfig'].each do |extraconfig|
|
||||
next unless extraconfig.key.include?('opennebula.disk') ||
|
||||
extraconfig.key.include?('opennebula.vm') ||
|
||||
extraconfig.key.downcase.include?('remotedisplay')
|
||||
|
||||
keys_to_remove << extraconfig.key
|
||||
end
|
||||
|
||||
[vm, keys_to_remove]
|
||||
end
|
||||
|
||||
def remove_keys(vm, keys_to_remove)
|
||||
spec_hash = keys_to_remove.map {|key| { :key => key, :value => '' } }
|
||||
|
||||
spec = RbVmomi::VIM.VirtualMachineConfigSpec(
|
||||
:extraConfig => spec_hash
|
||||
)
|
||||
vm.item.ReconfigVM_Task(:spec => spec).wait_for_completion
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -409,7 +409,42 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
begin
|
||||
print '.'
|
||||
vm, keys = helper.clear_tags(vmid)
|
||||
|
||||
client = Client.new
|
||||
|
||||
vm_pool = VirtualMachinePool.new(client, -1)
|
||||
host_pool = HostPool.new(client)
|
||||
deploy_id = -1
|
||||
host_id = -1
|
||||
hostname = ''
|
||||
|
||||
rc = vm_pool.info
|
||||
raise rc.message if OpenNebula.is_error?(rc)
|
||||
|
||||
rc = host_pool.info
|
||||
raise rc.message if OpenNebula.is_error?(rc)
|
||||
|
||||
vm_pool.each do |vm|
|
||||
next if vm.id.to_s != vmid
|
||||
|
||||
deploy_id = vm.deploy_id
|
||||
vm_history = vm.to_hash['VM']['HISTORY_RECORDS']['HISTORY']
|
||||
hostname = vm_history['HOSTNAME']
|
||||
break
|
||||
end
|
||||
|
||||
host_pool.each do |host|
|
||||
if host.name == hostname
|
||||
host_id = host.id
|
||||
end
|
||||
end
|
||||
|
||||
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
|
||||
vm = VCenterDriver::VirtualMachine
|
||||
.new(vi_client, deploy_id, vmid)
|
||||
|
||||
keys = vm.extra_config_keys
|
||||
|
||||
print '.'
|
||||
|
||||
if keys.empty?
|
||||
@ -422,7 +457,7 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
puts 'The following keys will be removed:'
|
||||
keys.each {|key| puts "\t- #{key}" }
|
||||
|
||||
helper.remove_keys(vm, keys)
|
||||
vm.clear_tags
|
||||
rescue StandardError => e
|
||||
STDERR.puts "Couldn't clear VM tags. Reason: #{e.message}"
|
||||
exit 1
|
||||
|
@ -1695,6 +1695,34 @@ end
|
||||
info_nics
|
||||
end
|
||||
|
||||
# Clear extraconfig tags from a vCenter VM
|
||||
#
|
||||
def clear_tags
|
||||
keys_to_remove = extra_config_keys
|
||||
|
||||
spec_hash =
|
||||
keys_to_remove.map {|key| { :key => key, :value => '' } }
|
||||
|
||||
spec = RbVmomi::VIM.VirtualMachineConfigSpec(
|
||||
:extraConfig => spec_hash
|
||||
)
|
||||
@item.ReconfigVM_Task(:spec => spec).wait_for_completion
|
||||
end
|
||||
|
||||
# Get extraconfig tags from a vCenter VM
|
||||
#
|
||||
def extra_config_keys
|
||||
keys_to_remove = []
|
||||
@item['config.extraConfig'].each do |extraconfig|
|
||||
next unless extraconfig.key.include?('opennebula.disk') ||
|
||||
extraconfig.key.include?('opennebula.vm') ||
|
||||
extraconfig.key.downcase.include?('remotedisplay')
|
||||
|
||||
keys_to_remove << extraconfig.key
|
||||
end
|
||||
keys_to_remove
|
||||
end
|
||||
|
||||
# Get required parameters to use VMware HTML Console SDK
|
||||
# To be used with the following SDK:
|
||||
# https://code.vmware.com/web/sdk/2.1.0/html-console
|
||||
|
@ -47,6 +47,36 @@ module VCenterDriver
|
||||
vm = selected[:one_item] || build
|
||||
template = selected[:template] || import_tmplt
|
||||
template = "DEPLOY_ID = #{vm_ref}\n" + template
|
||||
|
||||
# Index where start GRAPHICS block
|
||||
graphics_index = template.index('GRAPHICS = [')
|
||||
unless graphics_index.nil?
|
||||
# Index where finish GRAPHICS block
|
||||
end_of_graphics = template[graphics_index..-1].index(']') + 1
|
||||
|
||||
# GRAPHICS block
|
||||
graphics_sub_string =
|
||||
template[graphics_index, end_of_graphics]
|
||||
|
||||
# GRAPHICS block with PORT removed
|
||||
# OpenNebula will asing a new not used PORT
|
||||
graphics_sub_string =
|
||||
graphics_sub_string.gsub(/PORT(.*?),[\r\n]/, '')
|
||||
|
||||
# Index where graphics block finish
|
||||
before_graphics = template[0, graphics_index]
|
||||
|
||||
# Block after graphics block
|
||||
after_graphics =
|
||||
template[graphics_index..-1][end_of_graphics..-1]
|
||||
|
||||
# Template with out PORT inside GRAPHICS
|
||||
template =
|
||||
before_graphics +
|
||||
graphics_sub_string +
|
||||
after_graphics
|
||||
end
|
||||
|
||||
host_id = selected[:host] || @list.keys[0]
|
||||
|
||||
vc_uuid = @vi_client.vim.serviceContent.about.instanceUuid
|
||||
@ -56,6 +86,9 @@ module VCenterDriver
|
||||
vc_vm = VCenterDriver::VirtualMachine.new_without_id(@vi_client,
|
||||
vm_ref)
|
||||
|
||||
# clear OpenNebula attributes
|
||||
vc_vm.clear_tags
|
||||
|
||||
# Importing Wild VMs with snapshots is not supported
|
||||
# https://github.com/OpenNebula/one/issues/1268
|
||||
if vc_vm.snapshots? && vc_vm.disk_keys.empty?
|
||||
|
Loading…
x
Reference in New Issue
Block a user