Class: LinuxAdmin::LogicalVolume
- Inherits:
-
Volume
- Object
- LinuxAdmin
- Volume
- LinuxAdmin::LogicalVolume
- Includes:
- Mountable
- Defined in:
- lib/linux_admin/logical_volume.rb
Constant Summary collapse
- DEVICE_PATH =
Pathname.new('/dev/')
Constants inherited from LinuxAdmin
Instance Attribute Summary collapse
-
#name ⇒ Object
logical volume name.
-
#sectors ⇒ Object
logical volume size in sectors.
-
#volume_group ⇒ Object
volume group name.
Attributes included from Mountable
Class Method Summary collapse
Instance Method Summary collapse
- #extend_with(vg) ⇒ Object
-
#initialize(args = {}) ⇒ LogicalVolume
constructor
A new instance of LogicalVolume.
-
#path ⇒ Object
path to logical volume.
- #path=(value) ⇒ Object
Methods included from Mountable
#format_to, included, #mount, #umount
Methods included from Common
Constructor Details
#initialize(args = {}) ⇒ LogicalVolume
Returns a new instance of LogicalVolume.
48 49 50 51 52 53 54 |
# File 'lib/linux_admin/logical_volume.rb', line 48 def initialize(args = {}) @volume_group = args[:volume_group] @sectors = args[:sectors] provided_name = args[:name].to_s self.path = provided_name self.name = provided_name end |
Instance Attribute Details
#name ⇒ Object
logical volume name
15 16 17 |
# File 'lib/linux_admin/logical_volume.rb', line 15 def name @name end |
#sectors ⇒ Object
logical volume size in sectors
21 22 23 |
# File 'lib/linux_admin/logical_volume.rb', line 21 def sectors @sectors end |
#volume_group ⇒ Object
volume group name
18 19 20 |
# File 'lib/linux_admin/logical_volume.rb', line 18 def volume_group @volume_group end |
Class Method Details
.create(name, vg, value) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/linux_admin/logical_volume.rb', line 78 def self.create(name, vg, value) self.scan # initialize local logical volumes params = { '-n' => name, nil => vg.name} size = nil if value <= 100 # size = # TODO size from extents params.merge!({'-l' => "#{value}%FREE"}) else size = value params.merge!({'-L' => bytes_to_string(size)}) end run!(cmd(:lvcreate), :params => params) lv = LogicalVolume.new(:name => name, :volume_group => vg, :sectors => size) @lvs << lv lv end |
.scan ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/linux_admin/logical_volume.rb', line 98 def self.scan @lvs ||= begin scan_volumes(cmd(:lvdisplay)) do |fields, vg| LogicalVolume.new(:name => fields[0], :volume_group => vg, :sectors => fields[6].to_i) end end end |
Instance Method Details
#extend_with(vg) ⇒ Object
56 57 58 59 60 |
# File 'lib/linux_admin/logical_volume.rb', line 56 def extend_with(vg) run!(cmd(:lvextend), :params => [self.name, vg.name]) self end |
#path ⇒ Object
path to logical volume
36 37 38 |
# File 'lib/linux_admin/logical_volume.rb', line 36 def path "/dev/#{self.volume_group.name}/#{self.name}" end |
#path=(value) ⇒ Object
40 41 42 |
# File 'lib/linux_admin/logical_volume.rb', line 40 def path=(value) @path = value.include?(File::SEPARATOR) ? value : DEVICE_PATH.join(@volume_group.name, value) end |