mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
add host based vmotion
This commit is contained in:
parent
d7e3ee870a
commit
9fdbd35415
4 changed files with 61 additions and 0 deletions
|
@ -22,6 +22,7 @@ module Fog
|
|||
request :vm_clone
|
||||
request :vm_create
|
||||
request :vm_destroy
|
||||
request :vm_migrate
|
||||
request :datacenters
|
||||
request :vm_reconfig_hardware
|
||||
request :vm_reconfig_memory
|
||||
|
|
|
@ -68,6 +68,13 @@ module Fog
|
|||
requires :instance_uuid
|
||||
connection.vm_destroy('instance_uuid' => instance_uuid)
|
||||
end
|
||||
|
||||
def migrate(options = {})
|
||||
options = { :priority => 'defaultPriority' }.merge(options)
|
||||
requires :instance_uuid
|
||||
connection.vm_migrate('instance_uuid' => instance_uuid, 'priority' => options[:priority])
|
||||
end
|
||||
|
||||
def create(options ={})
|
||||
requires :name, :path
|
||||
new_vm = self.class.new(create_results['vm_attributes'])
|
||||
|
|
37
lib/fog/vsphere/requests/compute/vm_migrate.rb
Normal file
37
lib/fog/vsphere/requests/compute/vm_migrate.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Vsphere
|
||||
class Real
|
||||
|
||||
def vm_migrate(options = {})
|
||||
#priority is the only required option, and it has a sane default option.
|
||||
priority = options['priority'].nil? ? 'defaultPriority' : options["priority"]
|
||||
raise ArgumentError, "instance_uuid is a required parameter" unless options.has_key? 'instance_uuid'
|
||||
|
||||
# Find the VM Object
|
||||
search_filter = { :uuid => options['instance_uuid'], 'vmSearch' => true, 'instanceUuid' => true }
|
||||
vm_mob_ref = @connection.searchIndex.FindAllByUuid(search_filter).first
|
||||
|
||||
unless vm_mob_ref.kind_of? RbVmomi::VIM::VirtualMachine
|
||||
raise Fog::Vsphere::Errors::NotFound,
|
||||
"Could not find VirtualMachine with instance uuid #{options['instance_uuid']}"
|
||||
end
|
||||
task = vm_mob_ref.MigrateVM_Task(:pool => options['pool'], :host => options['host'], :priority => "#{priority}", :state => options['state'] )
|
||||
task.wait_for_completion
|
||||
{ 'task_state' => task.info.state }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def vm_migrate(options = {})
|
||||
priority = options['priority'].nil? ? 'defaultPriority' : options["priority"]
|
||||
raise ArgumentError, "instance_uuid is a required parameter" unless options.has_key? 'instance_uuid'
|
||||
{ 'task_state' => 'success' }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
16
tests/vsphere/requests/compute/vm_migrate_tests.rb
Normal file
16
tests/vsphere/requests/compute/vm_migrate_tests.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
Shindo.tests('Fog::Compute[:vsphere] | vm_migrate request', ['vsphere']) do
|
||||
|
||||
compute = Fog::Compute[:vsphere]
|
||||
|
||||
powered_on_vm = '50137835-88a1-436e-768e-9b2677076e67'
|
||||
|
||||
tests('The response should') do
|
||||
response = compute.vm_migrate('instance_uuid' => powered_on_vm)
|
||||
test('be a kind of Hash') { response.kind_of? Hash }
|
||||
test('should have a task_state key') { response.has_key? 'task_state' }
|
||||
end
|
||||
|
||||
tests('The expected options') do
|
||||
raises(ArgumentError, 'raises ArgumentError when instance_uuid option is missing') { compute.vm_migrate }
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue