Class: Moob::Supermicro
Instance Attribute Summary
Attributes inherited from BaseLom
#hostname, #username
Instance Method Summary
collapse
Methods inherited from BaseLom
action, actions, #logout, name
Constructor Details
#initialize(hostname, options = {}) ⇒ Supermicro
Returns a new instance of Supermicro.
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/moob/supermicro.rb', line 5
def initialize hostname, options = {}
super hostname, options
@username ||= 'ADMIN'
@password ||= 'ADMIN'
begin
@ip = Socket.getaddrinfo(hostname, nil)[0][3]
rescue
raise "Couldn't resolve \"#{hostname}\""
end
@session.base_url = "#{@transport}://#{@ip}/"
end
|
Instance Method Details
#authenticate ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/moob/supermicro.rb', line 17
def authenticate
@session.handle_cookies nil
auth = @session.post 'cgi/login.cgi',
"name=#{@username}&pwd=#{@password}"
raise ResponseError.new auth unless auth.status == 200
return self
end
|
#detect ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/moob/supermicro.rb', line 26
def detect
begin
home = @session.get '/'
home.body =~ /META NAME=\"ATEN International Co Ltd\.\"/
rescue
false
end
end
|
#jnlp ⇒ Object
71
72
73
74
75
76
|
# File 'lib/moob/supermicro.rb', line 71
def jnlp
viewer = @session.get 'cgi/url_redirect.cgi?url_name=&url_type=jwsk'
raise ResponseError.new viewer unless viewer.status == 200
return viewer.body
end
|
#pcycle ⇒ Object
52
|
# File 'lib/moob/supermicro.rb', line 52
def pcycle; power_action "(1,2)"; end
|
#poff ⇒ Object
50
|
# File 'lib/moob/supermicro.rb', line 50
def poff; power_action "(1,0)"; end
|
#pon ⇒ Object
51
|
# File 'lib/moob/supermicro.rb', line 51
def pon; power_action "(1,1)"; end
|
#power_action(action) ⇒ Object
35
36
37
38
39
40
41
42
43
|
# File 'lib/moob/supermicro.rb', line 35
def power_action action
time_s = Time.now.strftime("%a %b %d %Y %H:%M:%S")
req = @session.get "cgi/ipmi.cgi?POWER_INFO.XML=" + CGI::escape(action) + "&time_stamp=" + CGI::escape(time_s)
raise ResponseError.new req unless req.status == 200
unless req.body =~ /POWER_INFO/
raise 'The answer looks wrong'
end
return nil
end
|
#preset ⇒ Object
53
|
# File 'lib/moob/supermicro.rb', line 53
def preset; power_action "(1,3)"; end
|
#pstatus ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/moob/supermicro.rb', line 57
def pstatus
time_s = Time.now.strftime("%a %b %d %Y %H:%M:%S")
status = @session.get "cgi/ipmi.cgi?POWER_INFO.XML=(0%2C0)&time_stamp=" + CGI::escape(time_s)
raise ResponseError.new status unless status.status == 200
raise 'Couldn\'t read the state' unless status.body =~ /POWER STATUS=\"([A-Z]+)\"/
case $1
when 'OFF'
return :off
when 'ON'
return :on
end
end
|
#shutdown ⇒ Object
54
|
# File 'lib/moob/supermicro.rb', line 54
def shutdown; power_action "(1,5)"; end
|