Connect to VM without XenCenter

Written by Ingmar Verheij on February 2nd, 2012. Posted in PowerShell, XenServer

Author: Ingmar Verheij

If you want to connect to the console of a virtual machine running on Citrix XenServer you either need XenCenter or the Web Self Service portal.

I created a PowerShell script that connects to the console of the virtual machine, without the use of both. This script can be used to offer a shortcut to a virtual machine without requiring the user to have XenCenter installed, or having a XenServer Enterprise or Platinum license (it works with the free license).

VNC

XenServer uses virtual network computing (VNC) to connect to the console of a virtual machine. In this script I’m using the TightVNC viewer to connect to the console, but you can use any other VNC viewer (although it requires you to change the script and might give issues when used via Citrix ICA).

SSH tunnel

The VNC connector on the XenServer only listens on the localhost, so you’re unable to connect to it directly. Before you can connect your VNC viewer to the console you need to tunnel the data through an SSL tunnel. This will encapsulate all VNC data through a secured channel and deliver it on the XenServer. I’m using plink (a component of the PuTTY suite) to send SSH commands and setup a SSL tunnel between the host and the XenServer host (just like XenCenter does when you connect to the console of a VM).

Note: The sa2 key fingerprint is accepted automatically by the script.

Note: I’m aware there is a Powershell cmdlet for SSH (which could prevent the use of plink) but this cmdlet is unable to set up a SSL tunnel.

Connect to who and where?

Before you can setup the SSL tunnel you need to know two thing. The XenServer the VM is running on (1) and the port the VNC server is running on (2). So before setting up the SSL tunnel I’m querying the XenServer (pool master)  for IP address of the XenServer host where the VM is running.

The name of my virtual machine is ‘WS01’ and I added custom field ‘STUDENT’ with the value ‘1’.

Now I know the IP address of the XenServer where the VM is running I can search for the domain ID of the virtual machine. With the domain ID I can search for the VNC server process qemu-dm-<domid>.

Okay, so now I know the IP address of the XenServer where the VM is running (1) and the port where the VNC host is running (2).

 

Connecting though ICA (Citrix XenApp / XenDesktop)

I published the console of a virtual machine as a published application so my users can access the console from anywhere (via the CloudGateway). During testing I found out that both RealVNC and UltraVNC had performance issues, only TightVNC in 8-bit mode worked at a proper speed.

If you don’t want the connect in 8-bit mode, change the line $vncUse8Bit=$true to $vncUse8Bit=$false.

 Published Application 'Workstation 1'PowerShellRemote console via published application

 

PowerShell script (this is where it’s all about)

Download:  ConsoleXSConnect.ps1

 

Usage

The script requires 4 arguments and has 2 optional arguments

XenServerPoolMaster: The IP/FQDN of the XenServer (pool master) host

XenServerUsername: The username to connect to the XenServer

XenServerPAssword: The password to connect to the XenServer

VMName: The name of the virtual machine

CustomFieldName (optional): The name of a custom field

CustomFieldValue (optional): The value of the custom field

 

The custom field can be used to uniquely identify a virtual machine if the name of the machine is reused. In my environment I cloned the virtual machine ‘WS01’ multiple times and added a CustomField ‘STUDENT’. For each student a virtual machine is published.

'WS01' Properties.

 

Additional downloads (required)

 

Additional information

Ingmar Verheij

Ingmar Verheij works for PepperByte as a Senior Consultant. His work consist of designing, migrating and troubleshooting Microsoft and Citrix infrastructures. He is working with technologies like Microsoft RDS, user environment management and (performance) monitoring. Ingmar is in the steering group of the Dutch Citrix User Group (DuCUG). RES Software named Ingmar RES Software Valued Professional in 2014.

More Posts - Website

Follow Me:
TwitterLinkedInGoogle Plus

Tags: , , , ,

Leave a comment

*

%d bloggers like this: