Skip to content

Instantly share code, notes, and snippets.

@lamw
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lamw/11322180 to your computer and use it in GitHub Desktop.
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
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