From 7710d4eb9fdcf54aa2caa918f8fd26361a161ef6 Mon Sep 17 00:00:00 2001 From: Daniel Clavijo Coca Date: Thu, 28 Mar 2019 05:14:32 -0600 Subject: [PATCH] development: Additional LXD fixes. Minor refactor of check stop functionality (cherry picked from commit 05258a1c9170e5fa4af474d0a271ef9235cfaaad) --- src/vmm_mad/remotes/lib/lxd/container.rb | 14 ++++++++++++-- src/vmm_mad/remotes/lxd/reboot | 7 +------ src/vmm_mad/remotes/lxd/shutdown | 6 +----- src/vnm_mad/remotes/lib/nic.rb | 4 ++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/vmm_mad/remotes/lib/lxd/container.rb b/src/vmm_mad/remotes/lib/lxd/container.rb index e7834f658e..890f37183a 100644 --- a/src/vmm_mad/remotes/lib/lxd/container.rb +++ b/src/vmm_mad/remotes/lib/lxd/container.rb @@ -69,7 +69,7 @@ class Container @lxc = lxc @one = one @lxc_command = 'lxc' - @lxc_command.prepend 'sudo' if client.snap + @lxc_command.prepend 'sudo ' if client.snap @containers = "#{@client.lxd_path}/storage-pools/default/containers" @rootfs_dir = "#{@containers}/#{name}/rootfs" @@ -193,6 +193,16 @@ class Container end end + def check_stop + return if status != 'Running' + + if ARGV[-1] == '-f' + stop(:force => true) + else + stop + end + end + def restart(options = {}) change_state(__method__, options) end @@ -401,7 +411,7 @@ class Container # Deletes the switch port. Unlike libvirt, LXD doesn't handle this. def del_bridge_port(nic) - return true unless /ovswitch/ =~ nic['VN_MAD'] + return true unless /ovswitch/ =~ nic['VN_MAD'] cmd = 'sudo ovs-vsctl --if-exists del-port '\ "#{nic['BRIDGE']} #{nic['TARGET']}" diff --git a/src/vmm_mad/remotes/lxd/reboot b/src/vmm_mad/remotes/lxd/reboot index 48758cf7c9..7a107b1c19 100755 --- a/src/vmm_mad/remotes/lxd/reboot +++ b/src/vmm_mad/remotes/lxd/reboot @@ -34,10 +34,5 @@ container = Container.get(vm_name, container.config['user.xml'], client) # ------------------------------------------------------------------------------ # Stop the container, start it # ------------------------------------------------------------------------------ -if ARGV[-1] == '-f' - container.stop(:force => true) -else - container.stop -end - +container.check_stop container.start diff --git a/src/vmm_mad/remotes/lxd/shutdown b/src/vmm_mad/remotes/lxd/shutdown index b1963384bd..bf5885d58f 100755 --- a/src/vmm_mad/remotes/lxd/shutdown +++ b/src/vmm_mad/remotes/lxd/shutdown @@ -37,11 +37,7 @@ container = Container.get(vm_name, xml, client) # Stop the container & unmap devices if not a wild container # ------------------------------------------------------------------------------ begin - if ARGV[-1] == '-f' - container.stop(:force => true) - else - container.stop - end + container.check_stop rescue => exception OpenNebula.log_error exception end diff --git a/src/vnm_mad/remotes/lib/nic.rb b/src/vnm_mad/remotes/lib/nic.rb index ac7b8d787d..756bff0bd4 100644 --- a/src/vnm_mad/remotes/lib/nic.rb +++ b/src/vnm_mad/remotes/lib/nic.rb @@ -116,9 +116,9 @@ module VNMMAD config, e, s = Open3.capture3(cmd) - if s.exitstatus != 0 && e.include?('cannot create'\ + if s.exitstatus != 0 && e.include?('cannot create '\ 'user data directory') - cmd.prepend('sudo') + cmd.prepend('sudo ') config, _e, _s = Open3.capture3(cmd) end