Last active
April 6, 2021 17:39
-
-
Save CognitiveDisson/177344c246d487741c283aeaf368289b to your computer and use it in GitHub Desktop.
Remote execute for anka
This file contains 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
require 'net/http' | |
require 'json' | |
require 'io/console' | |
args = Hash[ ARGV.join(' ').scan(/--?([^=\s]+)(?:=(\S+))?/) ] | |
controller_url = args['controller'] | |
if controller_url.nil? | |
raise "You need to specify the controller: --controller=http://anka.controller.net" | |
end | |
user = args['user'] | |
if user.nil? | |
raise "You need to specify the user: --user=user_name" | |
end | |
pem_path = args['pem'] | |
commands = [ | |
# "/usr/local/bin/anka license show" | |
# "curl -S -L -o ./Anka-2.4.0.129.pkg https://veertu.com/downloads/anka-virtualization-latest" | |
# "sudo installer -pkg Anka-2.4.0.129.pkg -tgt /" | |
"/usr/local/bin/anka version" | |
] | |
def get_nodes(controller_url) | |
url = URI.parse(controller_url + '/api/v1/node') | |
request = Net::HTTP::Get.new(url.to_s) | |
response = Net::HTTP.start(url.host, url.port) do |http| | |
http.request(request) | |
end | |
json = JSON.parse(response.body) | |
nodes = json["body"] | |
end | |
nodes = get_nodes(controller_url).sort_by { |hsh| hsh['node_name'] } | |
nodes.each do |node| | |
node_name = node['node_name'] | |
node_ip_address = node['ip_address'] | |
puts "#{node_name} #{node_ip_address}" | |
commands.each do |command| | |
puts "Execute: #{command}" | |
ssh_command = 'ssh -t' | |
unless pem_path.nil? | |
ssh_command += " -i #{pem_path}" | |
end | |
ssh_command += " #{user}@#{node_ip_address}" | |
ssh_command += " \"#{command}\"" | |
puts `#{ssh_command}` | |
end | |
puts '########################################################' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment