incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 3/4] Added information about current API provider to layout (near driver)
Date Tue, 19 Jul 2011 14:19:38 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 .../deltacloud/drivers/vsphere/vsphere_client.rb   |    2 +-
 .../deltacloud/drivers/vsphere/vsphere_driver.rb   |   18 +++++++++++-------
 server/views/layout.html.haml                      |    2 +-
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/server/lib/deltacloud/drivers/vsphere/vsphere_client.rb b/server/lib/deltacloud/drivers/vsphere/vsphere_client.rb
index f2cc486..7e5cb4a 100644
--- a/server/lib/deltacloud/drivers/vsphere/vsphere_client.rb
+++ b/server/lib/deltacloud/drivers/vsphere/vsphere_client.rb
@@ -68,7 +68,7 @@ module Deltacloud::Drivers::VSphere
       rootFolder = vsphere.serviceInstance.content.rootFolder
       rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).each do |dc|
         dc.datastoreFolder.childEntity.collect do |datastore|
-          vms += datastore.vm.collect { |vm| { :instance => vm, :datastore => datastore.name
} }
+          vms += datastore.vm.collect { |vm| { :instance => vm, :datastore => datastore.name
} unless vm.nil? }
         end
       end
       vms.flatten.compact
diff --git a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
index 3a502e0..971bbbb 100644
--- a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
+++ b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
@@ -27,6 +27,7 @@ module Deltacloud::Drivers::VSphere
     include Deltacloud::Drivers::VSphere::Helper
 
     feature :instances, :user_data
+    feature :instances, :user_name
 
     def hardware_profiles(credentials, opts={})
       vsphere = new_client(credentials)
@@ -71,7 +72,6 @@ module Deltacloud::Drivers::VSphere
         else
           template_vms = list_virtual_machines(credentials).select { |vm| vm[:instance].summary.config[:template]
}
         end
-
         img_arr = template_vms.collect do |image_hash|
           # Since all calls to vm are threaten as SOAP calls, reduce them using
           # local variable.
@@ -94,7 +94,6 @@ module Deltacloud::Drivers::VSphere
           )
         end
       end
-
       img_arr = filter_on( img_arr, :architecture, opts )
       img_arr.sort_by{|e| [e.owner_id, e.name]}
     end
@@ -145,10 +144,8 @@ module Deltacloud::Drivers::VSphere
           # Since all calls to vm are threaten as SOAP calls, reduce them using
           # local variable.
           vm, realm_id = vm_hash[:instance], vm_hash[:datastore]
-          next unless vm
           config = vm.summary.config
-          next unless config
-          next unless vm.summary.storage
+          next if not config
           template_id = vm.config[:extraConfig].select { |k| k.key == 'template_id' }
           template_id = template_id.first.value unless template_id.empty?
           properties = {
@@ -209,7 +206,7 @@ module Deltacloud::Drivers::VSphere
           :memoryMB => opts[:hwp_memory],
           :numCPUs => opts[:hwp_cpu],
           :extraConfig => [
-            { :key => 'template_id', :value => image_id }
+            { :key => 'template_id', :value => image_id },
           ]
         }
         # If user wants to inject data into instance he need to submit a Base64
@@ -220,7 +217,10 @@ module Deltacloud::Drivers::VSphere
           device = vm[:instance].config.hardware.device.select { |hw| hw.class == RbVmomi::VIM::VirtualCdrom
}.first
           if device
             # TODO: Upload baked ISO image to the Datastore
-            device.backing = RbVmomi::VIM.VirtualCdromIsoBackingInfo(:fileName => "[#{opts[:realm_id]
|| vm[:datastore]}] test.iso")
+            machine_config[:extraConfig] << {
+              :key => 'user_data_file', :value => "#{opts[:name]}.iso"
+            }
+            device.backing = RbVmomi::VIM.VirtualCdromIsoBackingInfo(:fileName => "[#{opts[:realm_id]
|| vm[:datastore]}] #{opts[:name].iso}")
             machine_config.merge!({
               :deviceChange => [{
                 :operation => :edit,
@@ -290,6 +290,10 @@ module Deltacloud::Drivers::VSphere
         status 502
       end
 
+      on /Failed to inject data/ do
+        status 502
+      end
+
     end
 
     def valid_credentials?(credentials)
diff --git a/server/views/layout.html.haml b/server/views/layout.html.haml
index f6d3010..9deaaf3 100644
--- a/server/views/layout.html.haml
+++ b/server/views/layout.html.haml
@@ -24,7 +24,7 @@
           |
           =link_to_format(:json)
         #driver_info
-          Driver: #{driver_symbol} | API version: #{settings.version}
+          Driver: #{driver_symbol} | Provider: #{Thread::current[:provider] || ENV['API_PROVIDER']}
| API version: #{settings.version}
         #copyright
           Copyright 2009-2011
           %a{:href => 'http://incubator.apache.org/deltacloud/'} The Apache Software Foundation
-- 
1.7.4.1


Mime
View raw message