Class: LVM::LVM

Inherits:
Object
  • Object
show all
Defined in:
lib/lvm.rb

Constant Summary collapse

VALID_OPTIONS =
[
  :command,
  :version,
  :debug
]
DEFAULT_COMMAND =
'/sbin/lvm'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ LVM

Returns a new instance of LVM.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/lvm.rb', line 24

def initialize(options={})
  # handy, thanks net-ssh!
  invalid_options = options.keys - VALID_OPTIONS
  if invalid_options.any?
    raise ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
  end

  @command = options[:command] || DEFAULT_COMMAND

  # default to loading attributes for the current version
  options[:version] ||= version 
  options[:debug] ||= false

  @logical_volumes = LogicalVolumes.new(options)
  @volume_groups = VolumeGroups.new(options)
  @physical_volumes = PhysicalVolumes.new(options)

  if block_given?
    yield self
  else
    return self
  end
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



11
12
13
# File 'lib/lvm.rb', line 11

def command
  @command
end

#logical_volumesObject (readonly)

Returns the value of attribute logical_volumes.



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

def logical_volumes
  @logical_volumes
end

#physical_volumesObject (readonly)

Returns the value of attribute physical_volumes.



14
15
16
# File 'lib/lvm.rb', line 14

def physical_volumes
  @physical_volumes
end

#volume_groupsObject (readonly)

Returns the value of attribute volume_groups.



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

def volume_groups
  @volume_groups
end

Instance Method Details

#raw(args) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/lvm.rb', line 48

def raw(args)
  output = []
  External.cmd("#{@command} #{args}") do |line|
    output << line
  end
  if block_given?
    return output.each { |l| yield l }
  else
    return output.join
  end
end

#userlandObject

helper methods



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/lvm.rb', line 65

def userland
  userland = UserLand.new
  raw('version') do |line|
    case line
    when  %r{^\s+LVM version:\s+([0-9].*)$}
      userland.lvm_version = $1
    when %r{^\s+Library version:\s+([0-9].*)$}
      userland.library_version = $1
    when  %r{^\s+Driver version:\s+([0-9].*)$}
      userland.driver_version = $1
    end
  end

  return userland
end

#versionObject



60
61
62
# File 'lib/lvm.rb', line 60

def version
  %r{^(.*?)(-| )}.match(userland.lvm_version)[1]
end