The demo consists of an index html page which more-or-less just includes the two jquery files and the demo.js file. The simplest way of trying it out is to is to put the files onto the XenServer to be served by the integrated web server. This is done by creating the webserver root directory ‘/opt/xensource/www’ and copying the files in. Alternatively, and more usefully, the files can be loaded locally from a file:// URI. However, this is more tricky because there may well be cross-site scripting protection built into the browser – certainly Firefox has this feature and there are commented-out lines in the demo files explaining how to deal with this.
I’ll just describe here the demo.js file. To talk to the XenServer, we must first create the jquery rpc object. In versions of XenServer prior to 5.0 the system.listMethods method was not implemented, so we have to explicitly list the methods that we’ll be using when creating the rpc object.
In this case, we’re only going to use two API calls. Of the other parameters, ‘actual_uri’ is the URI of the XenServer to connect to, and could be e.g. “http://<ip>/” if the files are not being hosted by XenServer, or simply “/” if they are. ‘nextfn’ is the function to call on successful creation of the rpc object. Once the object is initialised, we can call API functions:
Next time I’ll explain how the event mechanism works, and how it can be used to keep an up-to-date cache of the entire XenServer database.