Module: Moob

Defined in:
lib/moob.rb,
lib/moob/pec.rb,
lib/moob/idrac6.rb,
lib/moob/idrac7.rb,
lib/moob/idrac8.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, Idrac8, Megatrends, Pec, ResponseError, SunILom, Supermicro

Constant Summary collapse

TYPES =
{
  :idrac6     => Idrac6,
  :idrac7     => Idrac7,
  :idrac8     => Idrac8,
  :pec        => Pec,
  :megatrends => Megatrends,
  :sun        => SunILom,
  :ibm        => IbmEServer,
  :supermicro => Supermicro
}
AUTODETECT_ORDER =
[ :idrac8, :idrac7, :idrac6, :pec, :supermicro, :megatrends, :sun, :ibm ]
VERSION =
[0,4,1]

Class Method Summary collapse

Class Method Details

.inform(msg) ⇒ Object



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

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

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



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/moob.rb', line 39

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



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/moob.rb', line 82

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



72
73
74
75
76
77
78
79
80
# File 'lib/moob.rb', line 72

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



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/moob.rb', line 58

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



99
100
101
# File 'lib/moob.rb', line 99

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