Skip to content

Commit

Permalink
F #3189: Fix LXD net patch (#3897)
Browse files Browse the repository at this point in the history
  • Loading branch information
dann1 authored and Ruben S. Montero committed Nov 4, 2019
1 parent 936df07 commit ffaed2d
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions share/examples/network_hooks/99-lxd_clean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,28 @@
exit 0 unless vm.hypervisor == 'lxd'
OpenNebula.log 'running lxd network post cleanup'

# Detect nics from XML
nics = []
vm.nics.each do |nic|
next unless nic[:nic]

veth = nic[:nic][:target]
nics << nic
end

# Detect if hotplug or shutdown
detach = nil
nics.each do |nic|
next unless nic[:nic][:attach] == 'YES'

detach = nic[:nic][:target]
end

def clean_host_nic(veth)
cmd = "ip link show #{veth}"

_o, _e, s = Open3.capture3(cmd)

next unless s == 0
return unless s == 0

cmd = "sudo ip link delete #{veth}"
OpenNebula.log "Found lingering nic #{veth}\n Running #{cmd}"
Expand All @@ -31,3 +43,9 @@

OpenNebula.log "#{o}\n#{e}"
end

if detach # only clean detached nic
clean_host_nic(detach)
else # clean all nics
nics.each {|nic| clean_host_nic(nic[:nic][:target]) }
end

0 comments on commit ffaed2d

Please sign in to comment.