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

F #3189: Fix LXD status report (#4210)

* F #3189: Fix lxd net hook

* F #3189: Fix LXD transitions

* F #3189:  Prioritize transition flag over status

* M #: Lint

* M #: Remove WIP hook

* M #: C7 compat

* F #3189: Remove flag only on native containers

(cherry picked from commit e594c885409c56e057ce8b1932d1c313a2b1cf83)
This commit is contained in:
Daniel Clavijo Coca 2020-02-19 10:54:34 -06:00 committed by Ruben S. Montero
parent 7df413faeb
commit 9986eee7b4
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
4 changed files with 38 additions and 41 deletions

View File

@ -7,7 +7,6 @@ require 'open3'
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 @@ vm.nics.each do |nic|
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]) }

View File

@ -208,12 +208,7 @@ class Container
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 @@ class Container
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 @@ class Container
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 @@ class Container
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 @@ class Container
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}")

View File

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

View File

@ -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 = <<EOT
NAME="#{name}"
CPU=#{cpu}
VCPU=#{vcpu}
MEMORY=#{mem}
HYPERVISOR="lxd"
IMPORT_VM_ID="#{name}"
OS=[ARCH="#{arch}"]
EOT
template
unindent(<<-EOT)
NAME="#{name}"
CPU=#{cpu}
VCPU=#{vcpu}
MEMORY=#{mem}
HYPERVISOR="lxd"
IMPORT_VM_ID="#{name}"
OS=[ARCH="#{arch}"]
EOT
end
end