Snapshotting with the XenServer 5.0 SDK

Throughout the past couple of months at Citrix, I’ve been working on our next-generation automation framework: CADI (Citrix Automation Development Infrastructure). This framework empowers our developers to easily create and run automated system tests, which will ultimately result in higher quality products. Just about all of the framework’s functionality is exposed via PowerShell, so for instance we can setup a XenServer virtual machine with the latest XenApp build and launch an ICA session from a remote client to the XenApp server right from the PowerShell CLI.

During this project, I was responsible for driving the design and development of the test environment setup feature. Its main role is to give users the ability to provision machines, install software, and configure them. The automated tests would then take over, try to find bugs in our software, and report their results.

Coming into the project, we knew we wanted to use our lab hardware in the most efficient way and have the ability to take a snapshot of a machine in case we needed to see why a test failed. To achieve this we leveraged XenServer 5.0 whose SDK supports taking and reverting snapshots. This snapshot functionality is not currently available via XenCenter, however for those of your interested I’ve posted the C# take and revert snapshot code here. Please note XenAPI.net, which is released as part of the XenServer 5.0 SDK, is required to compile this.

The TakeSnapshot method is pretty straight forward. It will connect up to the XenServer host, retrieve the specified virtual machine, and call the VM.snapshot method on it. Once this has executed, you will see the snapshot appear as a template on your XenServer.

The RevertSnapshot code on the other hand isn’t very straight forward; however no worries here as I’ll walk through it. The code starts off by connecting to the XenServer host and retrieving the specified virtual machine. Then it does the following:

  1. Retrieve the snapshot we’re interested in. Remember, the snapshots are templates stored on the XenServer and they are linked to their virtual machines. The VM.get_snapshots method allows us to retrieve a virtual machine’s snapshots.
  2. Shutdown the virtual machine we are reverting. This is required as we will be modifying the virtual machine.
  3. Delete all VDIs (virtual disk images), except CDs since they can’t be deleted, and VBDs (virtual block drives) associated with the virtual machine. A VDI is synonymous with a hard drive while a VBD is the component that connects the VDI to the virtual machine.
  4. Clone the VDIs from the snapshot and connect them to the virtual machine.
  5. Power on the virtual machine.

I’ve been thinking about writing a couple PowerShell cmdlets for taking and reverting snapshots. If I receive enough interest, I’ll probably write them up and post them here. So if you find this post valuable feel free to leave a message. Till next time!

XenAppPrep Soon To Be Released

I’ve been getting a lot of e-mails about the release of XenAppPrep and have decided to write a blog post to let everyone know what’s going on.  Although I have received a lot of great feedback on the internal beta, I feel it’s important to have a team that’s dedicated to helping our customers with the tool.

Pete Downing, Product Manager of Provisioning Server, and I have been working together to setup a support channel for XenAppPrep before it’s released to the web (RTW). Thanks to the Provisioning Server Support Team, we were able to achieve this today.  Once the tool has been released, you will be able to dial into the Citrix technical support hotline and talk to a Citrite if you run into a problem or have any questions about XenAppPrep.

We are now in the midst of the RTW process, which includes having the tool reviewed by our security experts, and are expecting it be available on citrix.com in a week or so.  I’d like to thank everyone who has expressed interest in XenAppPrep, it will be worth the wait!  As always, I’d love to hear all feedback so feel free to drop me a message if you have any questions or comments.