Does not work with vSphere > 6.0 as the URL is always protected by SSO and the pre-auth ticket is ignored.
Created
May 9, 2017 09:53
-
-
Save timogoebel/c8a915dc4fae9b79c8733cc7a2796038 to your computer and use it in GitHub Desktop.
vmware vsphere html5 console
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
source 'https://rubygems.org' | |
gem 'fog' | |
gem 'fog-vsphere' | |
gem 'awesome_print' | |
gem 'pry' |
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
#!/usr/bin/env ruby | |
require 'fog' | |
require 'awesome_print' | |
require 'pry' | |
client = ::Fog::Compute.new( | |
:provider => 'vsphere', | |
:vsphere_username => 'xxx', | |
:vsphere_password => 'xxx', | |
:vsphere_server => 'xxx', | |
:vsphere_expected_pubkey_hash => 'xxx', | |
) | |
name = 'test.example.com' | |
vm = client.servers.get(name) | |
search_filter = { :uuid => vm.instance_uuid, 'vmSearch' => true, 'instanceUuid' => true } | |
vm_mob_ref = client.connection.searchIndex.FindAllByUuid(search_filter).first | |
ticket = vm_mob_ref.AcquireTicket(:ticketType => 'webmks') | |
server = client.vsphere_server | |
port = '9443' | |
vm_mo_ref_id = vm.mo_ref | |
vm_name = vm.name | |
server_guid = client.connection.serviceContent.about.instanceUuid | |
vcenter_fqdn = client.connection.serviceContent.setting.setting.find {|setting| setting.key == 'VirtualCenter.FQDN' }.value | |
session = client.connection.serviceContent.sessionManager.AcquireCloneTicket | |
ssl_thumbprint = ticket.sslThumbprint | |
url = "https://#{server}:#{port}/vsphere-client/webconsole.html?vmId=#{vm_mo_ref_id}&vmName=#{vm_name}&serverGuid=#{server_guid}&host=#{vcenter_fqdn}&sessionTicket=#{session}&thumbprint=#{ssl_thumbprint}" | |
puts url | |
sleep 180 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment