Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle LXD not removing host veth pair #3284

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/vmm_mad/remotes/lib/lxd/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -251,6 +256,8 @@ def attach_nic(mac)

@lxc['devices'].update(nic_config)

del_veth_pair(nic_xml['TARGET'])

update
end

Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/vmm_mad/remotes/lxd/detach_nic
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,4 +36,3 @@ client = LXDClient.new
container = Container.get(vm_name, xml, client)

container.detach_nic(mac)