1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[vsphere] adds support to get and set vnc console

This commit is contained in:
Ohad Levy 2012-03-28 12:34:36 +02:00 committed by Ohad Levy
parent 735a8822cc
commit 1497124853
4 changed files with 79 additions and 0 deletions

View file

@ -27,6 +27,7 @@ module Fog
request :vm_reconfig_hardware
request :vm_reconfig_memory
request :vm_reconfig_cpus
request :vm_config_vnc
module Shared

View file

@ -114,6 +114,18 @@ module Fog
tools_state != "toolsNotInstalled"
end
# defines VNC attributes on the hypervisor
def config_vnc(options = {})
requires :instance_uuid
connection.vm_config_vnc(options.merge('instance_uuid' => instance_uuid))
end
# returns a hash of VNC attributes required for connection
def vnc
requires :instance_uuid
connection.vm_get_vnc(instance_uuid)
end
def memory
memory_mb * 1024 * 1024
end

View file

@ -0,0 +1,47 @@
module Fog
module Compute
class Vsphere
class Real
def vm_config_vnc(options = { })
raise ArgumentError, "instance_uuid is a required parameter" unless options.has_key? 'instance_uuid'
search_filter = { :uuid => options['instance_uuid'], 'vmSearch' => true, 'instanceUuid' => true }
vm_mob_ref = @connection.searchIndex.FindAllByUuid(search_filter).first
task = vm_mob_ref.ReconfigVM_Task(:spec => {
:extraConfig => [
{ :key => 'RemoteDisplay.vnc.enabled', :value => options[:enabled] ? 'true' : 'false' },
{ :key => 'RemoteDisplay.vnc.password', :value => options[:password].to_s },
{ :key => 'RemoteDisplay.vnc.port', :value => options[:port].to_s || '5910' }
]
})
task.wait_for_completion
{ 'task_state' => task.info.state }
end
# return a hash of VNC attributes required to view the console
def vm_get_vnc uuid
search_filter = { :uuid => uuid, 'vmSearch' => true, 'instanceUuid' => true }
vm = @connection.searchIndex.FindAllByUuid(search_filter).first
Hash[vm.config.extraConfig.map do |config|
if config.key =~ /^RemoteDisplay\.vnc\.(\w+)$/
[$1.to_sym, config.value]
end
end.compact]
end
end
class Mock
def vm_config_vnc(options = { })
raise ArgumentError, "instance_uuid is a required parameter" unless options.has_key? 'instance_uuid'
{ 'task_state' => 'success' }
end
def vm_get_vnc uuid
{:password => 'secret', :port => '5900', :enabled => 'true'}
end
end
end
end
end

View file

@ -0,0 +1,19 @@
Shindo.tests('Fog::Compute[:vsphere] | vm_config_vnc request', ['vsphere']) do
compute = Fog::Compute[:vsphere]
reconfig_target = '50137835-88a1-436e-768e-9b2677076e67'
vnc_spec = {:port => '5900', :password => 'ssaaa', :enabled => 'true'}
tests('The response should') do
response = compute.vm_config_vnc('instance_uuid' => reconfig_target).merge(vnc_spec)
test('be a kind of Hash') { response.kind_of? Hash }
test('should have a task_state key') { response.has_key? 'task_state' }
end
tests('VNC attrs response should') do
response = compute.vm_get_vnc(reconfig_target)
test('be a kind of Hash') { response.kind_of? Hash }
test('should have a port key') { response.has_key? :port }
end
end