Class: LVM::LVM
- Inherits:
-
Object
- Object
- LVM::LVM
- Defined in:
- lib/lvm.rb
Constant Summary collapse
- VALID_OPTIONS =
%i{ command version debug additional_arguments }.freeze
- DEFAULT_COMMAND =
"/sbin/lvm".freeze
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.
Class Method Summary collapse
-
.parse_version(raw) ⇒ Object
Extract the canonical X.Y.Z or X.Y.Z(N) version key used by chef-ruby-lvm-attrib attribute directories.
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 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 |
Class Method Details
.parse_version(raw) ⇒ Object
Extract the canonical X.Y.Z or X.Y.Z(N) version key used by chef-ruby-lvm-attrib attribute directories.
67 68 69 70 71 72 |
# File 'lib/lvm.rb', line 67 def self.parse_version(raw) match = raw.to_s.match(/(\d+\.\d+\.\d+)(?:\((\d+))?/) return raw.to_s if match.nil? match[2] ? "#{match[1]}(#{match[2]})" : match[1] 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? output.each { |l| yield l } else output.join end end |
#userland ⇒ Object
helper methods
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/lvm.rb', line 75 def userland userland = UserLand.new raw("version") do |line| case line when /^\s+LVM version:\s+([0-9].*)$/ userland.lvm_version = $1 when /^\s+Library version:\s+([0-9].*)$/ userland.library_version = $1 when /^\s+Driver version:\s+([0-9].*)$/ userland.driver_version = $1 end end userland end |
#version ⇒ Object
61 62 63 |
# File 'lib/lvm.rb', line 61 def version self.class.parse_version(userland.lvm_version) end |