mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
743882f032
This massive commit refactors all of the request methods on the Fog::Compute[:vsphere] instance to return simple hashes. The behavior before this commit returned full vmware object references which was a problem because it was difficult to unit test. With this patch, it is much easier to add and maintain Mock implementations of the request methods. This makes adding behavior tests for the server model much easier. In addition, test coverage using Shindo has been added. Previously there was little test coverage of the behavior. To run the tests: shindont tests/vsphere/
41 lines
1.4 KiB
Ruby
41 lines
1.4 KiB
Ruby
module Fog
|
|
module Compute
|
|
class Vsphere
|
|
|
|
module Shared
|
|
|
|
# REVISIT: This is a naive implementation and not very efficient since
|
|
# we find ALL VM's and then iterate over them looking for the managed object
|
|
# reference id... There should be an easier way to obtain a reference to a
|
|
# VM using only the name or the _ref. This request is primarily intended to
|
|
# reload the attributes of a cloning VM which does not yet have an instance_uuid
|
|
def find_vm_by_ref(options = {})
|
|
raise ArgumentError, "Must pass a vm_ref option" unless options['vm_ref']
|
|
|
|
# This is the inefficient call
|
|
all_vm_attributes = list_virtual_machines['virtual_machines']
|
|
# Find the VM attributes of the reference
|
|
if vm_attributes = all_vm_attributes.find { |vm| vm['mo_ref'] == options['vm_ref'] }
|
|
response = { 'virtual_machine' => vm_attributes }
|
|
else
|
|
raise Fog::Compute::Vsphere::NotFound, "VirtualMachine with Managed Object Reference #{options['vm_ref']} could not be found."
|
|
end
|
|
response
|
|
end
|
|
|
|
end
|
|
|
|
# The Real and Mock classes share the same method
|
|
# because list_virtual_machines will be properly mocked for us
|
|
|
|
class Real
|
|
include Shared
|
|
end
|
|
|
|
class Mock
|
|
include Shared
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|