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

Fix vm clone problem when a Guid instance is passed as the instance_uuid

Without this patch the vm_clone requiest would not find a Managed Object
Reference when a UUID that is not a string is passed as the
instance_uuid option.  This is a problem because an unhelpful "undefined
method `parent' for nil:NilClass" would be thrown to the application.

This patch throws a more helpful Fog::Compute::Vsphere::NotFound
exception if the Virtual Machine template is not found.

The tests have been updated to reflect this expectation.
This commit is contained in:
Jeff McCune 2011-09-14 10:15:19 -07:00
parent 91cd093cab
commit dd9e132de5
3 changed files with 11 additions and 1 deletions

View file

@ -25,9 +25,11 @@ module Fog
# Option handling
options = vm_clone_check_options(options)
notfound = lambda { raise Fog::Compute::Vsphere::NotFound, "Cloud not find VM template" }
# REVISIT: This will have horrible performance for large sites.
# Find the Managed Object reference of the template VM (Wish I could do this with the API)
vm_mob_ref = list_all_virtual_machine_mobs.find do |vm|
vm_mob_ref = list_all_virtual_machine_mobs.find(notfound) do |vm|
convert_vm_mob_ref_to_attr_hash(vm)['instance_uuid'] == options['instance_uuid']
end
@ -79,6 +81,10 @@ module Fog
def vm_clone(options = {})
# Option handling
options = vm_clone_check_options(options)
notfound = lambda { raise Fog::Compute::Vsphere::NotFound, "Cloud not find VM template" }
vm_mob_ref = list_virtual_machines['virtual_machines'].find(notfound) do |vm|
vm['instance_uuid'] == options['instance_uuid']
end
{
'vm_ref' => 'vm-123',
'task_ref' => 'task-1234'

View file

@ -1,4 +1,5 @@
Shindo.tests("Fog::Compute[:servers] | vm_clone request") do
require 'guid'
template = "50323f93-6835-1178-8b8f-9e2109890e1a"
compute = Fog::Compute[:vsphere]
@ -15,5 +16,8 @@ Shindo.tests("Fog::Compute[:servers] | vm_clone request") do
'it should raise ServiceError if a VM already exists with the provided name') do
compute.vm_clone('instance_uuid' => '123', 'name' => 'jefftest')
end
raises(Fog::Compute::Vsphere::NotFound, 'it should raise Fog::Compute::Vsphere::NotFound when the UUID is not a string') do
compute.vm_clone('instance_uuid' => Guid.from_s(template), 'name' => 'jefftestfoo')
end
end
end