Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ruby IPMI Collins Script
#!/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
You can’t perform that action at this time.