From 735a8822cc82a7a295ae7389efc4f855aca40692 Mon Sep 17 00:00:00 2001 From: Ohad Levy Date: Wed, 28 Mar 2012 10:20:27 +0200 Subject: [PATCH] [vsphere] adds memory and cpu server attributes --- lib/fog/vsphere/compute.rb | 6 ++++-- lib/fog/vsphere/models/compute/server.rb | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/fog/vsphere/compute.rb b/lib/fog/vsphere/compute.rb index 92c3b630b..838e3a875 100644 --- a/lib/fog/vsphere/compute.rb +++ b/lib/fog/vsphere/compute.rb @@ -49,6 +49,8 @@ module Fog :tools_state => 'guest.toolsStatus', :tools_version => 'guest.toolsVersionStatus', :is_a_template => 'config.template', + :memory_mb => 'config.hardware.memoryMB', + :cpus => 'config.hardware.numCPU', } # Utility method to convert a VMware managed object into an attribute hash. @@ -65,8 +67,8 @@ module Fog # API. The hypervisor name and mac_addresses attributes may not be available # so we need catch any exceptions thrown during lookup and set them to nil. # - # The use of the "tap" method here is a convience, it allows us to update the - # hash object without expliclty returning the hash at the end of the method. + # The use of the "tap" method here is a convenience, it allows us to update the + # hash object without explicitly returning the hash at the end of the method. Hash[ATTR_TO_PROP.map { |k,v| [k.to_s, props[v]] }].tap do |attrs| attrs['id'] ||= vm_mob_ref._ref attrs['mo_ref'] = vm_mob_ref._ref diff --git a/lib/fog/vsphere/models/compute/server.rb b/lib/fog/vsphere/models/compute/server.rb index a3521162f..4ed67d7f8 100644 --- a/lib/fog/vsphere/models/compute/server.rb +++ b/lib/fog/vsphere/models/compute/server.rb @@ -34,19 +34,24 @@ module Fog attribute :connection_state attribute :mo_ref attribute :path + attribute :memory_mb + attribute :cpus def vm_reconfig_memory(options = {}) requires :instance_uuid, :memory connection.vm_reconfig_memory('instance_uuid' => instance_uuid, 'memory' => memory) end + def vm_reconfig_cpus(options = {}) requires :instance_uuid, :cpus connection.vm_reconfig_cpus('instance_uuid' => instance_uuid, 'cpus' => cpus) end + def vm_reconfig_hardware(options = {}) requires :instance_uuid, :hardware_spec connection.vm_reconfig_hardware('instance_uuid' => instance_uuid, 'hardware_spec' => hardware_spec) end + def start(options = {}) requires :instance_uuid connection.vm_power_on('instance_uuid' => instance_uuid) @@ -82,6 +87,7 @@ module Fog new_vm.connection = self.connection new_vm end + def clone(options = {}) requires :name, :path # Convert symbols to strings @@ -108,6 +114,10 @@ module Fog tools_state != "toolsNotInstalled" end + def memory + memory_mb * 1024 * 1024 + end + end end