incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francesco Vollero <fvoll...@redhat.com>
Subject Re: [PATCH core] VSphere: Added more validation for CPU property value
Date Thu, 06 Oct 2011 13:33:20 GMT
Tested and it work properly. Just a small error in ~= instead of =~. ACK

------------
output: 

[fvollero@fermat ~]$ curl -u 'Administrator' -X POST -H 'Accept: application/xml' -d "image_id=factory-image-1ad2930a-74e0-4556-b0bd-caafd5d76cf4&hwp_memory=512&name=dctest01-testVsphere&realm_id=datastore1&keyname=&hwp_id=default&hwp_cpu=1.0&hwp_storage="
http://10.34.2.158:8080/api/instances
Enter host password for user 'Administrator':
<error status='400' url='/api/instances'>
  <parameter>RuntimeError</parameter>
  <message><![CDATA[Invalid CPU value. Must be in integer format]]></message>
</error>
------------

On Thu, Oct 06, 2011 at 03:13:15PM +0200, mfojtik@redhat.com wrote:
> 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..4068ca4 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?(val)
> +      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