diff --git a/src/vmm_mad/remotes/lib/lxd/container.rb b/src/vmm_mad/remotes/lib/lxd/container.rb index b93a536ee9..bfee50a724 100644 --- a/src/vmm_mad/remotes/lib/lxd/container.rb +++ b/src/vmm_mad/remotes/lib/lxd/container.rb @@ -129,7 +129,8 @@ class Container # Create a container without a base image def create(wait: true, timeout: '') @lxc['source'] = { 'type' => 'none' } - @lxc['config']['user.one_status'] = '0' + + transition_start # not ready to report status yet wait?(@client.post(CONTAINERS, @lxc), wait, timeout) @@ -209,7 +210,7 @@ class Container operation = change_state(__method__, options) - @lxc['config'].delete('user.one_status') + transition_end update operation @@ -217,6 +218,7 @@ class Container def stop(options = { :timeout => 120 }) OpenNebula.log '--- Stopping container ---' + change_state(__method__, options) # Remove nic from ovs-switch if needed @@ -229,13 +231,9 @@ class Container return if status != 'Running' begin - if force == '-f' - stop(:force => true) - else - stop - end + stop(:force => force) rescue => exception - OpenNebula.log_error exception + OpenNebula.log_error "LXD Error: #{exception}" real_status = 'Unknown' @@ -248,10 +246,34 @@ class Container break if %w[Running Stopped].include? real_status end - stop(:force => true) if real_status == 'Running' + begin + stop(:force => true) if real_status == 'Running' + rescue => exception + error = "LXD Error: Cannot shut down container #{exception}" + + OpenNebula.log_error error + end end end + # Extended reboot required for OpenNebula execution flow + def reboot(force) + case config['user.reboot_state'] + when 'STOPPED' + start + + config['user.reboot_state'] = 'RUNNING' + transition_start + else + check_stop(force) + + config['user.reboot_state'] = 'STOPPED' + transition_end + end + + update + end + def restart(options = {}) change_state(__method__, options) end @@ -470,6 +492,17 @@ class Container update end + # Flags a container indicating current status not definitive + # Stalls monitoring status query. Requires updating the container + def transition_start + @lxc['config']['user.one_status'] = '0' + end + + # Removes transient state flag. Requires updating the container. + def transition_end + @lxc['config'].delete('user.one_status') + end + private def idmaps_file diff --git a/src/vmm_mad/remotes/lxd/reboot b/src/vmm_mad/remotes/lxd/reboot index 3e08de59a1..ac847d63ec 100755 --- a/src/vmm_mad/remotes/lxd/reboot +++ b/src/vmm_mad/remotes/lxd/reboot @@ -31,18 +31,7 @@ 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 -# ------------------------------------------------------------------------------ -case container.config['user.reboot_state'] -when 'STOPPED' - container.start - container.config['user.reboot_state'] = 'RUNNING' -else - force = false - force = true if ARGV[-1] == '-f' - container.check_stop(force) - container.config['user.reboot_state'] = 'STOPPED' -end +force = false +force = true if ARGV[-1] == '-f' -container.update +container.reboot(force) diff --git a/src/vmm_mad/remotes/lxd/shutdown b/src/vmm_mad/remotes/lxd/shutdown index caeff44db3..9089d1f21c 100755 --- a/src/vmm_mad/remotes/lxd/shutdown +++ b/src/vmm_mad/remotes/lxd/shutdown @@ -40,6 +40,7 @@ container.vnc('stop') force = false force = true if ARGV[-1] == '-f' + container.check_stop(force) exit 0 if container.wild?