feature #1691: Implements attach NIC actions for KVM

This commit is contained in:
Ruben S. Montero committed 2013-03-07 01:24:32 +01:00
1 parent 7ef496a5a2
commit 33b724ec4b
4 files changed
+154

No files matched your search

+2
View File
@@ -759,6 +759,8 @@ VMM_EXEC_KVM_SCRIPTS="src/vmm_mad/remotes/kvm/cancel \
src/vmm_mad/remotes/kvm/poll_ganglia \
src/vmm_mad/remotes/kvm/attach_disk \
src/vmm_mad/remotes/kvm/detach_disk \
src/vmm_mad/remotes/kvm/attach_nic \
src/vmm_mad/remotes/kvm/detach_nic \
src/vmm_mad/remotes/kvm/snapshot_create \
src/vmm_mad/remotes/kvm/snapshot_revert \
src/vmm_mad/remotes/kvm/snapshot_delete \
+90
View File
@@ -734,6 +734,96 @@ class ExecDriver < VirtualMachineDriver
action.run(steps)
end
#
# ATTACHNIC action to attach a new nic interface
#
def attach_nic(id, drv_message)
xml_data = decode(drv_message)
begin
source = xml_data.elements["VM/TEMPLATE/NIC[ATTACH='YES']/BRIDGE"]
mac = xml_data.elements["VM/TEMPLATE/NIC[ATTACH='YES']/MAC"]
source = source.text.strip
mac = mac.text.strip
rescue
send_message(action, RESULT[:failure], id,
"Error in #{ACTION[:attach_nic]}, BRIDGE and MAC needed in NIC")
return
end
model = xml_data.elements["VM/TEMPLATE/NIC[ATTACH='YES']/MODEL"]
model = model.text if !model.nil?
model = model.strip if !model.nil?
model = "-" if model.nil?
action = VmmAction.new(self, id, :attach_nic, drv_message)
steps=[
# Execute pre-attach networking setup
{
:driver => :vnm,
:action => :pre
},
# Attach the new NIC
{
:driver => :vmm,
:action => :attach_nic,
:parameters => [:deploy_id, mac, source, model]
},
# Execute post-boot networking setup
{
:driver => :vnm,
:action => :post,
:parameters => [:deploy_info],
:fail_actions => [
{
:driver => :vmm,
:action => :detach_nic,
:parameters => [:deploy_id, mac]
}
]
}
]
action.run(steps)
end
#
# DETACHNIC action to detach a nic interface
#
def detach_nic(id, drv_message)
xml_data = decode(drv_message)
begin
mac = xml_data.elements["VM/TEMPLATE/NIC[ATTACH='YES']/MAC"]
mac = mac.text.strip
rescue
send_message(action, RESULT[:failure], id,
"Error in #{ACTION[:detach_nic]}, MAC needed in NIC")
return
end
action = VmmAction.new(self, id, :detach_nic, drv_message)
steps=[
# Detach the NIC
{
:driver => :vmm,
:action => :detach_nic,
:parameters => [:deploy_id, mac]
},
# Clean networking setup
{
:driver => :vnm,
:action => :clean
}
]
action.run(steps)
end
private
def ensure_xpath(xml_data, id, action, xpath)
+34
View File
@@ -0,0 +1,34 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/kvmrc
source $(dirname $0)/../../scripts_common.sh
DOMAIN=$1
MAC=$2
SOURCE=$3
MODEL=$4
ATTACH_ARGS="--domain $DOMAIN --type bridge --source $SOURCE --mac $MAC"
if [ "$MODEL" != "-" ]; then
ATTACH_ARGS="$ATTACH_ARGS --model $MODEL"
fi
exec_and_log "virsh --connect $LIBVIRT_URI attach-interface $ATTACH_ARGS" \
"Could not attach NIC ($MAC) to $DOMAIN"
+28
View File
@@ -0,0 +1,28 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/kvmrc
source $(dirname $0)/../../scripts_common.sh
DOMAIN=$1
MAC=$2
DETACH_ARGS="--domain $DOMAIN --type bridge --mac $MAC"
exec_and_log "virsh --connect $LIBVIRT_URI detach-interface $DETACH_ARGS" \
"Could not attach NIC ($MAC) to $DOMAIN"