Class: Moob::Idrac6

Inherits:
BaseLom show all
Defined in:
lib/moob/idrac6.rb

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

Instance Attribute Summary

Attributes inherited from BaseLom

#hostname, #username

Instance Method Summary collapse

Methods inherited from BaseLom

action, actions, name

Constructor Details

#initialize(hostname, options = {}) ⇒ Idrac6

Returns a new instance of Idrac6.


26
27
28
29
30
# File 'lib/moob/idrac6.rb', line 26

def initialize hostname, options = {}
  super hostname, options
  @username ||= 'root'
  @password ||= 'calvin'
end

Instance Method Details

#authenticateObject


32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/moob/idrac6.rb', line 32

def authenticate
  @session.handle_cookies nil
  start = @session.get 'start.html'
  raise ResponseError.new start unless start.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"
  return self
end

#boot_on(level) ⇒ Object


90
91
92
93
94
# File 'lib/moob/idrac6.rb', line 90

def boot_on level
  req = @session.post "data?set=vmBootOnce:1,firstBootDevice:#{level}", {}
  raise ResponseError.new req unless req.status == 200
  return nil
end

#detectObject


53
54
55
56
57
58
59
60
# File 'lib/moob/idrac6.rb', line 53

def detect
  begin
    home = @session.get 'login.html'
    home.body =~ /Integrated Dell Remote Access Controller 6/
  rescue
    false
  end
end

#drac_set_params(params) ⇒ Object


170
171
172
173
174
175
176
# File 'lib/moob/idrac6.rb', line 170

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_ipmiObject


166
167
168
# File 'lib/moob/idrac6.rb', line 166

def enable_ipmi
  drac_set_params({ 'ipmiLAN' => 1 })
end

#fetch_console_previewObject


181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/moob/idrac6.rb', line 181

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


142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/moob/idrac6.rb', line 142

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

#infosObject


138
139
140
# File 'lib/moob/idrac6.rb', line 138

def infos
  return JSON.pretty_generate get_infos INFO_FIELDS
end

#jnlpObject


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/moob/idrac6.rb', line 63

def jnlp
  idx = @session.get 'index.html'
  raise ResponseError.new idx unless idx.status == 200

  idx.body =~ /var DnsName += +"([^"]+)"/
  raise "Couldn't find the DNS name -- is the iDRAC running firmware 1.50 or higher?" unless $&
  dns_name = $1

  idx.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}@[email protected]#{title}@#{Time.now.to_i * 1000})"
  raise ResponseError.new viewer unless viewer.status == 200

  return viewer.body
end

#logoutObject


47
48
49
50
51
# File 'lib/moob/idrac6.rb', line 47

def logout
  out = @session.get 'data/logout'
  raise ResponseError.new out unless out.status == 200
  return self
end

#power_control(action) ⇒ Object


84
85
86
87
88
# File 'lib/moob/idrac6.rb', line 84

def power_control action
  req = @session.post "data?set=pwState:#{action}", {}
  raise ResponseError.new req unless req.status == 200
  return nil
end

#pstatusObject


126
127
128
129
130
131
132
133
134
135
# File 'lib/moob/idrac6.rb', line 126

def pstatus
  case get_infos(['pwState'])['pwState']
  when '0'
    return :off
  when '1'
    return :on
  else
    return nil
  end
end

#set_paramsObject


158
159
160
161
162
163
# File 'lib/moob/idrac6.rb', line 158

def set_params
  unless @params
    raise "Params are not set!"
  end
  drac_set_params @params
end