You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/10/06 13:27:59 UTC
[PATCH core] VSphere: Added more validation for CPU property value
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
.../deltacloud/drivers/vsphere/vsphere_driver.rb | 14 +++++++++++++-
1 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
index 136766d..6549539 100644
--- a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
+++ b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
@@ -171,7 +171,8 @@ module Deltacloud::Drivers::VSphere
:hwp_cpu => properties[:cpus],
:hwp_memory => properties[:memory],
:hwp_storage => properties[:storage])
-
+ # Check if all values are set in required format
+ validate_instance_profile!(instance_profile)
# We're getting IP address from 'vmware guest tools'.
# If guest tools are not installed, we return list of MAC addresses
# assigned to this instance.
@@ -205,6 +206,9 @@ module Deltacloud::Drivers::VSphere
def create_instance(credentials, image_id, opts)
vsphere = new_client(credentials)
safely do
+ if opts[:hwp_cpu]
+ raise "Invalid CPU value. Must be in integer format" unless valid_cpu_value?(opts[:hwp_cpu])
+ end
rootFolder = vsphere.serviceInstance.content.rootFolder
vm = find_vm(credentials, opts[:image_id])
raise "ERROR: Could not find the image in given datacenter" unless vm[:instance]
@@ -351,6 +355,10 @@ module Deltacloud::Drivers::VSphere
status 502
end
+ on /Invalid/ do
+ status 400
+ end
+
end
def valid_credentials?(credentials)
@@ -404,6 +412,10 @@ module Deltacloud::Drivers::VSphere
new_state
end
+ def valid_cpu_value?(cpu)
+ true if val ~= /^(\d+)$/
+ end
+
def valid_memory_value?(val)
true if (val.to_i%4) == 0
end
--
1.7.4.4