class Lsmap

Attributes

mapping[RW]
sys[RW]
vios[RW]

Public Class Methods

new(string = '', vios = nil, sys = nil) click to toggle source
# File lib/VIOS/lsmap.rb, line 12
def initialize(string = '', vios = nil, sys = nil)
  @vios = vios
  @sys = sys

  @mapping = {}

  parse_long(string) unless string.empty?
end

Public Instance Methods

backing_devices_for_lpar(lpar_id) click to toggle source
# File lib/VIOS/lsmap.rb, line 89
def backing_devices_for_lpar(lpar_id)
  result = []
  mapping_for_lpar(lpar_id).each do |vhost|
    vhost.vtds.each do |vtd|
      result.push(vtd.backing_device)
    end
  end
  result.sort
end
lpars() click to toggle source
# File lib/VIOS/lsmap.rb, line 73
def lpars
  result = []
  @mapping.each_value do |vhost|
    result.push(vhost.client_partition_id_nice)
  end
  result.uniq
end
mapping_for_lpar(lpar_id) click to toggle source
# File lib/VIOS/lsmap.rb, line 81
def mapping_for_lpar(lpar_id)
  result = []
  @mapping.each_value do |vhost|
    result.push(vhost) if vhost.client_partition_id_nice == lpar_id
  end
  result
end
parse_long(string) click to toggle source
# File lib/VIOS/lsmap.rb, line 21
def parse_long(string)

  vhost_number = 0
  vtd_number = 0
  vhost = ''
  vhost_value = ''

  regexp_text = /^\s*SVSA\s+Physloc\s+Client\sPartition\sID\s*$/
  regexp_separator = /^\s*[-]+\s+[-]+\s+[-]+\s*$/
  regexp_no_devices = /NO VIRTUAL TARGET DEVICE FOUND/
  regexp_empty = /^\s*$/

  regexp_mirrored = /^\s*Mirrored\s+(true|false)\s*$/
  regexp_status = /^\s*Status\s+(Available|Defined)\s*$/
  regexp_physloc = /Physloc/
  regexp_lun_id = /^\s*LUN\s+(0x\w+)\s*$/
  regexp_b_device = /Backing\sdevice\s+([\w\-\_]+)/
  regexp_vtd = /^\s*VTD\s+([\w\_\-]+)\s*$/

  regexp_vhost = /^\s*(vhost\d+)\s+([\w\-\.]+)\s+(\w+)\s*$/

  string.each_line do |line|
    next if line =~ /#{regexp_empty}|#{regexp_text}|#{regexp_separator}|#{regexp_no_devices}/

    if line =~ /#{regexp_vhost}/
      if vhost_number > 0
        vhost.vtds.push(Vtd.new(vhost_value)) unless vhost_value.empty?
        @mapping[vhost.name] = vhost
      end

      vhost = Vhost.new(line)
      vhost.sys = @sys
      vhost.vios = @vios
      vhost_number += 1
      vhost_value = ''
      vtd_number = 0

    elsif line =~ /#{regexp_vtd}/
      vhost.vtds.push(Vtd.new(vhost_value)) if vtd_number > 0
      vtd_number += 1
      vhost_value = line
    elsif line =~ /#{regexp_status}|#{regexp_lun_id}|#{regexp_b_device}|#{regexp_physloc}|#{regexp_mirrored}/
      vhost_value += line
    else
      raise "Class:VIOS:lsmap, function: parse_long, RegExp couldn't decode line >>#{line}<<"
    end
  end

  vhost.vtds.push(Vtd.new(vhost_value)) if vtd_number > 0
  @mapping[vhost.name] = vhost if vhost_number > 0
end
to_s(fields = 'all', separator = ':') click to toggle source
# File lib/VIOS/lsmap.rb, line 99
def to_s(fields = 'all', separator = ':')
  result = ''
  @mapping.each_value do |vhost|
    result += vhost.to_s(fields, separator) + "\n"
  end
  result
end
to_s_long_fixed() click to toggle source
# File lib/VIOS/lsmap.rb, line 107
def to_s_long_fixed
  result = ''
  @mapping.each_value do |vhost|
    result += vhost.to_s_long_fixed
  end
  result
end