1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[vcloud|compute] introduce vapps

This commit is contained in:
Peter Meier 2011-09-26 17:20:17 +02:00
parent 3024678e2a
commit f2c90dcc7f
5 changed files with 79 additions and 3 deletions

View file

@ -83,6 +83,8 @@ module Fog
collection :servers
model :task
collection :tasks
model :vapp
collection :vapps
model :vdc
collection :vdcs
model :organization
@ -300,7 +302,6 @@ module Fog
parser = Nokogiri::XML::SAX::PushParser.new(document)
parser << response.body
parser.finish
response.body = document.body
end
end

View file

@ -13,8 +13,14 @@ module Fog
attribute :href, :aliases => :Href
def all
check_href!(:parent => "Vdc")
load(_vapps)
if self.href =~ /\/vdc\//
check_href!("Vdc")
load(_vapps)
else
check_href!("Vapp")
attributes[:vapp].load_unless_loaded!
load(attributes[:vapp].children)
end
end
def get(uri)

View file

@ -0,0 +1,29 @@
module Fog
module Vcloud
class Compute
class Vapp < Fog::Vcloud::Model
identity :href
ignore_attributes :xmlns, :xmlns_xsi, :xmlns_xsd
attribute :name
attribute :type
attribute :status
attribute :description
attribute :deployed, :type => :boolean
attribute :children, :aliases => :Children, :squash => :Vm
attribute :lease_settings, :aliases => :LeaseSettingsSection
attribute :other_links, :aliases => :Link
def servers
@servers ||= Fog::Vcloud::Compute::Servers.
new( :connection => connection,
:href => href,
:vapp => self
)
end
end
end
end
end

View file

@ -0,0 +1,31 @@
require 'fog/vcloud/models/compute/vapp'
module Fog
module Vcloud
class Compute
class Vapps < Collection
model Fog::Vcloud::Compute::Vapp
undef_method :create
attribute :href
def all
data = connection.get_vdc(self.href).body[:ResourceEntities][:ResourceEntity].select { |re| re[:type] == "application/vnd.vmware.vcloud.vApp+xml" }
load(data)
end
def get(uri)
if data = connection.get_vapp(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -30,6 +30,13 @@ module Fog
:href => href )
end
def vapps
@vapps ||= Fog::Vcloud::Compute::Vapps.
new( :connection => connection,
:href => href
)
end
private
def collection_based_on_type(type, klass = nil)
@ -39,6 +46,8 @@ module Fog
case type
when "application/vnd.vmware.vcloud.catalog+xml"
Fog::Vcloud::Compute::Catalog
when "application/vnd.vmware.vcloud.vApp+xml"
Fog::Vcloud::Compute::Vapp
end.new( :connection => connection, :href => link[:href] )
else
[ ]