Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request fog#2211 from nosborn/vcloud_director_capture_vapp
[vcloud_director] Add post_capture_vapp request.
- Loading branch information
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
lib/fog/vcloud_director/generators/compute/capture_vapp_params.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Fog | ||
module Generators | ||
module Compute | ||
module VcloudDirector | ||
require 'fog/vcloud_director/generators/compute/base' | ||
|
||
# Parameters for a captureVapp request. | ||
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/types/CaptureVAppParamsType.html | ||
# vCloud API Documentation | ||
class CaptureVappParams < Base | ||
|
||
attr_reader :name, :source_href | ||
|
||
def initialize(name, source_href, options={}) | ||
super options | ||
@name = name | ||
@source_href = source_href | ||
end | ||
|
||
# @api private | ||
# @return [Nokogiri::XML::Builder] | ||
def builder | ||
@builder ||= Nokogiri::XML::Builder.new do |xml| | ||
attrs = {:xmlns => 'http://www.vmware.com/vcloud/v1.5', :name => name} | ||
xml.CaptureVAppParams(attrs) { | ||
xml.Description options[:Description] || '' | ||
xml.Source(:href => source_href) | ||
} | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end |
39 changes: 39 additions & 0 deletions
39
lib/fog/vcloud_director/requests/compute/post_capture_vapp.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Fog | ||
module Compute | ||
class VcloudDirector | ||
class Real | ||
require 'fog/vcloud_director/generators/compute/capture_vapp_params' | ||
|
||
# Create a vApp template from a vApp. | ||
# | ||
# The response includes a Task element. You can monitor the task to to | ||
# track the creation of the vApp template. | ||
# | ||
# @param [String] vdc_id Object identifier of the vDC. | ||
# @param [String] name Name of the vApp template. | ||
# @param [String] source_id Object identifier of the vApp to capture. | ||
# @param [Hash] options | ||
# @option options [String] :Description Optional description. | ||
# @return [Excon::Response] | ||
# * body<~Hash>: | ||
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/POST-CaptureVApp.html | ||
# vCloud API Documentation | ||
# @since vCloud API version 0.9 | ||
def post_capture_vapp(vdc_id, name, source_id, options={}) | ||
body = Fog::Generators::Compute::VcloudDirector::CaptureVappParams.new( | ||
name, "#{endpoint}vApp/#{source_id}", options | ||
) | ||
|
||
request( | ||
:body => body.to_xml, | ||
:expects => 201, | ||
:headers => {'Content-Type' => 'application/vnd.vmware.vcloud.captureVAppParams+xml'}, | ||
:method => 'POST', | ||
:parser => Fog::ToHashDocument.new, | ||
:path => "vdc/#{vdc_id}/action/captureVApp" | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
tests/vcloud_director/generators/compute/capture_vapp_params_tests.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Shindo.tests('Compute::VcloudDirector | CaptureVAppParams generator', ['vclouddirector', 'xsd']) do | ||
|
||
require 'fog/vcloud_director/generators/compute/capture_vapp_params' | ||
|
||
tests('#to_xml').returns(String) do | ||
@capture_vapp_params = Fog::Generators::Compute::VcloudDirector::CaptureVappParams.new( | ||
'name', 'http://example.com/api/vApp/0' | ||
) | ||
@capture_vapp_params.to_xml.class | ||
end | ||
|
||
tests('#validate').returns([]) do | ||
pending unless VcloudDirector::Generators::Helpers.have_xsd? | ||
VcloudDirector::Generators::Helpers.validate(@capture_vapp_params.doc) | ||
end | ||
|
||
end |