Class: LVM::LVM
- Inherits:
-
Object
- Object
- LVM::LVM
- Defined in:
- lib/lvm.rb
Constant Summary collapse
- VALID_OPTIONS =
[ :command, :version, :debug, :additional_arguments, ]
- DEFAULT_COMMAND =
"/sbin/lvm"
Instance Attribute Summary collapse
-
#additional_arguments ⇒ Object
readonly
Returns the value of attribute additional_arguments.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#logical_volumes ⇒ Object
readonly
Returns the value of attribute logical_volumes.
-
#physical_volumes ⇒ Object
readonly
Returns the value of attribute physical_volumes.
-
#volume_groups ⇒ Object
readonly
Returns the value of attribute volume_groups.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ LVM
constructor
A new instance of LVM.
- #raw(args) ⇒ Object
-
#userland ⇒ Object
helper methods.
- #version ⇒ Object
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( = {}) # handy, thanks net-ssh! = .keys - VALID_OPTIONS if .any? raise ArgumentError, "invalid option(s): #{.join(', ')}" end @command = [:command] || DEFAULT_COMMAND # default to loading attributes for the current version [:version] ||= version [:debug] ||= false @logical_volumes = LogicalVolumes.new() @volume_groups = VolumeGroups.new() @physical_volumes = PhysicalVolumes.new() if block_given? yield self else return self end end |
Instance Attribute Details
#additional_arguments ⇒ Object (readonly)
Returns the value of attribute additional_arguments.
14 15 16 |
# File 'lib/lvm.rb', line 14 def additional_arguments @additional_arguments end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
10 11 12 |
# File 'lib/lvm.rb', line 10 def command @command end |
#logical_volumes ⇒ Object (readonly)
Returns the value of attribute logical_volumes.
11 12 13 |
# File 'lib/lvm.rb', line 11 def logical_volumes @logical_volumes end |
#physical_volumes ⇒ Object (readonly)
Returns the value of attribute physical_volumes.
13 14 15 |
# File 'lib/lvm.rb', line 13 def physical_volumes @physical_volumes end |
#volume_groups ⇒ Object (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 |
#userland ⇒ Object
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 |
#version ⇒ Object
61 62 63 |
# File 'lib/lvm.rb', line 61 def version %r{^(.*?)(-| )}.match(userland.lvm_version)[1] end |