mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2209 from nosborn/vcloud_director_post_undeploy_vapp
[vcloud_director] Fix :UndeployPowerAction in post_undeploy_vapp
This commit is contained in:
commit
980dddd59e
4 changed files with 103 additions and 7 deletions
39
lib/fog/vcloud_director/generators/compute/base.rb
Normal file
39
lib/fog/vcloud_director/generators/compute/base.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
module Fog
|
||||
module Generators
|
||||
module Compute
|
||||
module VcloudDirector
|
||||
class Base
|
||||
|
||||
attr_reader :options
|
||||
|
||||
def initialize(options)
|
||||
@options = options
|
||||
end
|
||||
|
||||
# @return [String]
|
||||
def to_xml
|
||||
builder.to_xml(:ident => 0)
|
||||
end
|
||||
|
||||
# @return [String]
|
||||
def pretty_xml
|
||||
builder.to_xml
|
||||
end
|
||||
|
||||
# @api private
|
||||
# @return [Nokogiri::XML::Document]
|
||||
def doc
|
||||
builder.doc
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# @api private
|
||||
def builder
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,28 @@
|
|||
module Fog
|
||||
module Generators
|
||||
module Compute
|
||||
module VcloudDirector
|
||||
require 'fog/vcloud_director/generators/compute/base'
|
||||
|
||||
# Parameters to an undeploy vApp request.
|
||||
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/types/UndeployVAppParamsType.html
|
||||
# vCloud API Documentation
|
||||
class UndeployVappParams < Base
|
||||
|
||||
# @api private
|
||||
# @return [Nokogiri::XML::Builder]
|
||||
def builder
|
||||
@builder ||= Nokogiri::XML::Builder.new do |xml|
|
||||
xml.UndeployVAppParams(:xmlns => 'http://www.vmware.com/vcloud/v1.5') {
|
||||
if options.has_key?(:UndeployPowerAction)
|
||||
xml.UndeployPowerAction options[:UndeployPowerAction]
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,6 +2,8 @@ module Fog
|
|||
module Compute
|
||||
class VcloudDirector
|
||||
class Real
|
||||
require 'fog/vcloud_director/generators/compute/undeploy_vapp_params'
|
||||
|
||||
# Undeploy a vApp/VM.
|
||||
#
|
||||
# Undeployment deallocates all resources used by the vApp and the VMs it contains.
|
||||
|
@ -31,16 +33,12 @@ module Fog
|
|||
# vCloud API Documentation
|
||||
# @since vCloud API version 0.9
|
||||
def post_undeploy_vapp(vapp_id, options={})
|
||||
body = <<-END
|
||||
<UndeployVAppParams xmlns="http://www.vmware.com/vcloud/v1.5">
|
||||
<UndeployPowerAction>#{options[:UndeployPowerAction]||''}</UndeployPowerAction>
|
||||
</UndeployVAppParams>
|
||||
END
|
||||
body = Fog::Generators::Compute::VcloudDirector::UndeployVappParams.new(options)
|
||||
|
||||
request(
|
||||
:body => body,
|
||||
:body => body.to_xml,
|
||||
:expects => 202,
|
||||
:headers => {'Content-Type' => 'application/vnd.vmware.vcloud.undeployVAppParams+xml' },
|
||||
:headers => {'Content-Type' => 'application/vnd.vmware.vcloud.undeployVAppParams+xml'},
|
||||
:method => 'POST',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => "vApp/#{vapp_id}/action/undeploy"
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
Shindo.tests('Compute::VcloudDirector | UndeployVAppParams generator', ['vclouddirector', 'xsd']) do
|
||||
|
||||
require 'fog/vcloud_director/generators/compute/undeploy_vapp_params'
|
||||
|
||||
tests('with :UndeployPowerAction option') do
|
||||
tests('#to_xml').returns(String) do
|
||||
attrs = {:UndeployPowerAction => 'default'}
|
||||
@undeploy_vapp_params = Fog::Generators::Compute::VcloudDirector::UndeployVappParams.new(attrs)
|
||||
@undeploy_vapp_params.to_xml.class
|
||||
end
|
||||
|
||||
tests('#validate').returns([]) do
|
||||
pending unless VcloudDirector::Generators::Helpers.have_xsd?
|
||||
VcloudDirector::Generators::Helpers.validate(@undeploy_vapp_params.doc)
|
||||
end
|
||||
end
|
||||
|
||||
tests('without :UndeployPowerAction option') do
|
||||
tests('#to_xml').returns(String) do
|
||||
attrs = {}
|
||||
@undeploy_vapp_params = Fog::Generators::Compute::VcloudDirector::UndeployVappParams.new(attrs)
|
||||
@undeploy_vapp_params.to_xml.class
|
||||
end
|
||||
|
||||
tests('#validate').returns([]) do
|
||||
pending unless VcloudDirector::Generators::Helpers.have_xsd?
|
||||
VcloudDirector::Generators::Helpers.validate(@undeploy_vapp_params.doc)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue