|
| 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