2011-09-01 15:10:57 -07:00
|
|
|
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
|
|
|
|
|
2011-11-10 16:01:22 -08:00
|
|
|
# 'path' => '/Datacenters/vm/Jeff/Templates' will be MUCH faster.
|
|
|
|
# than simply listing everything.
|
|
|
|
def all(filters = {})
|
|
|
|
# REVISIT: I'm not sure if this is the best way to implement search
|
|
|
|
# filters on a collection but it does work. I need to study the AWS
|
|
|
|
# code more to make sure this matches up.
|
|
|
|
filters['folder'] ||= attributes['folder']
|
|
|
|
response = connection.list_virtual_machines(filters)
|
2011-09-10 13:27:52 -07:00
|
|
|
load(response['virtual_machines'])
|
2011-09-01 15:10:57 -07:00
|
|
|
end
|
|
|
|
|
2011-09-06 20:09:57 -07:00
|
|
|
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-/
|
2011-09-10 13:27:52 -07:00
|
|
|
response = connection.find_vm_by_ref('vm_ref' => id)
|
|
|
|
server_attributes = response['virtual_machine']
|
2011-09-06 20:09:57 -07:00
|
|
|
else
|
2011-09-10 13:27:52 -07:00
|
|
|
response = connection.list_virtual_machines('instance_uuid' => id)
|
|
|
|
server_attributes = response['virtual_machines'].first
|
2011-09-06 16:53:56 -07:00
|
|
|
end
|
2011-09-10 13:27:52 -07:00
|
|
|
new(server_attributes)
|
2011-09-01 15:10:57 -07:00
|
|
|
rescue Fog::Compute::Vsphere::NotFound
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|