pyvmomi-community-samples icon indicating copy to clipboard operation
pyvmomi-community-samples copied to clipboard

vSphere 6.7 vm html console

Open plrnr opened this issue 6 years ago • 15 comments

I used this script here: https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/generate_html5_console.py to generate link but it doesnt work, see below.

I get this link from script:

http://myvcenter:7331/console/?vmId=vm-429&vmName=myvm&host=myvcenter>&sessionTicket=cst-VCT-5287c10e-1edf-e6e3-abc5-b6020891467e--tp-BE-D6-93-F7-1B-87-AD-4F-6A-4B-A6-11-83-86-3F-EB-4D-0F-CB-7A&thumbprint=BE:D6:93:F7:1B:87:AD:4F:6A:4B:A6:11:83:86:3F:EB:4D:0F:CB:7A

The error I get on browser is: This site can’t be reached

It seems like port 7331 is not even open on vcenter server.

Could this be due to version 6.7 ? if yes, is there a way I can get html console for a VM?

plrnr avatar Apr 08 '19 19:04 plrnr

Hi plrnr,

The below modified code is working , please try.

def get_guest_console(service_instance):

search_index = service_instance.content.searchIndex
serverGuid = service_instance.content.about.instanceUuid

vm = search_index.FindByUuid(None, "5016531e-0c73-064e-e9fe-bcee63cd6847", True, True)
content = service_instance.RetrieveContent()
vcenter_data = content.setting
vm_moid = vm._moId
vcenter_settings = vcenter_data.setting
console_port = '9443'

for item in vcenter_settings:
    key = getattr(item, 'key')
    if key == 'VirtualCenter.FQDN':
        vcenter_fqdn = getattr(item, 'value')

session_manager = content.sessionManager
session = session_manager.AcquireCloneTicket()
print(type(session))
vc_cert = ssl.get_server_certificate(("VCIP", 443))
vc_pem = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, vc_cert)
vc_fingerprint = vc_pem.digest('sha1')
print(type(vc_fingerprint))
print("console_op","https://" + "VCIP" + ":" + console_port + "/vsphere-client/webconsole.html?vmId=" + str(vm_moid) + "&vmName=" + vm.name + "&serverGuid=" + serverGuid + "&host=" + vcenter_fqdn + ":443&sessionTicket=" + session + "&thumbprint=" + str(vc_fingerprint) + "&locale=en-US")

def main(): """ Command-line program for listing the events on a system. """ args = cli.get_args() context = ssl._create_unverified_context() if args.disable_ssl_verification: service_instance = SmartConnect(host=args.host, user=args.user, pwd=args.password, port=int(args.port), sslContext=context) else: service_instance = SmartConnect(host=args.host, user=args.user, pwd=args.password, port=int(args.port))

atexit.register(Disconnect, service_instance)
get_guest_console(service_instance)

Start program

if name == "main": main()

VMuuid and VC ip not passing command line argument

Thanks, Shweta

shwetapurohit avatar Apr 09 '19 06:04 shwetapurohit

hi Shweta,

Thanks for that! Can you confirm your vCenter version please?

plrnr avatar Apr 09 '19 22:04 plrnr

Ok, just tried your script and I do some progress. However,

  1. It takes me to login page to vCenter.
  2. After I login with my vcenter credentails, it does open the console but it says below: The console has been disconnected. Close this window and re-launch the console to reconnect.

And it just gives me the same message even if I close/re-launch...

Please do let me know what vCenter version do you have?

plrnr avatar Apr 09 '19 23:04 plrnr

Hi Plrnr,

Try constructing url as below,

print("console_op","https://" + "VCIP" + "/ui/webconsole.html?vmId=" + str(vm_moid) + "&vmName=" + vm.name + "&serverGuid=" + serverGuid + "&host=" + vcenter_fqdn + ":443&sessionTicket=" + session + "&thumbprint=" + str(vc_fingerprint) + "&locale=en-US")

  1. Yes , you should login to vcenter
  2. After constructing the url above, you can able to connect to VM web console
  3. I tried with 6.7 and above versions

Thanks, Shweta

shwetapurohit avatar Apr 10 '19 09:04 shwetapurohit

what about pre-authenticate url? Can I use the authentication session to forward a request to this generated url?

