diff --git a/src/vmm_mad/remotes/lib/lxd/container.rb b/src/vmm_mad/remotes/lib/lxd/container.rb index 6c5edc87472..50b8fff4af9 100644 --- a/src/vmm_mad/remotes/lib/lxd/container.rb +++ b/src/vmm_mad/remotes/lib/lxd/container.rb @@ -175,6 +175,11 @@ def start(options = {}) 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 @@ 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 #--------------------------------------------------------------------------- @@ -382,6 +388,21 @@ def vnc(signal) 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 diff --git a/src/vmm_mad/remotes/lxd/reboot b/src/vmm_mad/remotes/lxd/reboot index 280fc6682c6..48758cf7c92 100755 --- a/src/vmm_mad/remotes/lxd/reboot +++ b/src/vmm_mad/remotes/lxd/reboot @@ -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