Xen Console Internals (AJAXify your XenU)!

Xen Console Internals (AJAXify your XenU)!

One of the holy grails for the Enomalism project is the ability to have remote serial console over AJAX, without needing to have a running SSH daemon on the DomU. I recently solved this problem (which is going to be part of the core open source release) and thought I would document it here. After all, there could be ANOTHER nerd who needs to write an application that takes control of the virtual serial Xen consoles without using expect. Xen serial consoles are amazingly simple, robust, and eliminate the need for SSH on your DomU.

Note: This post has become somewhat obsolete, since I have found the method for reading XenStoreD directly

Normally when I want to do something wierd with Xen, I start digging around in the source code in /usr/lib/python/xen/xm/main.py , and this was no exception. Unlike usual, this time I was left with a dead end when I discovered that Xen launches a "black box" C application to provide Xen console services. That sucks (and why would anyone write a console APP in C anymore)? This left me digging around in the xenstored directory. I found out that there is useful information about the terminals stored here:

/var/lib/xenstored/store/domain/[XEN UUID of your XenU here]/console/tty

Hmmm. Closer, but we need our uuid! That turns out to be easy either via:

xm list --long [your domname]

or, even better:

#!/bin/env python
import os, sys
sys.path.append( '/usr/lib/python' ) #Required to import from /usr/lib/python for FC4
import xen.xm.main as xenxm
temp=xenxm.getDomains(['yourdomnamehere'])
uuid=None
for item in temp[0][1:]:
    if item[0]=='uuid':
            uuid=item[1]
            break;
print uuid

So now we need to see how the console works. While it is easy to connect using xm console [your DomU], I want to be... a little more direct.

The UUCP package includes a command called cu, which allows you to connect the currently running terminal to another device.

[root@enkitestpig ~]# cu -l /dev/pts/1
Connected.
Fedora Core release 4 (Stentz)
Kernel 2.6.12.6-xenU on an i686

fc4_pristine login:root
Password:XXXXXXXXXX
Last login: Tue May  9 12:54:43 on tty1
[root@fc4_pristine ~]# uname -r
2.6.12.6-xenU
[root@fc4_pristine ~]# ~~.
Disconnected.

Cool, but I noticed I had to hit enter to display the login prompt. Does Xen cache output, or does it toss it away? I was still logged in on the DomU, so...

[root@enkitestpig ~]# echo "ps aux" > /dev/pts/1
[root@enkitestpig ~]# cat /dev/pts/1
ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.4   1740   628 ?        S    12:54   0:05 init [3]
[snip]
root      2941  0.0  1.0   2424  1408 tty1     Ss   14:43   0:00 -bash
root      2958  0.0  0.5   2404   808 tty1     R+   14:45   0:00 ps aux
[root@fc4_pristine ~]#

SWEET! The data is cached between commands, so plain old file operations can be used to read and write the console data. This makes things much easier, since I don't need to store a lot of state data (or complicated classes) between sessions in my TurboGears web app.

Now, I COULD get all crazy and define how I am going to turn this into the AJAX shell, but that is a little overly complex, and I also haven't done it yet. The plan is to use the existing AjaxTerm project's awesome shell emulation, rebuilt to run over TurboGears, and to stuff that into the VM Manager display. More details to follow!

Home Home
http://www.reaysmoving.com/