Class: LinuxAdmin::LogicalVolume

Inherits:
Volume show all
Defined in:
lib/linux_admin/logical_volume.rb

Constant Summary

Constants inherited from LinuxAdmin

VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#cmd, #run, #run!

Constructor Details

#initialize(args = {}) ⇒ LogicalVolume

other fields available: logical volume access logical volume status internal logical volume number open count of logical volume current logical extents associated to logical volume allocated logical extents of logical volume allocation policy of logical volume read ahead sectors of logical volume major device number of logical volume minor device number of logical volume



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

def initialize(args = {})
  @name         = args[:name]
  @volume_group = args[:volume_group]
  @sectors      = args[:sectors]
end

Instance Attribute Details

#nameObject

logical volume name



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

def name
  @name
end

#sectorsObject

logical volume size in sectors



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

def sectors
  @sectors
end

#volume_groupObject

volume group name



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

def volume_group
  @volume_group
end

Class Method Details

.create(name, vg, value) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/linux_admin/logical_volume.rb', line 57

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

.scanObject



76
77
78
79
80
81
82
83
84
# File 'lib/linux_admin/logical_volume.rb', line 76

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



35
36
37
38
39
# File 'lib/linux_admin/logical_volume.rb', line 35

def extend_with(vg)
  run!(cmd(:lvextend),
      :params => [self.name, vg.name])
  self
end