Module: Moob

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

Defined Under Namespace

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

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.inform(msg) ⇒ Object



91
92
93
# File 'lib/moob.rb', line 91

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

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



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

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



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

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



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

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



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

def self.start_jnlp lom
  jnlp = lom.jnlp

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

  tmpfile = Tempfile.new("#{lom.hostname}_#{Time.now.to_i}.jnlp")
  tmpfile.write jnlp
  tmpfile.close

  raise 'javaws failed' unless system "javaws -wait #{tmpfile.path}"
end

.warn(msg) ⇒ Object



95
96
97
# File 'lib/moob.rb', line 95

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