1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/vsphere/models/compute/servers.rb
Jeff McCune 8bc5c768ec (#9241) Add model for Fog::Compute[:vsphere].servers
This patch adds a request list_virtual_machines which is responsible for
making an API connection and returning a raw "response" object from the
API.

Model instances of a Server (compute resource) are returned as a
collection through the "all" method.  The Fog framework calls all on the
instance of the collection.
2011-09-10 13:32:58 -07:00

35 lines
839 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
# Virtual Machine Managed Objects (vm_mobs)
vm_mobs = connection.list_virtual_machines
vm_attributes = vm_mobs.collect do |vm_mob|
model.attribute_hash_from_mob(vm_mob)
end
load(vm_attributes)
end
def get(server_id)
raise NotImplementedError
# FIXME: (TODO) Make a raw API call
# Massage the data into an attribute hash
# Pass the attribute hash to new() to create a new instance of the model.
rescue Fog::Compute::Vsphere::NotFound
nil
end
end
end
end
end