Class: LVM::LVM

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ LVM

Returns a new instance of LVM.



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

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

#additional_argumentsObject (readonly)

Returns the value of attribute additional_arguments.



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

def additional_arguments
  @additional_arguments
end

#commandObject (readonly)

Returns the value of attribute command.



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

def command
  @command
end

#logical_volumesObject (readonly)

Returns the value of attribute logical_volumes.



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

def logical_volumes
  @logical_volumes
end

#physical_volumesObject (readonly)

Returns the value of attribute physical_volumes.



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

def physical_volumes
  @physical_volumes
end

#volume_groupsObject (readonly)

Returns the value of attribute volume_groups.



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

def volume_groups
  @volume_groups
end

Instance Method Details

#raw(args) ⇒ Object



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

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



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

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



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

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