Class: LinuxAdmin::LogicalVolume

Inherits:
Volume
  • Object
show all
Includes:
Mountable
Defined in:
lib/linux_admin/logical_volume.rb

Constant Summary collapse

DEVICE_PATH =
Pathname.new('/dev/')

Instance Attribute Summary collapse

Attributes included from Mountable

#fs_type, #mount_point

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mountable

#discover_mount_point, #format_to, included, #mount, #umount

Constructor Details

#initialize(args = {}) ⇒ LogicalVolume

Returns a new instance of LogicalVolume.



43
44
45
46
47
48
49
# 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

Instance Attribute Details

#nameObject

logical volume name



10
11
12
# File 'lib/linux_admin/logical_volume.rb', line 10

def name
  @name
end

#sectorsObject

logical volume size in sectors



16
17
18
# File 'lib/linux_admin/logical_volume.rb', line 16

def sectors
  @sectors
end

#volume_groupObject

volume group name



13
14
15
# File 'lib/linux_admin/logical_volume.rb', line 13

def volume_group
  @volume_group
end

Class Method Details

.create(name, vg, value) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# 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

.scanObject



93
94
95
96
97
98
99
100
101
# 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

Instance Method Details

#extend_with(vg) ⇒ Object



51
52
53
54
55
# 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

#pathObject

path to logical volume



31
32
33
# File 'lib/linux_admin/logical_volume.rb', line 31

def path
  "/dev/#{self.volume_group.name}/#{self.name}"
end

#path=(value) ⇒ Object



35
36
37
# 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