Skip to content

Commit

Permalink
F #3297: Minor Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dann1 committed Jan 21, 2020
1 parent 96528c3 commit 1227810
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
17 changes: 8 additions & 9 deletions src/vmm_mad/remotes/lib/lxd/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,9 @@ def setup_storage(operation)
return nil unless setup_disk(disk, operation)
end

return true unless @one.has_context?
return true unless @one.context?

context = @one.get_context_disk
mapper = FSRawMapper.new
mapper = FSRawMapper.new

if operation == 'map'
mk_context_dir = "#{Mapper::COMMANDS[:su_mkdir]} #{@context_path}"
Expand All @@ -318,7 +317,7 @@ def setup_storage(operation)
end
end

mapper.public_send(operation, @one, context, context_source)
mapper.public_send(operation, @one, @one.context_disk, context_source)
end

# Generate the context devices and maps the context the device
Expand All @@ -332,14 +331,14 @@ def attach_context
true
end

# Removes the context section from the LXD configuration and unmap the
# context device
# Removes the context section from the LXD configuration and
# unmaps the context device
def detach_context
return true unless @one.has_context?
return true unless @one.context?

context_src = context_source

@lxc['devices'].delete('context')['source']
@lxc['devices'].delete('context')
update

mapper = FSRawMapper.new
Expand Down Expand Up @@ -548,7 +547,7 @@ def new_disk_mapper(disk)
end

def context_source
return unless @one.has_context?
return unless @one.context?

disk_source('context')
end
Expand Down
2 changes: 2 additions & 0 deletions src/vmm_mad/remotes/lib/lxd/mapper/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,15 @@ def update_partable(dev)
Command.execute(cmd, false)
end

# Formats a block device
def mkfs(device, format)
cmd = "#{COMMANDS[:mkfs]}.#{format} #{device}"
rc, o, e = Command.execute(cmd, false)

return true if rc.zero?

OpenNebula.log_error "Failed to format #{device}\n#{o}\n#{e}"
false
end

end
12 changes: 6 additions & 6 deletions src/vmm_mad/remotes/lib/lxd/opennebula_vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def initialize(xml)
@rootfs_id = boot_order.split(',')[0][-1] unless boot_order.empty?
end

def has_context?
def context?
!@xml['//TEMPLATE/CONTEXT/DISK_ID'].empty?
end

Expand Down Expand Up @@ -157,7 +157,7 @@ def network(hash)
# Creates a nic hash from NIC xml root
def nic(info)
eth = {
'name' => "eth#{info['NIC_ID']}",
'name' => "eth#{info['NIC_ID']}",
'host_name' => info['TARGET'],
'parent' => info['BRIDGE'],
'hwaddr' => info['MAC'],
Expand Down Expand Up @@ -195,19 +195,19 @@ def get_disks_by(filter, value)
end
end

def get_context_disk
# Context disk XML
def context_disk
@xml.element('//TEMPLATE/CONTEXT')
end

# Disk XML array
def get_disks
@xml.elements('//TEMPLATE/DISK')
end

# Sets up the storage devices configuration in devices
def storage(hash)
disks = @xml.elements('//TEMPLATE/DISK')

disks.each do |n|
get_disks.each do |n|
next if swap?(n)

hash.update(disk(n, nil, nil))
Expand Down

0 comments on commit 1227810

Please sign in to comment.