Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B #3175 Fix LXD shutdown #3171

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions src/vmm_mad/remotes/lib/lxd/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ def initialize(lxc, one, client)

@lxc = lxc
@one = one

@lxc_command = 'lxc'
@lxc_command.prepend 'sudo ' if client.snap

@containers = "#{@client.lxd_path}/storage-pools/default/containers"
@rootfs_dir = "#{@containers}/#{name}/rootfs"
@rootfs_dir = "#{@client.lxd_path}/storage-pools/default/containers/"\
"#{name}/rootfs"
@context_path = "#{@rootfs_dir}/context"
end

Expand Down Expand Up @@ -149,11 +150,15 @@ def update(wait: true, timeout: '')
wait?(@client.put("#{CONTAINERS}/#{name}", @lxc), wait, timeout)
end

# Returns the container current state
# Returns the container live state
def monitor
@client.get("#{CONTAINERS}/#{name}/state")
end

def check_status
monitor['metadata']['status'] if Container.exist?(name, @client)
end

# Retreive metadata for the container
def get_metadata
@lxc = @client.get("#{CONTAINERS}/#{name}")['metadata']
Expand Down Expand Up @@ -196,10 +201,27 @@ def stop(options = { :timeout => 120 })
def check_stop
return if status != 'Running'

if ARGV[-1] == '-f'
stop(:force => true)
else
stop
begin
if ARGV[-1] == '-f'
stop(:force => true)
else
stop
end
rescue => exception
OpenNebula.log_error exception

real_status = 'Unknown'

2.times do
# This call may return an operation output instead of a
# container data in case of timeout. The call breaks
# the container info. It needs to be read again

real_status = check_status
break if %w[Running Stopped].include? real_status
end

container.stop(:force => true) if real_status == 'Running'
end
end

Expand Down
20 changes: 5 additions & 15 deletions src/vmm_mad/remotes/lxd/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,14 @@ container = Container.new_from_xml(xml, client)

# ------------------------------------------------------------------------------
# Create Container in LXD
# - Already exists: gets container metadata from LXD and set OpenNebula
# configurations to update existing container.
# - Not exists. Creates new container in LXD.
# - Already exists: Raise error if container is detected running
# - Doesn't exist. Creates new container in LXD.
# ------------------------------------------------------------------------------
if Container.exist?(container.name, client)
OpenNebula.log_info('Overriding container')

config = container.config
devices = container.devices

container.get_metadata
running = container.check_status == 'Running'
raise 'A container with the same ID is already running' if running

err_msg = 'A container with the same ID is already running'
raise err_msg if container.status == 'Running'

container.config = config

container.devices = devices
OpenNebula.log_info('Overriding container')

container.update
else
Expand Down
28 changes: 7 additions & 21 deletions src/vmm_mad/remotes/lxd/shutdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,14 @@ client = LXDClient.new
container = Container.get(vm_name, xml, client)

# ------------------------------------------------------------------------------
# Stop the container & unmap devices if not a wild container
# Stop vnc connection and container & unmap devices if not a wild container
# ------------------------------------------------------------------------------
begin
container.check_stop
rescue => exception
OpenNebula.log_error exception
end

# This call may return an operation output instead of a container data
# in case of timeout. The call breaks the container attributes
# it needs to be read again
container = Container.get(vm_name, xml, client) # :status => "Sucess"
# Fixer call
container = Container.get(vm_name, xml, client) unless %w[Running Stopped].include? container.status

if !container.wild?
container.stop(:force => true) if container.status == 'Running'
container.vnc('stop')
container.check_stop

e = 'Failed to dismantle container storage'
raise "#{e}\n#{container}" unless container.setup_storage('unmap')
return if container.wild?

container.delete
end
raise 'Failed to dismantle container storage' unless \
container.setup_storage('unmap')

container.vnc('stop')
container.delete