Class: LinuxAdmin::LogicalVolume

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

Constant Summary collapse

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

Constants inherited from LinuxAdmin

VERSION

Instance Attribute Summary collapse

Attributes included from Mountable

#fs_type, #mount_point

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mountable

#format_to, included, #mount, #umount

Methods included from Common

#cmd, #run, #run!

Constructor Details

#initialize(args = {}) ⇒ LogicalVolume

Returns a new instance of LogicalVolume.



46
47
48
49
50
51
52
# File 'lib/linux_admin/logical_volume.rb', line 46

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



18
19
20
# File 'lib/linux_admin/logical_volume.rb', line 18

def name
  @name
end

#pathObject

path to logical volume



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

def path
  @path
end

#sectorsObject

logical volume size in sectors



24
25
26
# File 'lib/linux_admin/logical_volume.rb', line 24

def sectors
  @sectors
end

#volume_groupObject

volume group name



21
22
23
# File 'lib/linux_admin/logical_volume.rb', line 21

def volume_group
  @volume_group
end

Class Method Details

.create(name, vg, value) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/linux_admin/logical_volume.rb', line 80

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



100
101
102
103
104
105
106
107
108
# File 'lib/linux_admin/logical_volume.rb', line 100

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



54
55
56
57
58
# File 'lib/linux_admin/logical_volume.rb', line 54

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