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

(#9241) Don't fail when trying to model a cloning VM

With the introduction of the vm_clone API request, a server
may be returned in the list which does not have a complete
configuration yet.  This is because the system is still in
the process of being cloned.

This is a problem because Fog would throw an undefined
method error when calling the config method of the vm managed
object instance.

This patch fixes the problem by checking if the config method
returns something and only sets attributes that are known to be
available for a cloning VM.
This commit is contained in:
Jeff McCune 2011-09-06 16:49:28 -07:00
parent ef2833cb20
commit 27a689b951

View file

@ -32,25 +32,33 @@ module Fog
attribute :hypervisor, :aliases => 'host'
attribute :is_a_template
# Create an instance of the server model from a
# Return an attribute hash suitable for the initializer given a
# vSphere Managed Object (mob) instance.
def self.attribute_hash_from_mob(vm)
{
:id => vm.config.instanceUuid || vm._ref,
:name => vm.name,
:uuid => vm.config.uuid,
:instance_uuid => vm.config.instanceUuid,
:hostname => vm.summary.guest.hostName,
:operatingsystem => vm.summary.guest.guestFullName,
:ipaddress => vm.summary.guest.ipAddress,
:power_state => vm.runtime.powerState,
:connection_state => vm.runtime.connectionState,
:hypervisor => vm.runtime.host.name,
:tools_state => vm.summary.guest.toolsStatus,
:tools_version => vm.summary.guest.toolsVersionStatus,
:mac_addresses => vm.macs,
:is_a_template => vm.config.template
}
return {} unless vm
# A cloning VM doesn't have a configuration yet. Unfortuantely we just get
# a RunTime exception.
begin
is_ready = vm.config ? true : false
rescue RuntimeError
is_ready = nil
end
{
:id => is_ready ? vm.config.instanceUuid : vm._ref,
:name => vm.name,
:uuid => is_ready ? vm.config.uuid : 'unavailable',
:instance_uuid => is_ready ? vm.config.instanceUuid : 'unavailable',
:hostname => vm.summary.guest.hostName,
:operatingsystem => vm.summary.guest.guestFullName,
:ipaddress => vm.summary.guest.ipAddress,
:power_state => vm.runtime.powerState,
:connection_state => vm.runtime.connectionState,
:hypervisor => vm.runtime.host ? vm.runtime.host.name : 'unknown',
:tools_state => vm.summary.guest.toolsStatus,
:tools_version => vm.summary.guest.toolsVersionStatus,
:mac_addresses => is_ready ? vm.macs : nil,
:is_a_template => is_ready ? vm.config.template : nil
}
end
def start