2011-09-01 18:10:57 -04: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
|
2012-11-14 08:31:02 -05:00
|
|
|
attr_accessor :datacenter
|
|
|
|
attr_accessor :network
|
|
|
|
attr_accessor :cluster
|
|
|
|
attr_accessor :resource_pool
|
|
|
|
attr_accessor :folder
|
2011-09-01 18:10:57 -04:00
|
|
|
|
2012-11-14 08:31:02 -05:00
|
|
|
# 'folder' => '/Datacenters/vm/Jeff/Templates' will be MUCH faster.
|
2011-11-10 19:01:22 -05:00
|
|
|
# than simply listing everything.
|
2012-11-14 08:31:02 -05:00
|
|
|
def all(filters = { })
|
2012-12-22 18:21:53 -05:00
|
|
|
load service.list_virtual_machines(filters.merge(
|
2012-11-14 08:31:02 -05:00
|
|
|
:datacenter => datacenter,
|
|
|
|
:cluster => cluster,
|
|
|
|
:network => network,
|
|
|
|
:resource_pool => resource_pool,
|
|
|
|
:folder => folder
|
|
|
|
))
|
2011-09-01 18:10:57 -04:00
|
|
|
end
|
|
|
|
|
2012-11-14 08:31:02 -05:00
|
|
|
def get(id, datacenter = nil)
|
2012-12-22 18:21:53 -05:00
|
|
|
new service.get_virtual_machine id, datacenter
|
2011-09-01 18:10:57 -04:00
|
|
|
rescue Fog::Compute::Vsphere::NotFound
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|