Created
January 7, 2019 21:50
-
-
Save michaeljs1990/4f09f3588400d5c85692f8e91e58e2d0 to your computer and use it in GitHub Desktop.
Revisions
-
michaeljs1990 created this gist
Jan 7, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ #!/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