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

[vcloud_director] Add get_*_ovf_descriptor methods.

This commit is contained in:
Nick Osborn 2013-10-02 02:14:52 +01:00
parent 233166467a
commit a931ac87e4
4 changed files with 94 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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