From 1e92536eafa9df6969e45ab35c98fe76bd13b06b Mon Sep 17 00:00:00 2001 From: Mike Pountney Date: Sun, 15 Dec 2013 18:49:29 +0000 Subject: [PATCH] vApp rename via put_vapp_name_and_description --- lib/fog/vcloud_director/compute.rb | 1 + .../generators/compute/vapp.rb | 30 ++++++++++++++++ .../compute/put_vapp_name_and_description.rb | 36 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 lib/fog/vcloud_director/generators/compute/vapp.rb create mode 100644 lib/fog/vcloud_director/requests/compute/put_vapp_name_and_description.rb diff --git a/lib/fog/vcloud_director/compute.rb b/lib/fog/vcloud_director/compute.rb index 025bc3360..83cf6674c 100644 --- a/lib/fog/vcloud_director/compute.rb +++ b/lib/fog/vcloud_director/compute.rb @@ -244,6 +244,7 @@ module Fog request :put_metadata_value # deprecated request :put_network_connection_system_section_vapp request :put_vapp_metadata_item_metadata + request :put_vapp_name_and_description request :put_vapp_template_metadata_item_metadata request :put_vm request :put_vm_capabilities diff --git a/lib/fog/vcloud_director/generators/compute/vapp.rb b/lib/fog/vcloud_director/generators/compute/vapp.rb new file mode 100644 index 000000000..700410632 --- /dev/null +++ b/lib/fog/vcloud_director/generators/compute/vapp.rb @@ -0,0 +1,30 @@ +module Fog + module Generators + module Compute + module VcloudDirector + + # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/types/VmType.html + class Vapp + attr_reader :name, :description + + def initialize(name, description=nil) + @name = name + @description = description + end + + def generate_xml + attrs = @attrs + Nokogiri::XML::Builder.new do + VApp('xmlns' => 'http://www.vmware.com/vcloud/v1.5', + 'name' => name + ) { + Description description unless description.nil? + } + end.to_xml + end + + end + end + end + end +end diff --git a/lib/fog/vcloud_director/requests/compute/put_vapp_name_and_description.rb b/lib/fog/vcloud_director/requests/compute/put_vapp_name_and_description.rb new file mode 100644 index 000000000..714e42d59 --- /dev/null +++ b/lib/fog/vcloud_director/requests/compute/put_vapp_name_and_description.rb @@ -0,0 +1,36 @@ +module Fog + module Compute + class VcloudDirector + class Real + + require 'fog/vcloud_director/generators/compute/vapp' + + # Modify the name or description of a vApp. + # + # This operation is asynchronous and returns a task that you can monitor + # to track the progress of the request. + # + # + # @param [String] id Object identifier of the VM. + # @param [String] name of the VM. + # @param [String] description to be assigned. + # @return [Excon::Response] + # * body<~Hash>: + # + # @see http://pubs.vmware.com/vcd-55/topic/com.vmware.vcloud.api.reference.doc_55/doc/operations/PUT-VAppNameAndDescription.html + # @since vCloud API version 0.9 + def put_vapp_name_and_description(id, name, description=nil) + body = Fog::Generators::Compute::VcloudDirector::Vapp.new(name, description).generate_xml + request( + :body => body, + :expects => 202, + :headers => {'Content-Type' => 'application/vnd.vmware.vcloud.vApp+xml'}, + :method => 'PUT', + :parser => Fog::ToHashDocument.new, + :path => "vApp/#{id}" + ) + end + end + end + end +end