mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
(cherry picked from commit 5fa02872d1f5b4f34ebb2fe824a4db27619ec2b1)
This commit is contained in:
parent
31880fb5a6
commit
29005aba77
@ -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
|
||||
|
@ -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)
|
||||
|
@ -40,6 +40,7 @@ container.vnc('stop')
|
||||
|
||||
force = false
|
||||
force = true if ARGV[-1] == '-f'
|
||||
|
||||
container.check_stop(force)
|
||||
|
||||
exit 0 if container.wild?
|
||||
|
Loading…
x
Reference in New Issue
Block a user