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

Fix LXD not handling nic removal from openvswitch bridges #3097

Merged
merged 6 commits into from
Mar 25, 2019
Merged
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: 22 additions & 1 deletion src/vmm_mad/remotes/lib/lxd/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ def start(options = {})

def stop(options = { :timeout => 120 })
change_state(__method__, options)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be called through the pre/post/clean scripts. This code should be moved to the owsirch network drivers

# 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 = {})
Expand Down Expand Up @@ -213,7 +218,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

#---------------------------------------------------------------------------
Expand Down Expand Up @@ -384,6 +390,21 @@ def vnc(signal)

private

# Deletes the switch port. Unlike libvirt, LXD doesn't handle this.
dann1 marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
3 changes: 2 additions & 1 deletion src/vmm_mad/remotes/lxd/reboot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down