Created
January 7, 2019 21:50
-
-
Save michaeljs1990/4f09f3588400d5c85692f8e91e58e2d0 to your computer and use it in GitHub Desktop.
Ruby IPMI Collins Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Fetch root credentials for ipmi login to server | |
require 'collins_client' | |
require 'yaml' | |
@collins_config = Dir.home + "/.collins.yaml" | |
@hostname = ARGV.shift | |
@cmd = ARGV.shift | |
@user_num = ARGV.shift | |
@timeout = 10 | |
abort "Give me a hostname to connect to and command" unless @hostname | |
c = YAML.load_file(@collins_config) | |
collins = Collins::Client.new c | |
assets = collins.find(:hostname => @hostname, :details => true) | |
assets = collins.find(:tag => @hostname, :details => true) if assets.empty? | |
abort "More than 1 node found like #{@hostname} (found #{assets.length}). Please be more specific...\n#{assets.map {|a| a.hostname}.join "\n"}\n" if assets.length != 1 | |
node = assets.first | |
puts "Connecting to #{node.hostname} ipmi..." | |
base_cmd = "ipmitool -H #{node.ipmi.address} -U #{node.ipmi.username} -P #{node.ipmi.password} -I lanplus" | |
if @cmd == "sol" | |
exec "#{base_cmd} sol activate" | |
elsif @cmd == "soli" | |
exec "#{base_cmd} sol info" | |
elsif @cmd == "deactivate" | |
exec "#{base_cmd} sol deactivate" | |
elsif @cmd == "list" | |
exec "#{base_cmd} user list 1" | |
elsif @cmd == "enable" | |
exec "#{base_cmd} sol payload enable 1 #{@user_num}" | |
elsif @cmd == "lan" | |
exec "#{base_cmd} lan print" | |
elsif @cmd == "force_bios" | |
exec "#{base_cmd} chassis bootparam set bootflag force_bios" | |
else | |
exec "#{base_cmd} -vvv #{@cmd}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment