Skip to content

Commit

Permalink
Merge pull request fog#2210 from nosborn/vcloud_director_get_ovf_desc…
Browse files Browse the repository at this point in the history
…riptor

[vcloud_director] Add get_*_ovf_descriptor methods.
  • Loading branch information
nosborn committed Oct 2, 2013
2 parents 2331664 + a931ac8 commit 2a18843
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/fog/vcloud_director/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ class Task < ServiceError; end
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions tests/vcloud_director/requests/compute/ovf_descriptor_tests.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2a18843

Please sign in to comment.