Skip to content

Commit

Permalink
Merge pull request fog#2211 from nosborn/vcloud_director_capture_vapp
Browse files Browse the repository at this point in the history
[vcloud_director] Add post_capture_vapp request.
  • Loading branch information
nosborn committed Oct 2, 2013
2 parents 2a18843 + e8edcc0 commit c0af5b9
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/fog/vcloud_director/compute.rb
Expand Up @@ -110,6 +110,7 @@ class Task < ServiceError; end
request :get_vms_by_metadata
request :instantiate_vapp_template
request :post_cancel_task
request :post_capture_vapp
request :post_power_off_vapp
request :post_power_on_vapp
request :post_reboot_vapp
Expand Down
36 changes: 36 additions & 0 deletions lib/fog/vcloud_director/generators/compute/capture_vapp_params.rb
@@ -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 lib/fog/vcloud_director/requests/compute/post_capture_vapp.rb
@@ -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
@@ -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

0 comments on commit c0af5b9

Please sign in to comment.