Module: CommandMixins::Password

Included in:
DRACCommands::Password, SMCCommands::Password
Defined in:
lib/setup_oob/command/mixins.rb

Instance Method Summary collapse

Instance Method Details

#_converge!Object



225
226
227
228
229
230
# File 'lib/setup_oob/command/mixins.rb', line 225

def _converge!
  unless password_set?
    logger.info(' - Setting password')
    set_password
  end
end

#_converged?Boolean

Returns:



221
222
223
# File 'lib/setup_oob/command/mixins.rb', line 221

def _converged?
  password_set?
end

#ipmicmd(set = false) ⇒ Object



266
267
268
# File 'lib/setup_oob/command/mixins.rb', line 266

def ipmicmd(set = false)
  smc? ? basecmd(set) : SMCCommandBase.basecmd('localhost')
end

#passwordObject



217
218
219
# File 'lib/setup_oob/command/mixins.rb', line 217

def password
  @data
end

#password_set?Boolean

It turns out that ‘ipmitool user test’ and ‘ipmitool user set’ work fairly unversally. And there’s no way to do ‘user test’ in racadm. So this should work pretty much everywhere.

Though… ‘ipmitool user list’, for some reason, is not so universal. Womp Womp.

Returns:



242
243
244
245
246
247
# File 'lib/setup_oob/command/mixins.rb', line 242

def password_set?
  id = admin_id
  cmd = ipmicmd + ['user', 'test', id, smc? ? '20' : '16', password]
  s = run(cmd, false)
  !s.error?
end

#set_passwordObject



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/setup_oob/command/mixins.rb', line 249

def set_password
  id = admin_id
  cmd = ipmicmd(true) + ['user', 'set', 'password', id, password]
  s = run(cmd)
  if s.error?
    # if the password isn't what we expect *and* isn't ADMIN, it may be
    # serial or an old password. We can reset it to ADMIN
    # NOTE: this actually resets ALL it's settings. Which is OK because
    # we set password first, so the rest will get set properly
    run(ipmicmd(true) + ['raw', '0x30', '0x48', '0x1'])
    # takes about  seconds for it to come to its senses
    sleep(5)
    # now, try again
    run(cmd)
  end
end

#smc?Boolean

Returns:



232
233
234
# File 'lib/setup_oob/command/mixins.rb', line 232

def smc?
  @smc ||= self.class.to_s.start_with?('SMC')
end