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

F #1684: Changes to make LXD driver compatible with ruby 1.9

This commit is contained in:
Daniel Clavijo Coca 2018-12-20 02:28:38 -06:00 committed by Ruben S. Montero
parent f6f10bd02c
commit bdaaf11c25
6 changed files with 16 additions and 25 deletions

View File

@ -276,7 +276,7 @@ class Container
end
# Attach disk to container (ATTACH = YES) in VM description
def attach_disk(source)
def attach_disk
disk_element = hotplug_disk
raise 'Missing hotplug info' unless disk_element
@ -284,13 +284,7 @@ class Container
status = setup_disk(disk_element, 'map')
return unless status
source2 = source.dup
if source
mapper_location = source2.index('/disk.')
source2.insert(mapper_location, '/mapper')
end
disk_hash = @one.disk(disk_element, source2, nil)
disk_hash = @one.disk(disk_element, nil, nil)
@lxc['devices'].update(disk_hash)

View File

@ -191,12 +191,7 @@ class Mapper
device = ''
real_path = directory
ds = one_vm.sysds_path
if File.symlink?(ds)
real_ds = File.readlink(ds)
real_path = real_ds + real_path.split(ds)[-1] if real_path.include?(ds)
end
real_path = File.realpath(directory) if File.symlink?(one_vm.sysds_path)
sys_parts.each {|d|
if d['mountpoint'] == real_path
@ -344,7 +339,7 @@ class Mapper
return false
end
if out.match?(path)
if out.include?(path)
OpenNebula.log_error("mount_dev: Mount detected in #{path}")
return false
end
@ -397,14 +392,14 @@ class Mapper
if rc != 0 || o.empty?
OpenNebula.log_error("lsblk: #{e}")
return nil
return
end
partitions = nil
begin
partitions = JSON.parse(o)['blockdevices']
if !device.empty?
partitions = partitions[0]
@ -414,13 +409,13 @@ class Mapper
partitions = [partitions]
end
partitions.delete_if { |p|
p['fstype'].casecmp?('swap') if p['fstype']
partitions.delete_if {|p|
p['fstype'].casecmp('swap').zero? if p['fstype']
}
end
rescue
OpenNebula.log_error("lsblk: error parsing lsblk -OJ #{device}")
return nil
return
end
# Fix for lsblk paths for version < 2.33

View File

@ -218,7 +218,9 @@ class OpenNebulaVM
end
def disk_mountpoint(disk_id)
"#{@sysds_path}/#{@vm_id}/mapper/disk.#{disk_id}"
datastore = @sysds_path
datastore = File.readlink(@sysds_path) if File.symlink?(@sysds_path)
"#{datastore}/#{@vm_id}/mapper/disk.#{disk_id}"
end
# @return [String] the canonical disk path for the given disk
@ -353,7 +355,7 @@ class OpenNebulaVM
# Creates or closes a connection to a container rfb port depending on signal
def vnc_command(signal)
data = @xml.element('//TEMPLATE/GRAPHICS')
return unless data && data['PORT'] && data['TYPE'] && data['TYPE'].casecmp?('vnc')
return unless data && data['PORT'] && data['TYPE'] && data['TYPE'].casecmp('vnc').zero?
pass = data['PASSWD']
pass = '-' unless pass && !pass.empty?

View File

@ -37,4 +37,4 @@ xml = STDIN.read
client = LXDClient.new
container = Container.get(vm_name, xml, client)
raise 'failed to attach disk' unless container.attach_disk(image_path)
raise 'failed to attach disk' unless container.attach_disk

View File

@ -84,7 +84,7 @@ module LXD
values[:memory] = get_memory(name)
values[:netrx], values[:nettx] = get_net_statistics(vmd['network'])
running_containers.append(name)
running_containers.push(name)
vms_info[name][:memory] = values[:memory]
end

View File

@ -41,5 +41,5 @@ if iso_path != ''
raise 'Failed to attach context' unless container.attach_context
rc, _out, err = container.exec('one-contextd local')
raise err unless rc.zero?
OpenNebula.log_error "Failed to run contextualization\n#{err}" unless rc.zero?
end