diff --git a/lib/fog/vcloud/compute.rb b/lib/fog/vcloud/compute.rb index f251db213..6b8aba198 100644 --- a/lib/fog/vcloud/compute.rb +++ b/lib/fog/vcloud/compute.rb @@ -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 diff --git a/lib/fog/vcloud/models/compute/servers.rb b/lib/fog/vcloud/models/compute/servers.rb index 5031890c5..e2c6f5f63 100644 --- a/lib/fog/vcloud/models/compute/servers.rb +++ b/lib/fog/vcloud/models/compute/servers.rb @@ -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) diff --git a/lib/fog/vcloud/models/compute/vapp.rb b/lib/fog/vcloud/models/compute/vapp.rb new file mode 100644 index 000000000..ab696414e --- /dev/null +++ b/lib/fog/vcloud/models/compute/vapp.rb @@ -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 diff --git a/lib/fog/vcloud/models/compute/vapps.rb b/lib/fog/vcloud/models/compute/vapps.rb new file mode 100644 index 000000000..d4efaa69d --- /dev/null +++ b/lib/fog/vcloud/models/compute/vapps.rb @@ -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 diff --git a/lib/fog/vcloud/models/compute/vdc.rb b/lib/fog/vcloud/models/compute/vdc.rb index a334374c7..f3110e3a1 100644 --- a/lib/fog/vcloud/models/compute/vdc.rb +++ b/lib/fog/vcloud/models/compute/vdc.rb @@ -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 [ ]