1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

F #1684: LXD update

This commit is contained in:
Daniel Clavijo Coca 2018-12-15 10:20:18 -06:00 committed by Ruben S. Montero
parent 5a4740b8c7
commit 9c38e999f5
8 changed files with 44 additions and 39 deletions

View File

@ -36,12 +36,12 @@ class LXDClient
def initialize
paths = ['/var/lib/lxd', '/var/snap/lxd/common/lxd']
@socket = nil
@socket = nil
@lxd_path = nil
paths.each do |path|
begin
@socket = socket(path)
@socket = socket(path)
@lxd_path = path
break
rescue

View File

@ -71,7 +71,6 @@ class Container
@containers = "#{@client.lxd_path}/storage-pools/default/containers"
@rootfs_dir = "#{@containers}/#{name}/rootfs"
@context_path = "#{@rootfs_dir}/context"
end
@ -136,9 +135,10 @@ class Container
# Delete container
def delete(wait: true, timeout: '')
unless Dir.empty?(@rootfs_dir) || (Dir["#{@rootfs_dir}/*"] == [@context_path] && Dir.empty?(@context_path))
raise 'Container rootfs not empty'
end
cmd = "#{Mapper::COMMANDS[:lsblk]} -J"
_rc, o, _e = Command.execute(cmd, false)
raise "Container rootfs still mounted \n#{o}" if o.include?(@rootfs_dir)
wait?(@client.delete("#{CONTAINERS}/#{name}"), wait, timeout)
end
@ -331,10 +331,6 @@ class Container
def setup_disk(disk, operation)
return unless @one
ds_path = @one.ds_path
ds_id = @one.sysds_id
vm_id = @one.vm_id
disk_id = disk['DISK_ID']
if disk_id == @one.rootfs_id
@ -362,7 +358,12 @@ class Container
bin = 'svncterm_server'
server = "#{bin} #{vnc_args}"
Command.execute_once(server, true)
rc, _o, e = Command.execute_once(server, true)
if rc != 0
OpenNebula.log_error("do_map: #{e}")
return
end
lfd = Command.lock
@ -402,15 +403,14 @@ class Container
def new_disk_mapper(disk)
case disk['TYPE']
when 'FILE'
ds_path = @one.ds_path
ds_id = @one.sysds_id
ds = "#{@one.sysds_path}/#{@one.vm_id}/disk.#{disk['DISK_ID']}"
vm_id = @one.vm_id
disk_id = disk['DISK_ID']
rc, out, err = Command.execute("#{Mapper::COMMANDS[:file]} #{ds}", false)
ds = "#{ds_path}/#{ds_id}/#{vm_id}/disk.#{disk_id}"
_rc, out, _err = Command.execute("#{Mapper::COMMANDS[:file]} #{ds}", false)
unless rc.zero?
OpenNebula.log_error("do_map: #{err}")
return
end
case out
when /.*QEMU QCOW.*/
@ -423,7 +423,7 @@ class Container
OpenNebula.log "Using raw disk mapper for #{ds}"
return DiskRawMapper.new
else
OpenNebula.log('Unknown image format, trying raw filesystem mapper')
OpenNebula.log("Unknown #{out} image format, trying raw filesystem mapper")
return FSRawMapper.new
end
when 'RBD'

View File

@ -433,12 +433,7 @@ class Mapper
# @return [String] the canonical disk path for the given disk
def disk_source(one_vm, disk)
ds_path = one_vm.ds_path
ds_id = one_vm.sysds_id
vm_id = one_vm.vm_id
disk_id = disk['DISK_ID']
"#{ds_path}/#{ds_id}/#{vm_id}/disk.#{disk_id}"
"#{one_vm.sysds_path}/#{one_vm.vm_id}/disk.#{disk['DISK_ID']}"
end
# Adds path to the partition Hash. This is needed for lsblk version < 2.33

View File

@ -54,7 +54,7 @@ class Qcow2Mapper < Mapper
return true if rc.zero?
OpenNebula.log_error("do_unmap: #{err}")
OpenNebula.log_error("do_unmap: #{err}")
nil
end

View File

@ -25,7 +25,8 @@ class LXDConfiguration < Hash
:width => '800',
:height => '600',
:timeout => '300'
}
},
:datastore_location => '/var/lib/one/datastores'
}
def initialize
@ -42,7 +43,7 @@ end
# This class parses and wraps the information in the Driver action data
class OpenNebulaVM
attr_reader :xml, :vm_id, :vm_name, :sysds_id, :ds_path, :rootfs_id, :lxdrc, :sysds_path
attr_reader :xml, :vm_id, :vm_name, :sysds_id, :sysds_path, :rootfs_id, :lxdrc
#---------------------------------------------------------------------------
# Class Constructor
@ -52,16 +53,17 @@ class OpenNebulaVM
@xml = @xml.element('//VM')
@vm_id = @xml['//TEMPLATE/VMID']
@sysds_id = @xml['//HISTORY_RECORDS/HISTORY/DS_ID']
@vm_name = @xml['//DEPLOY_ID']
@vm_name = "one-#{@vm_id}" if @vm_name.empty?
return if wild?
# Load Driver configuration
@lxdrc = LXDConfiguration.new
@sysds_id = @xml['//HISTORY_RECORDS/HISTORY/DS_ID']
@sysds_path = "#{@lxdrc[:datastore_location]}/#{@sysds_id}"
return if wild?
# Sets the DISK ID of the root filesystem
disk = @xml.element('//TEMPLATE/DISK')
@ -206,7 +208,7 @@ class OpenNebulaVM
return if cid.empty?
source = "#{@ds_path}/#{@sysds_id}/#{@vm_id}/mapper/disk.#{cid}"
source = disk_mountpoint(cid)
hash['context'] = {
'type' => 'disk',
@ -216,7 +218,7 @@ class OpenNebulaVM
end
def disk_mountpoint(disk_id)
"#{@ds_path}/#{@sysds_id}/#{@vm_id}/mapper/disk.#{disk_id}"
"#{@sysds_path}/#{@vm_id}/mapper/disk.#{disk_id}"
end
# Creates a disk hash from DISK xml element
@ -310,7 +312,7 @@ class OpenNebulaVM
if !data.empty? && type.casecmp('lxd').zero?
begin
raw_data = JSON.parse("{#{data}}")
rescue StandardError
rescue
end
end
@ -340,7 +342,7 @@ class OpenNebulaVM
pass = '-' unless pass && !pass.empty?
case signal
when 'start'
when 'start'
command = @lxdrc[:vnc][:command]
"#{data['PORT']} #{pass} lxc exec #{@vm_name} #{command}\n"
when 'stop'

View File

@ -27,4 +27,12 @@
:command: /bin/bash
:width: 800
:height: 600
:timeout: 300
:timeout: 300
################################################################################
# OpenNebula Configuration Options
################################################################################
#
# Default path for the datastores. This only need to be change if the
# corresponding value in oned.conf has been modified.
:datastore_location: /var/lib/one/datastores

View File

@ -31,7 +31,7 @@ client = LXDClient.new
container = Container.get(vm_name, nil, client)
# ------------------------------------------------------------------------------
# Stop the container, start it and reset VNC server
# Stop the container, start it
# ------------------------------------------------------------------------------
if ARGV[-1] == '-f'
container.stop(:force => true)

View File

@ -40,6 +40,6 @@ if iso_path != ''
raise 'Failed to attach context' unless container.attach_context
rc, _out, err = container.exec('one-contextd local 2>/dev/null')
rc, _out, err = container.exec('one-contextd local')
raise err unless rc.zero?
end