joaoreis81 avatar Apr 28 '19 01:04 joaoreis81

hi,

I still get the same message: The console has been disconnected. Close this window and re-launch the console to reconnect.

Does the session ticket we get has any expiry time?

plrnr avatar May 15 '19 20:05 plrnr

Here is the link script generates:

https://myvcsa.local:9443/vsphere-client/webconsole.html?vmId=vm-429&vmName=newvm&serverGuid=35b995f7-4098-40e3-aa30-d6c5d1e86891&host=myvcsa.local:443&sessionTicket=cst-VCT-52b353cf-65dc-f293-0bfe-03f3ce59703c--tp-BE-D6-93-F7-1B-87-AD-4F-6A-4B-A6-11-83-86-3F-EB-4D-0F-CB-7A&thumbprint=BE:D6:93:F7:1B:87:AD:4F:6A:4B:A6:11:83:86:3F:EB:4D:0F:CB:7A&locale=en-US

plrnr avatar May 15 '19 21:05 plrnr

Here is my code:

content = si.RetrieveContent()
serverGuid = content.about.instanceUuid
vm_moid = vmRef._moId
vcenter_data = content.setting
vcenter_settings = vcenter_data.setting
console_port = '9443'
serverIp = 'myvcsa.local'
httpsPort = 443
for item in vcenter_settings:
    key = getattr(item, 'key')
    if key == 'VirtualCenter.FQDN':
        vcenter_fqdn = getattr(item, 'value')
session_manager = content.sessionManager
sessionTicket = session_manager.AcquireCloneTicket()

ssl._create_default_https_context = ssl._create_unverified_context
vc_cert = ssl.get_server_certificate((serverIp, httpsPort))
vc_pem = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM,
                                         vc_cert)
vc_fingerprint = vc_pem.digest('sha1')
print("console_op", "https://" + serverIp + ":" + console_port + "/vsphere-client/webconsole.html?vmId=" + str(vm_moid) + "&vmName=" + vmName +
      "&serverGuid=" + serverGuid + "&host=" + vcenter_fqdn + ":443&sessionTicket=" + sessionTicket + "&thumbprint=" + str(vc_fingerprint) + "&locale=en-US")

plrnr avatar May 15 '19 23:05 plrnr

I've been dealing with this same issue @plrnr. Works great in vCenter 6.5, but not vCenter 6.7.

I've noticed a couple of things that might be handy:

  • The end point /vsphere-client/webconsole.html gives me a login screen, but like you, results in a "console has been disconnected" error
  • The end point /ui/webconsole.html gives no login prompt. However, if I have vCenter opened in another tab (i.e. already have a valid session), the link works and I get the console.

@aspurohit you sure you didn't have an active session in a different tab while testing?

willnx avatar May 20 '19 16:05 willnx

@willnx Thanks for responding. Its a relief to know that it is something on 6.7 version. I am going to bring up a 6.5 environment and try.

plrnr avatar May 20 '19 19:05 plrnr

Confirmed it works on 6.5!

plrnr avatar May 21 '19 18:05 plrnr

Hi Plrnr/wilnx,

  1. I tried with end point "/vsphere-client/webconsole.html" gives me login page , for 6.5,6.7 and latest vcenter version. I am not facing any error. I could login successfully.
  2. And end point "/ui/webconsole.html" gives me no login prompt. I found this issue earlier also.

Thanks, Shweta

shwetapurohit avatar May 24 '19 07:05 shwetapurohit

@plrnr @willnx . do you get any solutions? i have beening blocked by this issue for months. for vc6.0--6.5, inputing username and password in the sso login page and click login then the vm console shows as expected, but vc6.7 ,after login,I get the message: The console has been disconnected. Close this window and re-launch the console to reconnect.

wenhuliu avatar Jun 28 '19 02:06 wenhuliu

I never was able to figure out a solution on 6.7. I have not tried on the latest 7.0 version.

plrnr avatar Sep 16 '20 20:09 plrnr

i checked it works on vsphere 7 with a change in url at the beginning, see below. It does not have a 9443 port and uses "ui" instead of vsphere-client

https://vcsa7-dev.atg.lc/ui/webconsole.html?

plrnr avatar Dec 14 '20 20:12 plrnr