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/
37 lines
1,023 B
Ruby
37 lines
1,023 B
Ruby
require 'fog/core/collection'
|
|
require 'fog/vsphere/models/compute/server'
|
|
|
|
module Fog
|
|
module Compute
|
|
class Vsphere
|
|
|
|
class Servers < Fog::Collection
|
|
|
|
model Fog::Compute::Vsphere::Server
|
|
|
|
def all
|
|
response = connection.list_virtual_machines
|
|
load(response['virtual_machines'])
|
|
end
|
|
|
|
def get(id)
|
|
# Is the id a managed_object_reference? This may be the case if we're reloading
|
|
# a model of a VM in the process of being cloned, since it
|
|
# will not have a instance_uuid yet.
|
|
if id =~ /^vm-/
|
|
response = connection.find_vm_by_ref('vm_ref' => id)
|
|
server_attributes = response['virtual_machine']
|
|
else
|
|
response = connection.list_virtual_machines('instance_uuid' => id)
|
|
server_attributes = response['virtual_machines'].first
|
|
end
|
|
new(server_attributes)
|
|
rescue Fog::Compute::Vsphere::NotFound
|
|
nil
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|