Sha256: f91d2e3504872f525264620af59420a7215b9871e227fa3fb2c8efc161bb1c5c

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 KB

Contents

#! /usr/bin/env ruby
# coding: utf-8

require 'rexml/document'
#
#
#
class Comana::HostInspector::Pbsnodes
  attr_reader :name, :state, :np, :properties, :ntype, :gpus, :status

  class UnknownNodeError < Exception; end

  def initialize(hostname, pbs_server = nil)
    @hostname = hostname
    command = "pbsnodes -x #{hostname}"
    command = "pbsnodes -x -s #{pbs_server} #{hostname}" if pbs_server
    command = "cat test/pbsnodes/#{hostname}.xml" if $TEST
    #command = "cat test/pbsnodes/#{hostname}.xml"
    parse `#{command} 2> /dev/null`
  end

  private

  def parse(str)
    doc = REXML::Document.new(str)
    #pp doc.elements["/Data/Node/name"      ] == nil
    if doc.elements["/Data/Node/name"      ] == nil
      raise UnknownNodeError
    end

    @name       = doc.elements["/Data/Node/name"      ].text
    @state      = doc.elements["/Data/Node/state"     ].text
    @np         = doc.elements["/Data/Node/np"        ].text
    @properties = doc.elements["/Data/Node/properties"].text
    @ntype      = doc.elements["/Data/Node/ntype"     ].text
    @gpus       = doc.elements["/Data/Node/gpus"      ].text

    #status
    @status = {}
    elem = doc.elements["/Data/Node/status"]
    if elem
      #doc.elements["/Data/Node/status"].text.to_s.split(",").each do |equation|
      elem.text.split(",").each do |equation|
        left = equation.split("=")[0]
        right = equation.split("=")[1].to_s
        @status[left] = right
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comana-0.0.10 lib/comana/hostinspector/pbsnodes.rb