mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-20 20:02:38 +09:00
feature #1977: Add attach nic operation
This commit is contained in:
1 parent
e2d6c666d8
commit
aa2799ed34
3 files changed
+57
-4
No files matched your search
@@ -25,5 +25,6 @@ fi
|
||||
LOCAL_ACTIONS="deploy,shutdown,reboot,cancel,save,restore,migrate,poll,pre"
|
||||
LOCAL_ACTIONS="${LOCAL_ACTIONS},post,clean"
|
||||
LOCAL_ACTIONS="${LOCAL_ACTIONS},snapshotcreate,snapshotrevert,snapshotdelete"
|
||||
LOCAL_ACTIONS="${LOCAL_ACTIONS},attach_nic,detach_nic"
|
||||
|
||||
exec $MAD_LOCATION/one_vmm_exec -l $LOCAL_ACTIONS $*
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
@@ -15,7 +15,25 @@
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
source $(dirname $0)/../../scripts_common.sh
|
||||
|
||||
log_error "Attach network interface is not yet supported for VMware."
|
||||
exit 1
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'vi_driver'
|
||||
|
||||
deploy_id = ARGV[0]
|
||||
mac = ARGV[1]
|
||||
bridge = ARGV[2]
|
||||
host = ARGV[5]
|
||||
|
||||
vi_drv = VIDriver.new(host)
|
||||
|
||||
puts vi_drv.poll_vm(deploy_id)
|
||||
@@ -303,4 +303,38 @@ class VIDriver
|
||||
|
||||
return perfManager.retrieve_stats(objects, metrics, stat_opts)
|
||||
end
|
||||
|
||||
# -------------------------------------------------------------------------#
|
||||
# Attach a NIC to deploy_id, linked to bridge, with mac and of type = model#
|
||||
# -------------------------------------------------------------------------#
|
||||
def attach_nic(deploy_id, bridge, model, mac)
|
||||
vm = get_vm(deploy_id)[:vm]
|
||||
card_num = 1 # start in one, we want the next avaiable id
|
||||
vm.config.hardware.device.each{ |dv|
|
||||
if dv.class.ancestors[1] == VIM::VirtualEthernetCard
|
||||
card_num = card_num + 1
|
||||
end
|
||||
}
|
||||
backing = VIM.VirtualEthernetCardNetworkBackingInfo(:deviceName => bridge)
|
||||
device_spec = {:key => 0,
|
||||
:deviceInfo => {
|
||||
:label => "net" + card_num.to_s,
|
||||
:summary => bridge
|
||||
},
|
||||
:backing => backing,
|
||||
:addressType => 'manual'),
|
||||
:macAddress => mac }
|
||||
|
||||
device = case model.downcase
|
||||
when 'e1000'
|
||||
VIM.VirtualE1000(device_spec)
|
||||
when 'pcnet32'
|
||||
VIM.VirtualPCNet32(device_spec)
|
||||
when 'VirtualVmxnet'
|
||||
VIM.VirtualVmxnet(device_spec)
|
||||
end
|
||||
spec = {:deviceChange => [:operation => :add, :device => device]}
|
||||
|
||||
vm.ReconfigVM_Task(:spec => spec).wait_for_completion
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user