1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

B #3058: Fix LXD not handling nic removal from openvswitch bridges (#3097)

(cherry picked from commit 31a1cb9db7953dffec96255ad9b3dbc8d17a9ae3)
This commit is contained in:
Daniel Clavijo Coca 2019-03-25 08:18:18 -06:00 committed by Ruben S. Montero
parent d2a33ecbb5
commit 082fbe477e
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
2 changed files with 24 additions and 2 deletions

View File

@ -175,6 +175,11 @@ class Container
def stop(options = { :timeout => 120 })
change_state(__method__, options)
# 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 = {})
@ -211,7 +216,8 @@ class Container
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
#---------------------------------------------------------------------------
@ -382,6 +388,21 @@ class Container
private
# Deletes the switch port. Unlike libvirt, LXD doesn't handle this.
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

View File

@ -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