From a593fcdeb46bfa05cf06330efabf5f003bd64dad Mon Sep 17 00:00:00 2001 From: Daniel Clavijo Coca Date: Sun, 28 Apr 2019 14:08:57 -0500 Subject: [PATCH 1/2] Lint --- src/vmm_mad/remotes/lxd/detach_nic | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vmm_mad/remotes/lxd/detach_nic b/src/vmm_mad/remotes/lxd/detach_nic index e98808ee2d2..f012e6e8bf9 100755 --- a/src/vmm_mad/remotes/lxd/detach_nic +++ b/src/vmm_mad/remotes/lxd/detach_nic @@ -20,7 +20,7 @@ $LOAD_PATH.unshift File.dirname(__FILE__) require 'container' -require_relative '../../scripts_common' +require_relative '../../scripts_common' # ------------------------------------------------------------------------------ # Action Arguments, STDIN includes XML description of the OpenNebula VM @@ -36,4 +36,3 @@ client = LXDClient.new container = Container.get(vm_name, xml, client) container.detach_nic(mac) - From ea5dacab0feed1275d1742bd7951682c95e1bddc Mon Sep 17 00:00:00 2001 From: Daniel Clavijo Coca Date: Sun, 28 Apr 2019 17:39:40 -0500 Subject: [PATCH 2/2] B #3189 delete host veth pair if found previous to container status change --- src/vmm_mad/remotes/lib/lxd/container.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/vmm_mad/remotes/lib/lxd/container.rb b/src/vmm_mad/remotes/lib/lxd/container.rb index 302b136c4af..8a183ad3160 100644 --- a/src/vmm_mad/remotes/lib/lxd/container.rb +++ b/src/vmm_mad/remotes/lib/lxd/container.rb @@ -186,6 +186,11 @@ def show_log # Contianer Status Control #--------------------------------------------------------------------------- def start(options = {}) + # Remove veth pair from host if needed + @one.get_nics.each do |nic| + del_veth_pair(nic['TARGET']) + end + change_state(__method__, options) end @@ -251,6 +256,8 @@ def attach_nic(mac) @lxc['devices'].update(nic_config) + del_veth_pair(nic_xml['TARGET']) + update end @@ -446,6 +453,22 @@ def del_bridge_port(nic) false end + # Removes lxd host side nic if LXD hasn't removed it + def del_veth_pair(host_nic) + cmd = "ip link show #{host_nic}" + rc, _o, _e = Command.execute(cmd, false) + + return true unless rc.zero? + + cmd = "sudo ip link delete #{host_nic}" + rc, _o, e = Command.execute(cmd, false) + + return true if rc.zero? + + OpenNebula.log "#{__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