Skip to content

Instantly share code, notes, and snippets.

@timogoebel
Created May 9, 2017 09:53
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 timogoebel/c8a915dc4fae9b79c8733cc7a2796038 to your computer and use it in GitHub Desktop.
Save timogoebel/c8a915dc4fae9b79c8733cc7a2796038 to your computer and use it in GitHub Desktop.
vmware vsphere html5 console

Does not work with vSphere > 6.0 as the URL is always protected by SSO and the pre-auth ticket is ignored.

source 'https://rubygems.org'
gem 'fog'
gem 'fog-vsphere'
gem 'awesome_print'
gem 'pry'
#!/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