Class: Moob::Idrac7
Constant Summary collapse
- INFO_FIELDS =
%w[ biosVer svcTag expSvcCode hostName osName osVersion sysDesc sysRev datetime initCountdown presentCountdown fwVersion fwUpdated LCCfwVersion firstBootDevice vmBootOnce racName hwVersionmacAddr recoveryAction NicEtherMac1 NicEtherMac2 NicEtherMac3 NicEtherMac4 NiciSCSIMac1 NiciSCSIMac2 NiciSCSIMac3 NiciSCSIMac4 NicEtherVMac1 NicEtherVMac2 NicEtherVMac3 NicEtherVMac4 v4Enabled v4IPAddr v4Gateway v4NetMask v6Enabled v6Addr v6Gateway v6Prefix v6LinkLocal v4DHCPEnabled v4DHCPServers v4DNS1 v4DNS2 v6DHCPEnabled v6DHCPServers v6DNS1 v6DNS2 v6SiteLocal v6SiteLocal3 v6SiteLocal4 v6SiteLocal5 v6SiteLocal6 v6SiteLocal7 v6SiteLocal8 v6SiteLocal9 v6SiteLocal10 v6SiteLocal11 v6SiteLocal12 v6SiteLocal13 v6SiteLocal14 v6SiteLocal15 ipmiLAN ipmiMinPriv ipmiKey hostname ]
Instance Attribute Summary
Attributes inherited from BaseLom
Instance Method Summary collapse
- #authenticate ⇒ Object
- #boot_on(level) ⇒ Object
- #detect ⇒ Object
- #drac_set_params(params) ⇒ Object
- #enable_ipmi ⇒ Object
- #fetch_console_preview ⇒ Object
- #get_infos(keys) ⇒ Object
- #infos ⇒ Object
-
#initialize(hostname, options = {}) ⇒ Idrac7
constructor
A new instance of Idrac7.
- #jnlp ⇒ Object
- #logout ⇒ Object
- #lomreset ⇒ Object
- #power_control(action) ⇒ Object
- #pstatus ⇒ Object
- #set_params ⇒ Object
Methods inherited from BaseLom
Constructor Details
#initialize(hostname, options = {}) ⇒ Idrac7
Returns a new instance of Idrac7.
24 25 26 27 28 29 |
# File 'lib/moob/idrac7.rb', line 24 def initialize hostname, = {} super hostname, @username ||= 'root' @password ||= 'calvin' @index = nil end |
Instance Method Details
#authenticate ⇒ Object
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/moob/idrac7.rb', line 31 def authenticate @session. nil # Needed for new version of iDrac emb web server to even responde @session.headers['Accept-Language'] = 'en-US,en;q=0.8,sv;q=0.6' # idrac7 responds with a 404 if the request is sent for html is sent without encoding headers @session.headers['Accept-Encoding'] = 'gzip,deflate,sdch' 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 #1.30.30 (Build 43) introduced a nag to change credentials. bypass it. if @indexurl =~ /defaultCred/ @indexurl.gsub!(/defaultCred/,'index') Moob.inform "iDRAC recommends you should change the default credentials!" end Moob.inform "Requesting indexurl of #{@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. @authhash = @indexurl.split('?')[1] @authhash =~ /ST2=([0-9a-f]+)/ @st2 = $1 if @st2.nil? Moob.inform 'Trying to parse ST2 token from HTML page' @index = @session.get @indexurl @index.body =~ /var TOKEN_VALUE = "([0-9a-f]+)";/ raise ResponseError.new @index unless @index.status == 200 @st2 = $1 end @session.headers['ST2'] = @st2 return self end |
#boot_on(level) ⇒ Object
126 127 128 129 130 |
# File 'lib/moob/idrac7.rb', line 126 def boot_on level req = @session.post "data?set=vmBootOnce:1,firstBootDevice:#{level}", {} raise ResponseError.new req unless req.status == 200 return nil end |
#detect ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/moob/idrac7.rb', line 96 def detect begin home = @session.get 'login.html' home.body =~ /(Integrated Dell Remote Access Controller 7)|(iDRAC7)/ rescue false end end |
#drac_set_params(params) ⇒ Object
207 208 209 210 211 212 213 |
# File 'lib/moob/idrac7.rb', line 207 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
203 204 205 |
# File 'lib/moob/idrac7.rb', line 203 def enable_ipmi drac_set_params({ 'ipmiLAN' => 1 }) end |
#fetch_console_preview ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/moob/idrac7.rb', line 218 def fetch_console_preview imgfile = Tempfile.new('console_preview') refreshreq = @session.get "data?get=consolepreview[auto%20#{Time.now.utc.to_i}]", {} raise ResponseError.new req unless refreshreq.status == 200 req = @session.get_file "capconsole/scapture0.png?#{Time.now.utc.to_i}", imgfile.path raise ResponseError.new req unless req.status == 200 content_type = req.headers['Content-type'] || req.headers['Content-Type'] raise "Unexpected content type #{content_type}, expected 'image/' prefix" unless content_type =~ /image\// return imgfile, req.headers end |
#get_infos(keys) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/moob/idrac7.rb', line 178 def get_infos keys Moob.inform "Requesting data?get=#{keys.join(',')}" 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
174 175 176 |
# File 'lib/moob/idrac7.rb', line 174 def infos return JSON.pretty_generate get_infos INFO_FIELDS end |
#jnlp ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/moob/idrac7.rb', line 107 def jnlp # Request system name and hostname from data end-point req = get_infos ['sysDesc' ,'hostname'] # eg escaped "idrac-A1BCD2E, PowerEdge R610, User:root" title = CGI::escape "#{req['hostname']}, #{req['sysDesc']}, User:#{@username}" viewer = @session.get "viewer.jnlp(#{@hostname}@0@#{title}@#{Time.now.to_i * 1000}@#{@authhash})" raise ResponseError.new viewer unless viewer.status == 200 return viewer.body end |
#logout ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/moob/idrac7.rb', line 86 def logout if @skiplogout Moob.inform 'Skipping logout...' else out = @session.get 'data/logout' raise ResponseError.new out unless out.status == 200 end return self end |
#lomreset ⇒ Object
236 237 238 239 |
# File 'lib/moob/idrac7.rb', line 236 def lomreset @skiplogout = true drac_set_params({ 'iDracReset' => 1 }) end |
#power_control(action) ⇒ Object
120 121 122 123 124 |
# File 'lib/moob/idrac7.rb', line 120 def power_control action req = @session.post "data?set=pwState:#{action}", {} raise ResponseError.new req unless req.status == 200 return nil end |
#pstatus ⇒ Object
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/moob/idrac7.rb', line 162 def pstatus case get_infos(['pwState'])['pwState'] when '0' return :off when '1' return :on else return nil end end |
#set_params ⇒ Object
195 196 197 198 199 200 |
# File 'lib/moob/idrac7.rb', line 195 def set_params unless @params raise "Params are not set!" end drac_set_params @params end |