From b098a917ddd5a13bc05e80f0cccd4b13a508007d Mon Sep 17 00:00:00 2001 From: Daniel Clavijo Coca Date: Mon, 19 Aug 2019 00:16:23 -0500 Subject: [PATCH] B #3189: Beta LXD post net cleanup --- src/vnm_mad/remotes/lib/lxd_clean.rb | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/vnm_mad/remotes/lib/lxd_clean.rb b/src/vnm_mad/remotes/lib/lxd_clean.rb index c4f3e7d3c2b..8733d746bb5 100644 --- a/src/vnm_mad/remotes/lib/lxd_clean.rb +++ b/src/vnm_mad/remotes/lib/lxd_clean.rb @@ -3,11 +3,31 @@ $LOAD_PATH << "#{__dir__}/../.." require 'vnmmad' +require 'open3' template64 = STDIN.read vnm = VNMMAD::NoVLANDriver.from_base64(template64, nil, nil) -exit 0 unless vnm.vm.hypervisor == 'lxd' -STDERR.puts 'running lxd nic clean hook' +vm = vnm.vm -exit 0 +exit 0 unless vm.hypervisor == 'lxd' +OpenNebula.log 'running lxd network post cleanup' + +vm.nics.each do |nic| + next unless nic[:nic] + + veth = nic[:nic][:target] + + cmd = "ip link show #{veth}" + + _o, _e, s = Open3.capture3(cmd) + + next unless s == 0 + + cmd = "ip link delete #{veth}" + OpenNebula.log "Found lingering nic #{veth}\n Running #{cmd}" + + o, e, _s = Open3.capture3(cmd) + + OpenNebula.log "#{o}\n#{e}" +end