Skip to content

Commit

Permalink
development: Additional LXD fixes. Minor refactor of check stop funct…
Browse files Browse the repository at this point in the history
…ionality
  • Loading branch information
dann1 authored and Ruben S. Montero committed Mar 28, 2019
1 parent 73e5844 commit 05258a1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
14 changes: 12 additions & 2 deletions src/vmm_mad/remotes/lib/lxd/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def initialize(lxc, one, client)
@lxc = lxc
@one = one
@lxc_command = 'lxc'
@lxc_command.prepend 'sudo' if client.snap
@lxc_command.prepend 'sudo ' if client.snap

@containers = "#{@client.lxd_path}/storage-pools/default/containers"
@rootfs_dir = "#{@containers}/#{name}/rootfs"
Expand Down Expand Up @@ -193,6 +193,16 @@ def stop(options = { :timeout => 120 })
end
end

def check_stop
return if status != 'Running'

if ARGV[-1] == '-f'
stop(:force => true)
else
stop
end
end

def restart(options = {})
change_state(__method__, options)
end
Expand Down Expand Up @@ -401,7 +411,7 @@ def vnc(signal)

# Deletes the switch port. Unlike libvirt, LXD doesn't handle this.
def del_bridge_port(nic)
return true unless /ovswitch/ =~ nic['VN_MAD']
return true unless /ovswitch/ =~ nic['VN_MAD']

cmd = 'sudo ovs-vsctl --if-exists del-port '\
"#{nic['BRIDGE']} #{nic['TARGET']}"
Expand Down
7 changes: 1 addition & 6 deletions src/vmm_mad/remotes/lxd/reboot
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,5 @@ container = Container.get(vm_name, container.config['user.xml'], client)
# ------------------------------------------------------------------------------
# Stop the container, start it
# ------------------------------------------------------------------------------
if ARGV[-1] == '-f'
container.stop(:force => true)
else
container.stop
end

container.check_stop
container.start
6 changes: 1 addition & 5 deletions src/vmm_mad/remotes/lxd/shutdown
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ container = Container.get(vm_name, xml, client)
# Stop the container & unmap devices if not a wild container
# ------------------------------------------------------------------------------
begin
if ARGV[-1] == '-f'
container.stop(:force => true)
else
container.stop
end
container.check_stop
rescue => exception
OpenNebula.log_error exception
end
Expand Down
4 changes: 2 additions & 2 deletions src/vnm_mad/remotes/lib/nic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ def get_info(vm)

config, e, s = Open3.capture3(cmd)

if s.exitstatus != 0 && e.include?('cannot create'\
if s.exitstatus != 0 && e.include?('cannot create '\
'user data directory')
cmd.prepend('sudo')
cmd.prepend('sudo ')
config, _e, _s = Open3.capture3(cmd)
end

Expand Down

0 comments on commit 05258a1

Please sign in to comment.