diff --git a/lib/fog/vcloud_director/compute.rb b/lib/fog/vcloud_director/compute.rb index c1c57f29a..3c0070b51 100644 --- a/lib/fog/vcloud_director/compute.rb +++ b/lib/fog/vcloud_director/compute.rb @@ -98,7 +98,9 @@ module Fog request :get_task_list request :get_vapp request :get_vapp_metadata + request :get_vapp_ovf_descriptor request :get_vapp_template + request :get_vapp_template_ovf_descriptor request :get_vdc request :get_vm request :get_vm_customization diff --git a/lib/fog/vcloud_director/requests/compute/get_vapp_ovf_descriptor.rb b/lib/fog/vcloud_director/requests/compute/get_vapp_ovf_descriptor.rb new file mode 100644 index 000000000..2214b5ed6 --- /dev/null +++ b/lib/fog/vcloud_director/requests/compute/get_vapp_ovf_descriptor.rb @@ -0,0 +1,24 @@ +module Fog + module Compute + class VcloudDirector + class Real + # Retrieve the OVF descriptor of a vApp directly. + # + # @param [String] id Object identifier of the vApp. + # @return [Excon::Response] + # * body<~String> - + # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-VAppOvfDescriptor.html + # vCloud API Documentation + # @since vCloud API version 5.1 + def get_vapp_ovf_descriptor(id) + request( + :expects => 200, + :idempotent => true, + :method => 'GET', + :path => "vApp/#{id}/ovf" + ) + end + end + end + end +end diff --git a/lib/fog/vcloud_director/requests/compute/get_vapp_template_ovf_descriptor.rb b/lib/fog/vcloud_director/requests/compute/get_vapp_template_ovf_descriptor.rb new file mode 100644 index 000000000..09846fd94 --- /dev/null +++ b/lib/fog/vcloud_director/requests/compute/get_vapp_template_ovf_descriptor.rb @@ -0,0 +1,24 @@ +module Fog + module Compute + class VcloudDirector + class Real + # Retrieve the OVF descriptor of a vApp template. + # + # @param [String] id Object identifier of the vAppTemplate. + # @return [Excon::Response] + # * body<~String> - + # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-VAppTemplateOvfDescriptor.html + # vCloud API Documentation + # @since vCloud API version 0.9 + def get_vapp_template_ovf_descriptor(id) + request( + :expects => 200, + :idempotent => true, + :method => 'GET', + :path => "vAppTemplate/#{id}/ovf" + ) + end + end + end + end +end diff --git a/tests/vcloud_director/requests/compute/ovf_descriptor_tests.rb b/tests/vcloud_director/requests/compute/ovf_descriptor_tests.rb new file mode 100644 index 000000000..2c9b76cca --- /dev/null +++ b/tests/vcloud_director/requests/compute/ovf_descriptor_tests.rb @@ -0,0 +1,44 @@ +Shindo.tests('Compute::VcloudDirector | ovf requests', ['vclouddirector']) do + + @service = Fog::Compute::VcloudDirector.new + + tests('Get current organization') do + session = @service.get_current_session.body + link = session[:Link].detect do |l| + l[:type] == 'application/vnd.vmware.vcloud.org+xml' + end + @org = @service.get_organization(link[:href].split('/').last).body + end + + tests('Get first vDC') do + session = @service.get_current_session.body + link = @org[:Link].detect do |l| + l[:type] == 'application/vnd.vmware.vcloud.vdc+xml' + end + @vdc = @service.get_vdc(link[:href].split('/').last).body + @vdc[:ResourceEntities][:ResourceEntity] = [@vdc[:ResourceEntities][:ResourceEntity]] if @vdc[:ResourceEntities][:ResourceEntity].is_a?(Hash) + end + + # 'Envelope' is the outer type of the parsed XML document. + tests('#get_vapp_ovf_descriptor').returns('Envelope') do + pending if Fog.mocking? + link = @vdc[:ResourceEntities][:ResourceEntity].detect do |l| + l[:type] == 'application/vnd.vmware.vcloud.vApp+xml' + end + pending if link.nil? + body = @service.get_vapp_ovf_descriptor(link[:href].split('/').last).body + Nokogiri::XML::Document.parse(body).children.first.name + end + + # 'Envelope' is the outer type of the parsed XML document. + tests('#get_vapp_template_ovf_descriptor').returns('Envelope') do + pending if Fog.mocking? + link = @vdc[:ResourceEntities][:ResourceEntity].detect do |l| + l[:type] == 'application/vnd.vmware.vcloud.vAppTemplate+xml' + end + pending if link.nil? + body = @service.get_vapp_template_ovf_descriptor(link[:href].split('/').last).body + Nokogiri::XML::Document.parse(body).children.first.name + end + +end