Module: Moob

Defined in:
lib/moob.rb,
lib/moob/idrac6.rb,
lib/moob/idrac7.rb,
lib/moob/sunilom.rb,
lib/moob/ibmeserver.rb,
lib/moob/megatrends.rb

Defined Under Namespace

Classes: BaseLom, IbmEServer, Idrac6, Idrac7, Megatrends, ResponseError, SunILom

Constant Summary collapse

VERSION =
[0,3,12]
TYPES =
{
  :idrac6     => Idrac6,
  :idrac7     => Idrac7,
  :megatrends => Megatrends,
  :sun        => SunILom,
  :ibm        => IbmEServer
}
AUTODETECT_ORDER =
[ :idrac7, :idrac6, :megatrends, :sun, :ibm ]

Class Method Summary collapse

Class Method Details

.inform(msg) ⇒ Object



89
90
91
# File 'lib/moob.rb', line 89

def self.inform msg
  $stderr.puts "\033[36m#{msg}\033[0m" if $VERBOSE
end

.lom(type, hostname, options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/moob.rb', line 32

def self.lom type, hostname, options = {}
  case type
  when :auto
    AUTODETECT_ORDER.each do |sym|
      Moob.inform "Trying type #{sym}..."
      lom = TYPES[sym].new hostname, options
      if lom.detect
        Moob.inform "Type #{sym} detected."
        return lom
      end
      false
    end
    raise 'Couldn\'t detect a known LOM type'
  else
    raise "Type #{type} unknown" unless TYPES[type]
    return TYPES[type].new hostname, options
  end
end

.save_console_preview(lom) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/moob.rb', line 76

def self.save_console_preview lom
  imgfile, headers = lom.fetch_console_preview

  timestamp=Time.parse(headers['Last-modified'])
  fileext=headers['Content-type'].split('/')[1]

  filename="#{lom.hostname}-#{timestamp.utc.iso8601(0)}.#{fileext}"

  FileUtils.cp(imgfile.path, filename)

  return filename
end

.show_console_preview(lom) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/moob.rb', line 66

def self.show_console_preview lom
  imgfile, headers = lom.fetch_console_preview

  if RUBY_PLATFORM =~ /darwin/
    raise 'open failed' unless system "open #{imgfile.path}"
  else
    raise 'see failed' unless system "see #{imgfile.path}"
  end
end

.start_jnlp(lom) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/moob.rb', line 51

def self.start_jnlp lom
  jnlp = lom.jnlp

  unless jnlp[/<\/jnlp>/]
    raise "Invalid JNLP file (\"#{jnlp}\")"
  end

  filepath = "/tmp/#{lom.hostname}_#{Time.now.to_i}.jnlp"
  File.open filepath, 'w' do |f|
    f.write jnlp
  end

  raise 'javaws failed' unless system "javaws -wait #{filepath}"
end

.warn(msg) ⇒ Object



93
94
95
# File 'lib/moob.rb', line 93

def self.warn msg
  $stderr.puts "\033[36m#{msg}\033[0m"
end