You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by fv...@redhat.com on 2011/07/27 13:23:38 UTC

[PATCH core 2/2] Added user_data option in vsphere driver

From: Francesco Vollero <fv...@redhat.com>


Signed-off-by: Francesco Vollero <fv...@redhat.com>
---
 .../deltacloud/drivers/vsphere/vsphere_driver.rb   |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
index cff74ca..3797123 100644
--- a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
+++ b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
@@ -229,6 +229,25 @@ module Deltacloud::Drivers::VSphere
         # encoded gzipped ISO image.
         # This image will be uplaoded to the Datastore given in 'realm_id'
         # parameter and them attached to instance.
+        if opts[:user_data] and not opts[:user_data].empty?
+          device = vm[:instance].config.hardware.device.select { |hw| hw.class == RbVmomi::VIM::VirtualCdrom }.first
+          if device
+            VSphere::FileManager::user_data!(datastore, opts[:user_data],"deltacloud_user_data")
+            machine_config[:extraConfig] << {
+              :key => 'user_data_file', :value => "deltacloud_user_data.iso"
+            }
+            device.backing = RbVmomi::VIM.VirtualCdromIsoBackingInfo(:fileName => "[#{opts[:realm_id] || vm[:datastore]}] "+
+                                                                     "/#{VSphere::FileManager::DIRECTORY_PATH}/deltacloud_user_data.iso")
+            machine_config.merge!({
+              :deviceChange => [{
+                :operation => :edit,
+                :device => device
+              }]
+            })
+          else
+            raise "Failed to inject data to device because there is no CD-ROM drive defined in given template"
+          end
+        end
         if opts[:user_iso] and not opts[:user_iso].empty?
           device = vm[:instance].config.hardware.device.select { |hw| hw.class == RbVmomi::VIM::VirtualCdrom }.first
           if device
-- 
1.7.4.4


Re: [PATCH core 2/2] Added user_data option in vsphere driver

Posted by David Lutterkort <lu...@redhat.com>.
On Wed, 2011-07-27 at 13:23 +0200, fvollero@redhat.com wrote:
> From: Francesco Vollero <fv...@redhat.com>

Great stuff. One minor nit:

> diff --git a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
> index cff74ca..3797123 100644
> --- a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
> +++ b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
> @@ -229,6 +229,25 @@ module Deltacloud::Drivers::VSphere
>          # encoded gzipped ISO image.
>          # This image will be uplaoded to the Datastore given in 'realm_id'
>          # parameter and them attached to instance.
> +        if opts[:user_data] and not opts[:user_data].empty?
> +          device = vm[:instance].config.hardware.device.select { |hw| hw.class == RbVmomi::VIM::VirtualCdrom }.first

We should raise an error if both user_data and user_iso are set; that
the two are mutually exclusive should also be described in the feature
definition.

David