class LVM::LVM

Constants

DEFAULT_COMMAND
VALID_OPTIONS

Attributes

command[R]
logical_volumes[R]
physical_volumes[R]
volume_groups[R]

Public Class Methods

new(options={}) { |self| ... } click to toggle source
# File lib/lvm.rb, line 23
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

Public Instance Methods

raw(args) { |l| ... } click to toggle source
# File lib/lvm.rb, line 47
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() click to toggle source

helper methods

# File lib/lvm.rb, line 64
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() click to toggle source
# File lib/lvm.rb, line 59
def version
  %r{^(.*?)(-| )}.match(userland.lvm_version)[1]
end