2011-05-23 21:17:16 -04:00
|
|
|
require 'fog/compute/models/vcloud/server'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Vcloud
|
|
|
|
class Compute
|
|
|
|
|
|
|
|
class Servers < Fog::Vcloud::Collection
|
|
|
|
|
|
|
|
undef_method :create
|
|
|
|
|
|
|
|
model Fog::Vcloud::Compute::Server
|
|
|
|
|
|
|
|
attribute :href, :aliases => :Href
|
|
|
|
|
|
|
|
def all
|
|
|
|
check_href!(:parent => "Vdc")
|
|
|
|
load(_vapps)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(uri)
|
|
|
|
if data = connection.get_vapp(uri)
|
2011-05-30 23:24:15 -04:00
|
|
|
# If no tasks returned, set a mock entry to flush on reload
|
|
|
|
data.body[:Tasks] = {} unless data.body[:Tasks]
|
2011-05-23 21:17:16 -04:00
|
|
|
new(data.body)
|
|
|
|
end
|
|
|
|
rescue Fog::Errors::NotFound
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2011-06-09 00:53:41 -04:00
|
|
|
def create options
|
2011-05-30 01:17:53 -04:00
|
|
|
check_href!
|
2011-05-23 21:17:16 -04:00
|
|
|
options[:vdc_uri] = href
|
2011-06-09 00:53:41 -04:00
|
|
|
data = connection.instantiate_vapp_template(options).body
|
2011-05-23 21:17:16 -04:00
|
|
|
object = new(data)
|
|
|
|
object
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def _resource_entities
|
|
|
|
if Hash === resource_entities = connection.get_vdc(href).body[:ResourceEntities]
|
|
|
|
resource_entities[:ResourceEntity]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def _vapps
|
|
|
|
resource_entities = _resource_entities
|
|
|
|
if resource_entities.nil?
|
|
|
|
[]
|
|
|
|
else
|
2011-05-24 02:26:36 -04:00
|
|
|
resource_entities.select {|re| re[:type] == 'application/vnd.vmware.vcloud.vApp+xml' }
|
2011-05-23 21:17:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|