Last active
August 29, 2015 14:00
-
-
Save lamw/11322180 to your computer and use it in GitHub Desktop.
Enhancement to RVC cluster.add_host to extract SSL Thumbprint of ESXi host w/o having to run commmand twice
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
opts :add_host2 do | |
summary "Add a host to a cluster" | |
arg :cluster, nil, :lookup => VIM::ClusterComputeResource | |
arg :hostnames, nil, :multi => true | |
opt :username, "Username", :short => 'u', :default => 'root' | |
opt :password, "Password", :short => 'p', :default => '' | |
opt :force, "Force, e.g when host is already managed by other VC" | |
end | |
def add_host2 cluster, hostnames, opts | |
sslThumbprint = nil | |
hostnames.each do |hostname| | |
while true | |
`echo "" | openssl s_client -connect #{hostname}:443 2> /dev/null 1> /tmp/cert` | |
sslThumbprint = `openssl x509 -in /tmp/cert -fingerprint -sha1 -noout | awk -F '=' '{print $2}'`.delete!("\n") | |
spec = { | |
:force => opts[:force], | |
:hostName => hostname, | |
:userName => opts[:username], | |
:password => opts[:password], | |
:sslThumbprint => sslThumbprint, | |
} | |
puts spec | |
task = cluster.AddHost_Task :spec => spec, | |
:asConnected => true | |
begin | |
one_progress task | |
break | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment