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 2012/10/25 15:16:09 UTC

[PATCH core] VSphere: Added possibility to change the network name (DTACLOUD-348)

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

* Added new feature: 'network_name'
* Setting 'network_name' parameter when creating a new instance in VSphere
  should change the VM virtual ethernet interface name to value of this
  parameter.

Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/deltacloud/drivers/features.rb              |  7 +++++++
 .../lib/deltacloud/drivers/vsphere/vsphere_driver.rb   | 18 ++++++++++++++++++
 server/views/instances/new.html.haml                   |  5 +++++
 3 files changed, 30 insertions(+)

diff --git a/server/lib/deltacloud/drivers/features.rb b/server/lib/deltacloud/drivers/features.rb
index 3e1b704..9bdf154 100644
--- a/server/lib/deltacloud/drivers/features.rb
+++ b/server/lib/deltacloud/drivers/features.rb
@@ -58,6 +58,13 @@ module Deltacloud
         end
       end
 
+      feature :network_name, :for => :instances do
+        description "Allow to change the network interface when launching an instance"
+        operation :create do
+          param :network_name, :string, :optional
+        end
+      end
+
       feature :metrics, :for => :instances do
         description "Enable more detailed monitoring and metrics reporting for the instance"
         operation :create do
diff --git a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
index 43818fe..b0042b3 100644
--- a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
+++ b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
@@ -32,6 +32,7 @@ module Deltacloud::Drivers::Vsphere
     feature :instances, :user_iso
     feature :instances, :user_data
     feature :instances, :user_name
+    feature :instances, :network_name
 
     define_hardware_profile('default')
 
@@ -282,6 +283,23 @@ module Deltacloud::Drivers::Vsphere
             raise "Failed to inject data to device because there is no CD-ROM drive defined in given template"
           end
         end
+        if opts[:network_name] and not opts[:network_name].empty?
+          device = vm[:instance].config.hardware.device.find { |hw| hw.kind_of? RbVmomi::VIM::VirtualEthernetCard }
+
+          device.backing = RbVmomi::VIM::VirtualDeviceDeviceBackingInfo(:deviceName => opts[:network_name] )
+          device[:deviceInfo][:summary] = opts[:network_name]
+
+          if machine_config[:deviceChange]
+            machine_config[:deviceChange] << { :operation => :edit, :device => device }
+          else
+            machine_config.merge!({
+              :deviceChange => [{
+                :operation => :edit,
+                :device => device
+              }]
+            })
+          end
+        end
         spec = RbVmomi::VIM.VirtualMachineCloneSpec(
           :location => relocateSpec,
           :powerOn => true,
diff --git a/server/views/instances/new.html.haml b/server/views/instances/new.html.haml
index 6c8e130..72b40ac 100644
--- a/server/views/instances/new.html.haml
+++ b/server/views/instances/new.html.haml
@@ -42,6 +42,11 @@
             %label{ :for => :instance_count} # of instances to be launched:
             %input{ :type => :text, :id => :instance_count, :name => :instance_count, :value => '1' }
 
+        - if driver.class.has_feature?(:instances, :network_name)
+          %div{ 'data-role' => :fieldcontain }
+            %label{ :for => :network_name} Network Name:
+            %input{ :type => :text, :id => :network_name, :name => :network_name, :value => '' }
+
         - if driver.class.has_feature?(:instances, :metrics)
           %div{ 'data-role' => :fieldcontain }
             %label{ :for => :metrics} Enable metrics for this instance
-- 
1.7.12.1