1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge pull request #2452 from alphagov/update_vm_storage_profile

[vcloud_director] update name, description and storage_profile for vm
This commit is contained in:
Nick Osborn 2013-12-04 07:29:42 -08:00
commit 3ae7c2252c
3 changed files with 73 additions and 0 deletions

View file

@ -245,6 +245,7 @@ module Fog
request :put_network_connection_system_section_vapp
request :put_vapp_metadata_item_metadata
request :put_vapp_template_metadata_item_metadata
request :put_vm
request :put_vm_capabilities
class Model < Fog::Model

View file

@ -0,0 +1,33 @@
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 Vm
attr_reader :attrs
def initialize(attrs={})
@attrs = attrs
end
def generate_xml
attrs = @attrs
Nokogiri::XML::Builder.new do
Vm('xmlns' => 'http://www.vmware.com/vcloud/v1.5', 'name' => attrs[:name]) {
Description attrs[:Description] if attrs.key?(:Description)
if attrs.key?(:StorageProfile)
StorageProfile(
'type' => 'application/vnd.vmware.vcloud.vdcStorageProfile+xml',
'name' => attrs[:StorageProfile][:name],
'href' => attrs[:StorageProfile][:href]
)
end
}
end.to_xml
end
end
end
end
end
end

View file

@ -0,0 +1,39 @@
module Fog
module Compute
class VcloudDirector
class Real
require 'fog/vcloud_director/generators/compute/vm'
# Update the name, description and storage profile for VM.
#
# 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 [Hash] options
# * :Description<~String>: - description to be assigned.
# * :StorageProfile<~Hash>: - storage profile to be assigned.
# * :name<~String>
# * :href<~String>
# @return [Excon::Response]
# * body<~Hash>:
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/PUT-Vm.html
# @since vCloud API version 0.9
def put_vm(id, name, options)
body = Fog::Generators::Compute::VcloudDirector::Vm.new(options.merge(:name => name)).generate_xml
request(
:body => body,
:expects => 202,
:headers => {'Content-Type' => 'application/vnd.vmware.vcloud.vm+xml'},
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{id}"
)
end
end
end
end
end