Skip to content

Commit 16ad7cd

Browse files
author
prein
committed
added supermicro support, power control only, more to come
1 parent a6d3c0a commit 16ad7cd

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

lib/moob.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ def to_s
1919
autoload :Megatrends, 'moob/megatrends.rb'
2020
autoload :SunILom, 'moob/sunilom.rb'
2121
autoload :IbmEServer, 'moob/ibmeserver.rb'
22+
autoload :Supermicro, 'moob/supermicro.rb'
2223

2324
TYPES = {
2425
:idrac6 => Idrac6,
2526
:idrac7 => Idrac7,
2627
:megatrends => Megatrends,
2728
:sun => SunILom,
28-
:ibm => IbmEServer
29+
:ibm => IbmEServer,
30+
:supermicro => Supermicro
2931
}
3032

31-
AUTODETECT_ORDER = [ :idrac7, :idrac6, :megatrends, :sun, :ibm ]
33+
AUTODETECT_ORDER = [ :idrac7, :idrac6, :supermicro, :megatrends, :sun, :ibm ]
3234

3335
def self.lom type, hostname, options = {}
3436
case type

lib/moob/supermicro.rb

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
module Moob
2+
class Supermicro < BaseLom
3+
@name = 'Supermicro'
4+
5+
def initialize hostname, options = {}
6+
super hostname, options
7+
@username ||= 'ADMIN'
8+
@password ||= 'ADMIN'
9+
begin
10+
@ip = Socket.getaddrinfo(hostname, nil)[0][3]
11+
rescue
12+
raise "Couldn't resolve \"#{hostname}\""
13+
end
14+
@session.base_url = "#{@transport}://#{@ip}/"
15+
end
16+
17+
def authenticate
18+
@session.handle_cookies nil
19+
auth = @session.post 'cgi/login.cgi',
20+
"name=#{@username}&pwd=#{@password}"
21+
22+
raise ResponseError.new auth unless auth.status == 200
23+
return self
24+
end
25+
26+
def detect
27+
begin
28+
home = @session.get '/'
29+
home.body =~ /\"META NAME=\"ATEN International Co Ltd\.\"/
30+
rescue
31+
false
32+
end
33+
end
34+
35+
def power_action action
36+
time_s = Time.now.strftime("%a %b %d %Y %H:%M:%S")
37+
req = @session.get "cgi/ipmi.cgi?POWER_INFO.XML=" + CGI::escape(action) + "&time_stamp=" + CGI::escape(time_s)
38+
raise ResponseError.new req unless req.status == 200
39+
unless req.body =~ /POWER_INFO/
40+
raise 'The answer looks wrong'
41+
end
42+
return nil
43+
end
44+
45+
action :poff, 'Power Off'
46+
action :pon, 'Power On'
47+
action :pcycle, 'Power Cycle'
48+
action :preset, 'Power Reset'
49+
action :shutdown, 'Soft Power Off'
50+
def poff; power_action "(1,2)"; end
51+
def pon; power_action "(1,1)"; end
52+
def pcycle; power_action "(1,4)"; end
53+
def preset; power_action "(1,3)"; end
54+
def shutdown; power_action "(1,5)"; end
55+
56+
action :pstatus, 'Power status'
57+
def pstatus
58+
time_s = Time.now.strftime("%a %b %d %Y %H:%M:%S")
59+
status = @session.get "cgi/ipmi.cgi?POWER_INFO.XML=(0%2C0)&time_stamp=" + CGI::escape(time_s)
60+
raise ResponseError.new status unless status.status == 200
61+
raise 'Couldn\'t read the state' unless status.body =~ /POWER STATUS=\"([A-Z]+)\"/
62+
case $1
63+
when 'OFF'
64+
return :off
65+
when 'ON'
66+
return :on
67+
end
68+
end
69+
70+
end
71+
end

0 commit comments

Comments
 (0)