From 082fbe477eaeed6f8ddd6531a6418a7d3ae36480 Mon Sep 17 00:00:00 2001 From: Daniel Clavijo Coca Date: Mon, 25 Mar 2019 08:18:18 -0600 Subject: [PATCH] B #3058: Fix LXD not handling nic removal from openvswitch bridges (#3097) (cherry picked from commit 31a1cb9db7953dffec96255ad9b3dbc8d17a9ae3) --- src/vmm_mad/remotes/lib/lxd/container.rb | 23 ++++++++++++++++++++++- src/vmm_mad/remotes/lxd/reboot | 3 ++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/vmm_mad/remotes/lib/lxd/container.rb b/src/vmm_mad/remotes/lib/lxd/container.rb index 6c5edc87472..50b8fff4af9 100644 --- a/src/vmm_mad/remotes/lib/lxd/container.rb +++ b/src/vmm_mad/remotes/lib/lxd/container.rb @@ -175,6 +175,11 @@ def start(options = {}) def stop(options = { :timeout => 120 }) change_state(__method__, options) + + # Remove nic from ovs-switch if needed + @one.get_nics.each do |nic| + del_bridge_port(nic) # network driver matching implemented here + end end def restart(options = {}) @@ -211,7 +216,8 @@ def detach_nic(mac) device.include?('eth') && config['hwaddr'] == mac end - update + # Removes nic from ovs-switch if needed + update if del_bridge_port(@one.get_nic_by_mac(mac)) end #--------------------------------------------------------------------------- @@ -382,6 +388,21 @@ def vnc(signal) private + # Deletes the switch port. Unlike libvirt, LXD doesn't handle this. + def del_bridge_port(nic) + return true unless /ovswitch/ =~ nic['VN_MAD'] + + cmd = 'sudo ovs-vsctl --if-exists del-port '\ + "#{nic['BRIDGE']} #{nic['TARGET']}" + + rc, _o, e = Command.execute(cmd, false) + + return true if rc.zero? + + OpenNebula.log_error "#{__method__}: #{e}" + false + end + # Waits or no for response depending on wait value def wait?(response, wait, timeout) @client.wait(response, timeout) unless wait == false diff --git a/src/vmm_mad/remotes/lxd/reboot b/src/vmm_mad/remotes/lxd/reboot index 280fc6682c6..48758cf7c92 100755 --- a/src/vmm_mad/remotes/lxd/reboot +++ b/src/vmm_mad/remotes/lxd/reboot @@ -23,12 +23,13 @@ require 'container' require_relative '../../scripts_common' # ------------------------------------------------------------------------------ -# Action Arguments, STDIN includes XML description of the OpenNebula VM +# Action Arguments, STDIN doesn't include XML description of the OpenNebula VM # ------------------------------------------------------------------------------ vm_name = ARGV[0] client = LXDClient.new container = Container.get(vm_name, nil, client) +container = Container.get(vm_name, container.config['user.xml'], client) # ------------------------------------------------------------------------------ # Stop the container, start it