You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2011/10/06 15:54:26 UTC

svn commit: r1179627 - /incubator/deltacloud/trunk/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb

Author: mfojtik
Date: Thu Oct  6 13:54:26 2011
New Revision: 1179627

URL: http://svn.apache.org/viewvc?rev=1179627&view=rev
Log:
VSphere: Added more validation for CPU property value

Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb?rev=1179627&r1=1179626&r2=1179627&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb Thu Oct  6 13:54:26 2011
@@ -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?(val)
+      true if val =~ /^(\d+)$/
+    end
+
     def valid_memory_value?(val)
       true if (val.to_i%4) == 0
     end