Class: Moob::Pec
Constant Summary collapse
- INFO_FIELDS =
%w[ asic certificate chassisFLEDStatus chassisILEDStatus chassisName biosVer fwUpdated fwVersion hostname hwVersion ipmiKey ipmiLAN ipmiMinPriv productDescription productName pwState serialOverLanBaud serialOverLanEnabled serialOverLanPriv hostname ifName macAddr autoNeg v4Enabled v4DHCPEnabled v4IPAddr v4NetMask v4Gateway ]
Instance Attribute Summary
Attributes inherited from BaseLom
Instance Method Summary collapse
- #authenticate ⇒ Object
- #detect ⇒ Object
- #drac_set_params(params) ⇒ Object
- #enable_ipmi ⇒ Object
- #get_infos(keys) ⇒ Object
- #infos ⇒ Object
-
#initialize(hostname, options = {}) ⇒ Pec
constructor
A new instance of Pec.
- #jnlp ⇒ Object
- #logout ⇒ Object
- #power_control(action) ⇒ Object
- #pstatus ⇒ Object
- #set_params ⇒ Object
Methods inherited from BaseLom
Constructor Details
#initialize(hostname, options = {}) ⇒ Pec
Returns a new instance of Pec.
17 18 19 20 21 22 |
# File 'lib/moob/pec.rb', line 17 def initialize hostname, = {} super hostname, @username ||= 'root' @password ||= 'root' @index = nil end |
Instance Method Details
#authenticate ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/moob/pec.rb', line 24 def authenticate @session. nil login = @session.get 'login.html' raise ResponseError.new login unless login.status == 200 auth = @session.post 'data/login', "user=#{@username}&password=#{@password}" raise ResponseError.new auth unless auth.status == 200 auth.body =~ /<authResult>([^<]+)<\/authResult>/ raise 'Cannot find auth result' unless $& raise "Auth failed with: \"#{auth.body}\"" unless $1 == "0" auth.body =~ /<forwardUrl>([^<]+)<\/forwardUrl>/ raise 'Cannot find the authenticated index url after auth' unless $& @indexurl = $1 Moob.inform "Requesting indexurl of #{@indexurl}" @authhash = @indexurl.split('?')[1] @index = @session.get @indexurl # someone decided it was a good idea to include a ST2 token in every XHR # request. We need it for a lot of our features. @index.body =~ /var CSRF_TOKEN_2_VALUE = "([0-9a-f]+)";/ raise ResponseError.new @index unless @index.status == 200 @st2 = $1 @session.headers['ST2'] = @st2 return self end |
#detect ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/moob/pec.rb', line 69 def detect begin home = @session.get 'login.html' home.body =~ /Dell Remote Management Controller/ rescue false end end |
#drac_set_params(params) ⇒ Object
155 156 157 158 159 160 161 |
# File 'lib/moob/pec.rb', line 155 def drac_set_params params params.each do |p,v| req = @session.post "data?set=#{p}:#{v}", {} raise ResponseError.new req unless req.status == 200 end return nil end |
#enable_ipmi ⇒ Object
151 152 153 |
# File 'lib/moob/pec.rb', line 151 def enable_ipmi drac_set_params({ 'ipmiLAN' => 1 }) end |
#get_infos(keys) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/moob/pec.rb', line 127 def get_infos keys infos = @session.post "data?get=#{keys.join(',')}", {} raise ResponseError.new infos unless infos.status == 200 raise "The status isn't OK" unless infos.body =~ /<status>ok<\/status>/ return Hash[keys.collect do |k| if infos.body =~ /<#{k}>(.*?)<\/#{k}>/ [k, $1] else [k, nil] end end] end |
#infos ⇒ Object
123 124 125 |
# File 'lib/moob/pec.rb', line 123 def infos return JSON.pretty_generate get_infos INFO_FIELDS end |
#jnlp ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/moob/pec.rb', line 80 def jnlp # On PEC LOM CSRF_TOKEN_1 carries the auth token @index.body =~ /var CSRF_TOKEN_1\s+= \"ST1\" \+ \"=\" \+ "([0-9a-f]+)";/ @st1 = $1 viewer = @session.get "viewer.jnlp(#{@hostname}@0@#{Time.now.to_i * 1000})?ST1=#{@st1}" raise ResponseError.new viewer unless viewer.status == 200 return viewer.body end |
#logout ⇒ Object
63 64 65 66 67 |
# File 'lib/moob/pec.rb', line 63 def logout out = @session.get 'data/logout' raise ResponseError.new out unless out.status == 200 return self end |
#power_control(action) ⇒ Object
91 92 93 94 95 |
# File 'lib/moob/pec.rb', line 91 def power_control action req = @session.post "data?set=pwState:#{action}", {} raise ResponseError.new req unless req.status == 200 return nil end |
#pstatus ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/moob/pec.rb', line 111 def pstatus case get_infos(['pwState'])['pwState'] when '0' return :off when '1' return :on else return nil end end |
#set_params ⇒ Object
143 144 145 146 147 148 |
# File 'lib/moob/pec.rb', line 143 def set_params unless @params raise "Params are not set!" end drac_set_params @params end |