2011-08-24 21:11:42 -04:00
|
|
|
require 'fog/vcloud/models/compute/server'
|
2011-05-23 21:17:16 -04:00
|
|
|
|
|
|
|
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
|
2011-09-26 11:20:17 -04:00
|
|
|
if self.href =~ /\/vdc\//
|
|
|
|
check_href!("Vdc")
|
|
|
|
load(_vapps)
|
|
|
|
else
|
|
|
|
check_href!("Vapp")
|
|
|
|
attributes[:vapp].load_unless_loaded!
|
2011-09-28 08:21:43 -04:00
|
|
|
load(attributes[:vapp].children||[])
|
2011-09-26 11:20:17 -04:00
|
|
|
end
|
2011-05-23 21:17:16 -04:00
|
|
|
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
|