class Moob::Megatrends

Public Class Methods

new(hostname, options = {}) click to toggle source
Calls superclass method Moob::BaseLom::new
# File lib/moob/megatrends.rb, line 5
def initialize hostname, options = {}
  super hostname, options
  @username ||= 'root'
  @password ||= 'superuser'
  begin
    @ip = Socket.getaddrinfo(hostname, nil)[0][3]
  rescue
    raise "Couldn't resolve \"#{hostname}\""
  end
  @session.base_url = "#{@transport}://#{@ip}/"
end

Public Instance Methods

authenticate() click to toggle source
# File lib/moob/megatrends.rb, line 17
def authenticate
  auth = @session.post 'rpc/WEBSES/create.asp',
    { 'WEBVAR_USERNAME' => @username, 'WEBVAR_PASSWORD' => @password }

  raise ResponseError.new auth unless auth.status == 200

  auth.body =~ /'SESSION_COOKIE' *: *'([^']+)'/
  raise "Couldn't find auth cookie in \"#{auth.body}\"" unless $&

  @cookie = "test=1; path=/; SessionCookie=#{$1}"
  return self
end
detect() click to toggle source
# File lib/moob/megatrends.rb, line 30
def detect
  begin
    home = @session.get 'page/login.html'
    home.body =~ /\.\.\/res\/banner_right\.png/
  rescue
    false
  end
end
jnlp() click to toggle source
# File lib/moob/megatrends.rb, line 40
def jnlp
  @session.ignore_content_length = true
  viewer = @session.get 'Java/jviewer.jnlp', { 'Cookie' => @cookie }
  raise ResponseError.new viewer unless viewer.status == 200

  return viewer.body
end
pcycle() click to toggle source
# File lib/moob/megatrends.rb, line 66
def pcycle;    power_action 2; end
poff() click to toggle source
# File lib/moob/megatrends.rb, line 64
def poff;      power_action 0; end
pon() click to toggle source
# File lib/moob/megatrends.rb, line 65
def pon;       power_action 1; end
power_action(action) click to toggle source
# File lib/moob/megatrends.rb, line 48
def power_action action
  req = @session.post 'rpc/hostctl.asp',
    { 'WEBVAR_POWER_CMD' => action },
    { 'Cookie' => @cookie }
  raise ResponseError.new req unless req.status == 200
  unless req.body =~ /WEBVAR_STRUCTNAME_HL_POWERSTATUS/
    raise 'The answer looks wrong'
  end
  return nil
end
preset() click to toggle source
# File lib/moob/megatrends.rb, line 67
def preset;    power_action 3; end
pstatus() click to toggle source
# File lib/moob/megatrends.rb, line 71
def pstatus
  status = @session.get 'rpc/hoststatus.asp',
    { 'Cookie' => @cookie }
  raise ResponseError.new status unless status.status == 200
  raise 'Couldn\'t read the state' unless status.body =~ /'JF_STATE' : (.),/
  case $1
  when '0'
    return :off
  when '1'
    return :on
  end
end
soft_poff() click to toggle source
# File lib/moob/megatrends.rb, line 68
def soft_poff; power_action 5; end