incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core] VSphere: Added more validation for CPU property value
Date Thu, 06 Oct 2011 11:27:59 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@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


Mime
View raw message