Class: SMCCommandBase
- Inherits:
-
CommandBase
- Object
- CommandBase
- SMCCommandBase
- Defined in:
- lib/setup_oob/command/smc.rb
Overview
A slight extension of the Command class to add some SMC-specific utility functions. Will be the base class for all SMC commands
Direct Known Subclasses
SMCCommands::Ddns, SMCCommands::Hostname, SMCCommands::License, SMCCommands::Networkmode, SMCCommands::Networksrc, SMCCommands::Ntp, SMCCommands::Password
Constant Summary collapse
- DEFAULT_PASSWORD =
'ADMIN'.freeze
- USER =
'ADMIN'.freeze
- COMMANDS =
{ :hostname => [0x47], :ntp => [0x68, 0x01], :ddns => [0x68, 0x04], :networkmode => [0x70, 0x0c], :isactivated => [0x6A], :setlicense => [0x69], # some magic set of bytes for firmware version and mac ... }.freeze
- ACTIONS =
{ :get => [0x00], :set => [0x01], }.freeze
Instance Attribute Summary
Attributes inherited from CommandBase
Class Method Summary collapse
Instance Method Summary collapse
- #basecmd(defaultpass = false) ⇒ Object
-
#cmdbytes(command, action = nil) ⇒ Object
Get the IPMI bytes for the command we want to run.
- #enabled? ⇒ Boolean
-
#rawcmd(data) ⇒ Object
Builds the ‘raw’ command using ‘data’.
-
#runraw(data) ⇒ Object
Wrapper to build the “raw” command, run it, and convert the answer into an array of actual integers.
Methods inherited from CommandBase
#converge!, #converged?, #initialize
Constructor Details
This class inherits a constructor from CommandBase
Class Method Details
.basecmd(host, user = nil, pass = nil) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/setup_oob/command/smc.rb', line 76 def self.basecmd(host, user = nil, pass = nil) if host == 'localhost' ['ipmitool'] else unless user && pass fail 'basecmd: No user and password sent with host' end [ 'ipmitool', '-H', host, '-U', user, '-P', pass ] end end |
Instance Method Details
#basecmd(defaultpass = false) ⇒ Object
72 73 74 |
# File 'lib/setup_oob/command/smc.rb', line 72 def basecmd(defaultpass = false) SMCCommandBase.basecmd(@host, @user, defaultpass ? 'ADMIN' : @password) end |
#cmdbytes(command, action = nil) ⇒ Object
Get the IPMI bytes for the command we want to run
52 53 54 55 56 57 58 |
# File 'lib/setup_oob/command/smc.rb', line 52 def cmdbytes(command, action = nil) data = [0x30] + COMMANDS[command] if action data += ACTIONS[action] end data end |
#enabled? ⇒ Boolean
41 42 43 44 45 46 47 48 49 |
# File 'lib/setup_oob/command/smc.rb', line 41 def enabled? # assumes a sub-classed cmdbytes data = cmdbytes(:get, :enabled) out = runraw(data) # if the first byte is 1, "it" is enabled, whatever "it" is en = out[0] == 1 logger.debug("#{pretty_self} enabled: #{en}") en end |
#rawcmd(data) ⇒ Object
Builds the ‘raw’ command using ‘data’
68 69 70 |
# File 'lib/setup_oob/command/smc.rb', line 68 def rawcmd(data) basecmd + ['raw'] + data.map(&:to_s) end |
#runraw(data) ⇒ Object
Wrapper to build the “raw” command, run it, and convert the answer into an array of actual integers.
62 63 64 65 |
# File 'lib/setup_oob/command/smc.rb', line 62 def runraw(data) s = run(rawcmd(data)) s.stdout.split.map { |x| x.to_i(16) } end |