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/07/07 17:19:06 UTC

VSphere driver improvements

Hi,

These two matches improve a bit functionality for the recently imported VSphere driver.
The first patch will add a reference from the instance to the image it was created from.
Reference to image is stored in extraConfig key=>value store in VM.

The second one, more interesting, add support for attaching a floppy driver to the virtual
machine. This is the first part of 'user-data' feature support.

I need to discuss something there. Since we will need to upload this floppy drive to the datastore
and it actually 'break' our 'stateless' API (since I'll need to store that file temporarely) I need to
know if the approach that user will supply base64 encoded floppy image as a 'user_data' parameter when
creating a new instance is acceptable.
I'm not sure if the way where we will create a floppy image in driver is the way we want to go, since it will
work only on linux and it could be a bit slow for 'large' files.

  -- Michal


[PATCH core 2/2] VSphere: Add initial support for attaching a floppy driver to the VM (user_data feature)

Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 .../deltacloud/drivers/vsphere/vsphere_driver.rb   |   34 ++++++++++++++++++-
 1 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
index daf34f1..75221b9 100644
--- a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
+++ b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
@@ -21,6 +21,8 @@ module Deltacloud::Drivers::VSphere
 
   class VSphereDriver < Deltacloud::BaseDriver
 
+    feature :instances, :user_data
+
     # Set of predefined hardware profiles
     define_hardware_profile('small') do
       cpu                1
@@ -213,9 +215,37 @@ module Deltacloud::Drivers::VSphere
             :numCPUs => instance_profile.cpu.value,
             :extraConfig => [
               { :key => 'template_id', :value => image_id }
-            ]
-          )
+            ])
         )
+        if opts[:user_data]
+          #
+          # ** TODO **
+          #
+          # Pick up user_data and save it to the temporary file.
+          # User data should be base64 encoded floppy image.
+          # Then upload this file to the datastore.
+          # Code below will attach this floppy to the VM.
+          #
+          # NOTE: You need to do 'modprobe floppy' on Vm in order to
+          #       access /dev/fd0
+          #
+          spec[:config].merge!({
+            :deviceChange => [{
+              :operation => :add,
+              :device => RbVmomi::VIM.VirtualFloppy({
+                :key => 0,
+                :backing => RbVmomi::VIM.VirtualFloppyImageBackingInfo({
+                  :fileName => "[datastore1] floppy.img" # 'datastore1' is the datastore name, floppy.img is the filename in datastore
+                }),
+                :connectable => RbVmomi::VIM.VirtualDeviceConnectInfo({
+                  :connected => true,
+                  :allowGuestControl => true,
+                  :startConnected => true
+                })
+              })
+            }]
+          })
+        end
         #
         # WARNING: This operation may take a very long time (about 1m) to complete
         #
-- 
1.7.4.1


[PATCH core 1/2] VSphere: Added support for referencing template machine using 'extraConfig' property

Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 .../deltacloud/drivers/vsphere/vsphere_driver.rb   |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
index 2d3d279..daf34f1 100644
--- a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
+++ b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
@@ -151,13 +151,16 @@ module Deltacloud::Drivers::VSphere
           config = vm.summary.config
           next unless config
           next unless vm.summary.storage
+          template_id = vm.config[:extraConfig].select { |k| k.key == 'template_id' }
+          template_id = template_id.first.value unless template_id.empty?
           properties = {
             :memory => config[:memorySizeMB],
             :cpus => config[:numCpu],
             :storage => vm.summary.storage[:unshared],
             :name => config[:name],
-            :full_name => config[:guestFullName]
+            :full_name => config[:guestFullName],
           }
+          puts properties.inspect
           instance_state = convert_state(:instance, vm.summary.runtime[:powerState])
           instance_profile = InstanceProfile::new(match_hwp_id(:memory => properties[:memory].to_s, :cpus => properties[:cpus].to_s),
                                                   :hwp_cpu => properties[:cpus],
@@ -168,6 +171,7 @@ module Deltacloud::Drivers::VSphere
             :id => properties[:name],
             :name => properties[:name],
             :owner_id => credentials.user,
+            :image_id => template_id,
             :description => properties[:full_name],
             :realm_id => realm_id,
             :state => instance_state,
@@ -206,7 +210,10 @@ module Deltacloud::Drivers::VSphere
           :template => false,
           :config => RbVmomi::VIM.VirtualMachineConfigSpec(
             :memoryMB => instance_profile.memory.value,
-            :numCPUs => instance_profile.cpu.value
+            :numCPUs => instance_profile.cpu.value,
+            :extraConfig => [
+              { :key => 'template_id', :value => image_id }
+            ]
           )
         )
         #
-- 
1.7.4.1