Class: Lxc::VirtualDevice
- Inherits:
-
Object
- Object
- Lxc::VirtualDevice
- Includes:
- Helpers
- Defined in:
- lib/elecksee/storage/virtual_device.rb
Instance Attribute Summary collapse
-
#fs_type ⇒ Object
readonly
Returns the value of attribute fs_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#tmp_dir ⇒ Object
readonly
Returns the value of attribute tmp_dir.
-
#tmp_fs ⇒ Object
readonly
Returns the value of attribute tmp_fs.
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #device_path ⇒ Object
-
#initialize(name, args = {}) ⇒ VirtualDevice
constructor
A new instance of VirtualDevice.
- #mount ⇒ Object
- #mount_path ⇒ Object (also: #target_path)
- #mounted? ⇒ Boolean
- #unmount ⇒ Object
Methods included from Helpers
#command, #detect_home, #log, #run_command, #sudo
Constructor Details
#initialize(name, args = {}) ⇒ VirtualDevice
Returns a new instance of VirtualDevice.
15 16 17 18 19 20 21 22 23 |
# File 'lib/elecksee/storage/virtual_device.rb', line 15 def initialize(name, args={}) @name = name @tmp_dir = args[:tmp_dir] || '/tmp/lxc/ephemerals' @size = args[:size] || 2000 @fs_type = args[:fs_type] || 'ext4' @tmp_fs = !!args[:tmp_fs] @fs_type = 'tmpfs' if @tmp_fs create end |
Instance Attribute Details
#fs_type ⇒ Object (readonly)
Returns the value of attribute fs_type.
13 14 15 |
# File 'lib/elecksee/storage/virtual_device.rb', line 13 def fs_type @fs_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/elecksee/storage/virtual_device.rb', line 9 def name @name end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
11 12 13 |
# File 'lib/elecksee/storage/virtual_device.rb', line 11 def size @size end |
#tmp_dir ⇒ Object (readonly)
Returns the value of attribute tmp_dir.
10 11 12 |
# File 'lib/elecksee/storage/virtual_device.rb', line 10 def tmp_dir @tmp_dir end |
#tmp_fs ⇒ Object (readonly)
Returns the value of attribute tmp_fs.
12 13 14 |
# File 'lib/elecksee/storage/virtual_device.rb', line 12 def tmp_fs @tmp_fs end |
Instance Method Details
#create ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/elecksee/storage/virtual_device.rb', line 34 def create make_directories! unless(tmp_fs) command("dd if=/dev/zero of=#{@device_path} bs=1k seek=#{sive}k count=1 > /dev/null") command("echo \"y\" | mkfs -t #{fs_type} #{size} > /dev/null") end end |
#destroy ⇒ Object
60 61 62 63 64 65 |
# File 'lib/elecksee/storage/virtual_device.rb', line 60 def destroy unmount File.delete(device_path) if File.file?(device_path) FileUtils.rm_rf(device_path) if File.directory?(device_path) FileUtils.rmdir(mount_path) if File.directory?(mount_path) end |
#device_path ⇒ Object
25 26 27 |
# File 'lib/elecksee/storage/virtual_device.rb', line 25 def device_path tmp_fs ? 'none' : File.join(tmp_dir, 'virt-imgs', name) end |
#mount ⇒ Object
46 47 48 49 50 51 |
# File 'lib/elecksee/storage/virtual_device.rb', line 46 def mount unless(mounted?) command("mount -t #{fs_type}#{} #{device_path} #{mount_path}", :sudo => true) true end end |
#mount_path ⇒ Object Also known as: target_path
29 30 31 |
# File 'lib/elecksee/storage/virtual_device.rb', line 29 def mount_path File.join(tmp_dir, 'virt-mnts', name) end |
#mounted? ⇒ Boolean
42 43 44 |
# File 'lib/elecksee/storage/virtual_device.rb', line 42 def mounted? command("mount").stdout.include?(mount_path) end |
#unmount ⇒ Object
53 54 55 56 57 58 |
# File 'lib/elecksee/storage/virtual_device.rb', line 53 def unmount if(mounted?) command("umount #{mount_path}", :sudo => true) true end end |