Class: Bosh::Stemcell::DiskImage
- Inherits:
-
Object
- Object
- Bosh::Stemcell::DiskImage
- Defined in:
- lib/bosh/stemcell/disk_image.rb
Instance Attribute Summary collapse
-
#image_mount_point ⇒ Object
readonly
Returns the value of attribute image_mount_point.
Instance Method Summary collapse
-
#initialize(options) ⇒ DiskImage
constructor
A new instance of DiskImage.
- #mount ⇒ Object
- #unmount ⇒ Object
- #while_mounted ⇒ Object
Constructor Details
#initialize(options) ⇒ DiskImage
Returns a new instance of DiskImage.
10 11 12 13 14 15 |
# File 'lib/bosh/stemcell/disk_image.rb', line 10 def initialize() @image_file_path = .fetch(:image_file_path) @image_mount_point = .fetch(:image_mount_point, Dir.mktmpdir) @verbose = .fetch(:verbose, false) @shell = Bosh::Core::Shell.new end |
Instance Attribute Details
#image_mount_point ⇒ Object (readonly)
Returns the value of attribute image_mount_point.
8 9 10 |
# File 'lib/bosh/stemcell/disk_image.rb', line 8 def image_mount_point @image_mount_point end |
Instance Method Details
#mount ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# 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..include?(mount_command) sleep 0.5 shell.run(mount_command, output_command: verbose) end |
#unmount ⇒ Object
28 29 30 31 32 |
# 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 ⇒ Object
34 35 36 37 38 39 |
# File 'lib/bosh/stemcell/disk_image.rb', line 34 def while_mounted mount yield self ensure unmount end |