mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
8bc5c768ec
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.
35 lines
839 B
Ruby
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
|