class LinuxAdmin::LogicalVolume
Constants
- DEVICE_PATH
Attributes
name[R]
logical volume name
sectors[RW]
logical volume size in sectors
volume_group[RW]
volume group name
Public Class Methods
bytes_to_string(bytes)
click to toggle source
# File lib/linux_admin/logical_volume.rb, line 59 def self.bytes_to_string(bytes) if bytes > 1_073_741_824 # 1.gigabytes (bytes / 1_073_741_824).to_s + "G" elsif bytes > 1_048_576 # 1.megabytes (bytes / 1_048_576).to_s + "M" elsif bytes > 1_024 # 1.kilobytes (bytes / 1_024).to_s + "K" else bytes.to_s end end
create(name, vg, value)
click to toggle source
# File lib/linux_admin/logical_volume.rb, line 73 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 Common.run!(Common.cmd(:lvcreate), :params => params) lv = LogicalVolume.new(:name => name, :volume_group => vg, :sectors => size) @lvs << lv lv end
new(args = {})
click to toggle source
# File lib/linux_admin/logical_volume.rb, line 43 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
scan()
click to toggle source
# File lib/linux_admin/logical_volume.rb, line 93 def self.scan @lvs ||= begin scan_volumes(Common.cmd(:lvdisplay)) do |fields, vg| LogicalVolume.new(:name => fields[0], :volume_group => vg, :sectors => fields[6].to_i) end end end
Public Instance Methods
extend_with(vg)
click to toggle source
# File lib/linux_admin/logical_volume.rb, line 51 def extend_with(vg) Common.run!(Common.cmd(:lvextend), :params => [self.name, vg.name]) self end
name=(value)
click to toggle source
# File lib/linux_admin/logical_volume.rb, line 39 def name=(value) @name = value.include?(File::SEPARATOR) ? value.split(File::SEPARATOR).last : value end
path()
click to toggle source
path to logical volume
# File lib/linux_admin/logical_volume.rb, line 31 def path "/dev/#{self.volume_group.name}/#{self.name}" end
path=(value)
click to toggle source
# File lib/linux_admin/logical_volume.rb, line 35 def path=(value) @path = value.include?(File::SEPARATOR) ? value : DEVICE_PATH.join(@volume_group.name, value) end