From 739f9e2731566ec310f416cec9683848b83cfaa9 Mon Sep 17 00:00:00 2001 From: Nick Osborn Date: Mon, 14 Oct 2013 18:30:24 +0100 Subject: [PATCH] [vcloud_director] Explicitly handle duplicate names. --- .../compute/post_instantiate_vapp_template.rb | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/fog/vcloud_director/requests/compute/post_instantiate_vapp_template.rb b/lib/fog/vcloud_director/requests/compute/post_instantiate_vapp_template.rb index f2480012b..8127ec11a 100644 --- a/lib/fog/vcloud_director/requests/compute/post_instantiate_vapp_template.rb +++ b/lib/fog/vcloud_director/requests/compute/post_instantiate_vapp_template.rb @@ -45,6 +45,8 @@ module Fog # @return [Excon::Response] # * body<~Hash>: # + # @raise Fog::Compute::VcloudDirector::DuplicateName + # # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/POST-InstantiateVAppTemplate.html # @since vCloud API version 0.9 def post_instantiate_vapp_template(id, vapp_template_id, name, options={}) @@ -109,14 +111,21 @@ module Fog } end.to_xml - request( - :body => body, - :expects => 201, - :headers => {'Content-Type' => 'application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml'}, - :method => 'POST', - :parser => Fog::ToHashDocument.new, - :path => "vdc/#{id}/action/instantiateVAppTemplate" - ) + begin + request( + :body => body, + :expects => 201, + :headers => {'Content-Type' => 'application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml'}, + :method => 'POST', + :parser => Fog::ToHashDocument.new, + :path => "vdc/#{id}/action/instantiateVAppTemplate" + ) + rescue Fog::Compute::VcloudDirector::BadRequest => e + if e.minor_error_code == 'DUPLICATE_NAME' + raise Fog::Compute::VcloudDirector::DuplicateName.new(e.message) + end + raise + end end end end