From 119604cdeb23f493428b5f7fe68c78ed3c31a419 Mon Sep 17 00:00:00 2001 From: Martin Matuska Date: Tue, 19 Nov 2013 10:49:08 +0100 Subject: [PATCH] Add request to set VM annotations in vSphere --- lib/fog/vsphere/compute.rb | 1 + .../requests/compute/set_vm_customvalue.rb | 19 +++++++++++++++++ .../compute/set_vm_customvalue_tests.rb | 21 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 lib/fog/vsphere/requests/compute/set_vm_customvalue.rb create mode 100644 tests/vsphere/requests/compute/set_vm_customvalue_tests.rb diff --git a/lib/fog/vsphere/compute.rb b/lib/fog/vsphere/compute.rb index 6b820be5e..5e0737428 100644 --- a/lib/fog/vsphere/compute.rb +++ b/lib/fog/vsphere/compute.rb @@ -80,6 +80,7 @@ module Fog request :list_vm_customvalues request :list_customfields request :get_vm_first_scsi_controller + request :set_vm_customvalue module Shared diff --git a/lib/fog/vsphere/requests/compute/set_vm_customvalue.rb b/lib/fog/vsphere/requests/compute/set_vm_customvalue.rb new file mode 100644 index 000000000..e65aa3e13 --- /dev/null +++ b/lib/fog/vsphere/requests/compute/set_vm_customvalue.rb @@ -0,0 +1,19 @@ +module Fog + module Compute + class Vsphere + class Real + def set_vm_customvalue(vm_id, key, value) + vm_ref = get_vm_ref(vm_id) + vm_ref.setCustomValue(:key => key, :value => value) + end + + end + class Mock + def set_vm_customvalue(vm_id, key, value) + nil + end + end + end + end +end + diff --git a/tests/vsphere/requests/compute/set_vm_customvalue_tests.rb b/tests/vsphere/requests/compute/set_vm_customvalue_tests.rb new file mode 100644 index 000000000..76ba88f53 --- /dev/null +++ b/tests/vsphere/requests/compute/set_vm_customvalue_tests.rb @@ -0,0 +1,21 @@ +Shindo.tests('Fog::Compute[:vsphere] | set_vm_customvalue request', ['vsphere']) do + + compute = Fog::Compute[:vsphere] + + instance_uuid = '50137835-88a1-436e-768e-9b2677076e67' + custom_key = nil + custom_value = nil + + tests('The response should') do + response = compute.set_vm_customvalue(instance_uuid, custom_key, custom_value) + test('be nil') { response.nil? } + end + + tests('The expected options') do + raises(ArgumentError, 'raises ArgumentError when instance_uuid option is missing') { compute.set_vm_customvalue } + raises(ArgumentError, 'raises ArgumentError when custom_key option is missing') { compute.set_vm_customvalue(instance_uuid) } + raises(ArgumentError, 'raises ArgumentError when custom_value option is missing') { compute.set_vm_customvalue(instance_uuid, custom_key) } + end + +end +