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
- #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.
23 24 25 26 27 28 |
# File 'lib/moob/idrac7.rb', line 23 def initialize hostname, = {} super hostname, @username ||= 'root' @password ||= 'calvin' @index = nil end |
Instance Method Details
#authenticate ⇒ Object
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 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/moob/idrac7.rb', line 30 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 #1.30.30 (Build 43) introduced a nag to change credentials. bypass it. if @indexurl =~ /defaultCred/ @indexurl.gsub!(/defaultCred/,'index') Moob.warn "iDRAC recommends you should change the default credentials!" end 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 TOKEN_VALUE = "([0-9a-f]+)";/ raise ResponseError.new @index unless @index.status == 200 @st2 = $1 @session.headers['ST2'] = @st2 return self end |
#boot_on(level) ⇒ Object
116 117 118 119 120 |
# File 'lib/moob/idrac7.rb', line 116 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
81 82 83 84 85 86 87 88 |
# File 'lib/moob/idrac7.rb', line 81 def detect begin home = @session.get 'login.html' home.body =~ /Integrated Dell Remote Access Controller 7/ rescue false end end |
#drac_set_params(params) ⇒ Object
196 197 198 199 200 201 202 |
# File 'lib/moob/idrac7.rb', line 196 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
192 193 194 |
# File 'lib/moob/idrac7.rb', line 192 def enable_ipmi drac_set_params({ 'ipmiLAN' => 1 }) end |
#fetch_console_preview ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/moob/idrac7.rb', line 207 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 raise UnexpectedContentError.new req unless req.headers['Content-type'] =~ /image\// return imgfile, req.headers end |
#get_infos(keys) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/moob/idrac7.rb', line 168 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
164 165 166 |
# File 'lib/moob/idrac7.rb', line 164 def infos return JSON.pretty_generate get_infos INFO_FIELDS end |
#jnlp ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/moob/idrac7.rb', line 92 def jnlp @index.body =~ /var tmpHN += +"([^"]+)"/ raise "Couldn't find the DNS name" unless $& dns_name = $1 @index.body =~ /var sysNameStr += +"([^"]+)"/ raise "Couldn't find the system name" unless $& sys_name = $1 # eg PowerEdge R610 # eg escaped "idrac-A1BCD2E, PowerEdge R610, User:root" title = CGI::escape "#{dns_name}, #{sys_name}, 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
75 76 77 78 79 |
# File 'lib/moob/idrac7.rb', line 75 def logout out = @session.get 'data/logout' raise ResponseError.new out unless out.status == 200 return self end |
#power_control(action) ⇒ Object
110 111 112 113 114 |
# File 'lib/moob/idrac7.rb', line 110 def power_control action req = @session.post "data?set=pwState:#{action}", {} raise ResponseError.new req unless req.status == 200 return nil end |
#pstatus ⇒ Object
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/moob/idrac7.rb', line 152 def pstatus case get_infos(['pwState'])['pwState'] when '0' return :off when '1' return :on else return nil end end |
#set_params ⇒ Object
184 185 186 187 188 189 |
# File 'lib/moob/idrac7.rb', line 184 def set_params unless @params raise "Params are not set!" end drac_set_params @params end |