Class: LVM::LVM
- Inherits:
-
Object
- Object
- LVM::LVM
- Defined in:
- lib/lvm.rb
Constant Summary collapse
- VALID_OPTIONS =
[ :command, :version, :debug ]
- DEFAULT_COMMAND =
'/sbin/lvm'
Instance Attribute Summary collapse
-
#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.
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(={}) # 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
#command ⇒ Object (readonly)
Returns the value of attribute command.
11 12 13 |
# File 'lib/lvm.rb', line 11 def command @command end |
#logical_volumes ⇒ Object (readonly)
Returns the value of attribute logical_volumes.
12 13 14 |
# File 'lib/lvm.rb', line 12 def logical_volumes @logical_volumes end |
#physical_volumes ⇒ Object (readonly)
Returns the value of attribute physical_volumes.
14 15 16 |
# File 'lib/lvm.rb', line 14 def physical_volumes @physical_volumes end |
#volume_groups ⇒ Object (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 |
#userland ⇒ Object
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 |
#version ⇒ Object
60 61 62 |
# File 'lib/lvm.rb', line 60 def version %r{^(.*?)(-| )}.match(userland.lvm_version)[1] end |