diff --git a/share/examples/network_hooks/99-lxd_clean.rb b/share/examples/network_hooks/99-lxd_clean.rb index 4d56010b77a..bdb436951ba 100755 --- a/share/examples/network_hooks/99-lxd_clean.rb +++ b/share/examples/network_hooks/99-lxd_clean.rb @@ -7,7 +7,6 @@ def clean_host_nic(veth) cmd = "ip link show #{veth}" - _o, _e, s = Open3.capture3(cmd) return unless s == 0 @@ -15,9 +14,8 @@ def clean_host_nic(veth) cmd = "sudo ip link delete #{veth}" OpenNebula.log "Found lingering nic #{veth}\n Running #{cmd}" - o, e, _s = Open3.capture3(cmd) - - OpenNebula.log "#{o}\n#{e}" + o, e, s = Open3.capture3(cmd) + OpenNebula.log "#{o}\n#{e}" unless s == 0 end ############### @@ -40,16 +38,13 @@ def clean_host_nic(veth) nics << nic end -# Detect if hotplug or shutdown -detach = nil +# Detect if shutdown/reboot or nic hotplug calls vnm clean. +# Assumes only 1 nic detachable at once. nics.each do |nic| - next unless nic[:nic][:attach] == 'YES' - - detach = nic[:nic][:target] + if nic[:nic][:attach] == 'YES' + clean_host_nic(nic[:nic][:target]) + exit 0 + end end -if detach # only clean detached nic - clean_host_nic(detach) -else # clean all nics - nics.each {|nic| clean_host_nic(nic[:nic][:target]) } -end +nics.each {|nic| clean_host_nic(nic[:nic][:target]) } diff --git a/src/vmm_mad/remotes/lib/lxd/container.rb b/src/vmm_mad/remotes/lib/lxd/container.rb index bfee50a7242..5d746e2530c 100644 --- a/src/vmm_mad/remotes/lib/lxd/container.rb +++ b/src/vmm_mad/remotes/lib/lxd/container.rb @@ -208,12 +208,7 @@ def show_log def start(options = {}) OpenNebula.log '--- Starting container ---' - operation = change_state(__method__, options) - - transition_end - update - - operation + change_state(__method__, options) end def stop(options = { :timeout => 120 }) @@ -232,8 +227,8 @@ def check_stop(force) begin stop(:force => force) - rescue => exception - OpenNebula.log_error "LXD Error: #{exception}" + rescue => e + OpenNebula.log_error "LXD Error: #{e}" real_status = 'Unknown' @@ -248,8 +243,8 @@ def check_stop(force) begin stop(:force => true) if real_status == 'Running' - rescue => exception - error = "LXD Error: Cannot shut down container #{exception}" + rescue => e + error = "LXD Error: Cannot shut down container #{e}" OpenNebula.log_error error end @@ -263,12 +258,12 @@ def reboot(force) start config['user.reboot_state'] = 'RUNNING' - transition_start + transition_end # container reached a final state else check_stop(force) config['user.reboot_state'] = 'STOPPED' - transition_end + transition_start # container will be started later end update @@ -555,8 +550,9 @@ def new_disk_mapper(disk) when 'FILE', 'BLOCK' ds = @one.disk_source(disk) + cmd = "#{Mapper::COMMANDS[:file]} #{ds}" - rc, out, err = Command.execute("#{Mapper::COMMANDS[:file]} #{ds}", false) + rc, out, err = Command.execute(cmd, false) unless rc.zero? OpenNebula.log_error("#{__method__} #{err}") diff --git a/src/vmm_mad/remotes/lxd/deploy b/src/vmm_mad/remotes/lxd/deploy index a31e63577c8..6dad3d99c32 100755 --- a/src/vmm_mad/remotes/lxd/deploy +++ b/src/vmm_mad/remotes/lxd/deploy @@ -69,13 +69,13 @@ else begin operation = container.start raise operation if container.status != 'Running' - rescue StandardError => exception + rescue e # TODO: Improve wait condition sleep 5 # Wait for LXD to revert non-rootfs disks mountpoint container.clean - raise exception + raise e end end @@ -84,6 +84,7 @@ end # Updates container configuration with the OpenNebulaVM description # ------------------------------------------------------------------------------ container.config.update('user.xml' => xml) +container.transition_end unless container.wild? container.update container.vnc('start') diff --git a/src/vmm_mad/remotes/lxd/poll b/src/vmm_mad/remotes/lxd/poll index f89b482966f..929b2b570e8 100755 --- a/src/vmm_mad/remotes/lxd/poll +++ b/src/vmm_mad/remotes/lxd/poll @@ -108,6 +108,8 @@ module LXD # * 'stopped' container not running or in the process of shutting down. # * 'failure' container have failed. def get_state(container) + return '-' if container.config['user.one_status'] == '0' + begin status = container.status.downcase rescue StandardError @@ -121,8 +123,6 @@ module LXD state = 'p' when 'stopped' state = 'd' - - state = '-' if container.config['user.one_status'] == '0' when 'failure' state = 'e' else @@ -227,6 +227,12 @@ module LXD memory end + def unindent(str) + m = str.match(/^(\s*)/) + spaces = m[1].size + str.gsub!(/^ {#{spaces}}/, '') + end + def to_one(container) name = container.name arch = container.architecture @@ -248,16 +254,15 @@ module LXD cpu = cpu.chomp('%').to_f / 100 mem = parse_memory(mem) - template = <