class Bosh::Stemcell::DiskImage
Attributes
device[R]
image_file_path[R]
image_mount_point[R]
shell[R]
verbose[R]
Public Class Methods
new(options)
click to toggle source
# File lib/bosh/stemcell/disk_image.rb, line 10 def initialize(options) @image_file_path = options.fetch(:image_file_path) @image_mount_point = options.fetch(:image_mount_point, Dir.mktmpdir) @verbose = options.fetch(:verbose, false) @shell = Bosh::Core::Shell.new end
Public Instance Methods
mount()
click to toggle source
# File lib/bosh/stemcell/disk_image.rb, line 17 def mount device_path = stemcell_loopback_device_name mount_command = "sudo mount #{device_path} #{image_mount_point}" shell.run(mount_command, output_command: verbose) rescue => e raise e unless e.message.include?(mount_command) sleep 0.5 shell.run(mount_command, output_command: verbose) end
unmount()
click to toggle source
# File lib/bosh/stemcell/disk_image.rb, line 28 def unmount shell.run("sudo umount #{image_mount_point}", output_command: verbose) ensure unmap_image end
while_mounted() { |self| ... }
click to toggle source
# File lib/bosh/stemcell/disk_image.rb, line 34 def while_mounted mount yield self ensure unmount end
Private Instance Methods
map_image()
click to toggle source
# File lib/bosh/stemcell/disk_image.rb, line 52 def map_image @device = shell.run("sudo losetup --show --find #{image_file_path}", output_command: verbose) if Bosh::Stemcell::Arch.ppc64le? # power8 guest images have a p1: PReP partition and p2: file system, we need loopp2 here shell.run("sudo kpartx -av #{device} | grep \"^add\" | grep \"p2 \"", output_command: verbose) else shell.run("sudo kpartx -av #{device}", output_command: verbose) end end
stemcell_loopback_device_name()
click to toggle source
# File lib/bosh/stemcell/disk_image.rb, line 45 def stemcell_loopback_device_name split_output = map_image.split(' ') device_name = split_output[2] File.join('/dev/mapper', device_name) end
unmap_image()
click to toggle source
# File lib/bosh/stemcell/disk_image.rb, line 62 def unmap_image shell.run("sudo kpartx -dv #{device}", output_command: verbose) shell.run("sudo losetup -dv #{device}", output_command: verbose) end