Getting Up and Running with the XenApp Management SDK

I began working on my latest side project a week or so ago.  This one involves the XenApp Management SDK (aka MFCOM) with C# and WPF.  One of my goals for the project is to maintain compatibility with XenApp 4.5 and 5.0.  So I setup XenApp 4.5 on my XenServer and installed the latest and greatest version of the SDK (5.0) on my Vista development box.

I’ve used the SDK in the past, but its been a while so I was a little rusty.  I ran mfreg to point the SDK to my server.  Then without much thought I wrote some C# code to connect up to my 4.5 farm:

IMetaFrameFarm8 _farm = new MetaFrameFarm();
_farm.Initialize(MetaFrameObjectType.MetaFrameWinFarmObject);

I hit F5 to run my project in Visual Studio and got a little suprise in the form of an InvalidCastException:

Unable to cast COM object of type 'MetaFrameCOM.MetaFrameFarmClass' to interface type 'MetaFrameCOM.IMetaFrameFarm8'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{ED62F657-63C2-11D4-94D8-00C04FB0F326}' failed due to the following error: Unable to cast COM object of type 'MetaFrameCOM.MetaFrameFarmClass' to interface type 'MetaFrameCOM.IMetaFrameFarm8'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{ED62F657-63C2-11D4-94D8-00C04FB0F326}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

Version 8 of IMetaFrameFarm is the latest version of the farm interface for XenApp 5.0.  I needed to use an older version of the interface, one that 4.5 shipped with.  So I changed IMetaFrameFarm8 to IMetaFrameFarm7 and everything worked fine.  Older interfaces are compatible with future versions of XenApp, which means I’m guaranteed my code will work with XenApp 5.0.

That brings us to lesson #1: Each release of XenApp is updated with a new set of interfaces.  The interface you use must be <= to the version of XenApp you’re targeting. For example, IMetaFrameFarm7 shipped with XenApp 4.5 and can be used against XenApp 4.5 and 5.0.

Next I wrote some code to iterate through the applications in my farm and ran into the following UnauthorizedAccessException:

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

This was due to my Vista machine’s DCOM Default Impersonation Level not being set to Impersonate. It seems Identify is the default in Vista. I changed this by doing the following:

  1. Open the Component Services MMC snap-in.
  2. Right click on the My Computer node.
  3. Select Properties.
  4. Go to the Default Properties tab.
  5. Under Default Impersonation Level choose Impersonate.

That brings us to lesson #2: DCOM must be configured properly on the system running the SDK.  More information on this can be found in the documentation under Configuring MFCOM Security, which gets installed as part of the SDK.

After addressing these issues the SDK worked great and I was on my way churn out the bits of my project.

XenAppPrep Places 3rd at Rocket Science 2008

XenAppPrep was recently awarded third place at Rocket Science. Here’s a picture of the award taken from my Motorola Q:

Rocket Science Award

The event is held annually by the Citrix Application Virtualization Group (aka makers of XenApp amongst other products) where engineers can show off their latest side projects to the company. It’s like a science fair for Citrites.

I attended Rocket Science 2008 back in October and had the opportunity to demo XenAppPrep to our engineers, management team, and executives. The event was a blast, there were a lot of interesting inventions and conversations going on. I will be looking forward to Rocket Science 2009!

XenServer 5.0 SDKs Released to Web

Incase you haven’t heard, the XenServer 5.0 SDKs have been released. Here’s a short summary of them:

  • New XenServerPSSnapIn: This is the PowerShell snap-in for XenServer, which is a one-to-one mapping of the existing XenServer API. It should be noted that the functionality in XenServerSnapshotPSSnapIn can be duplicated with this, however it will take many lines of scripting. You can use both snap-ins together if you’d like to manage your XenServers and take snapshots via PowerShell.
  • Updated XenServer.NET: The XenServer SDK for .NET
  • Updated XenServerJava: The XenServer SDK for Java
  • Updated libxenserver: The XenServer SDK for C
  • Updated XenAPI.py: The XenServer Python module

The SDKs can be downloaded from Citrix Community. Enjoy!

Citrix Summit 2008 Pics

A couple of weeks ago I was at Citrix Summit 2008, which is a trade show that partners can attend to learn about our latest technologies. This year it was in Orlando, FL at the Walt Disney World Dolphin and Swan Resort.

One of the most popular events at Summit (and Synergy) is Tech Lab. This is where you can walkaround and see demos of the latest stuff from Citrix (such as Project Apollo) and third-party vendors. Here is the Citrix Tech Lab team:

Citrix Summit 2008 Tech Lab Team

More pictures of Summit can be found here.

Cloning a XenApp server with EdgeSight

I’ve received some feedback on using XenAppPrep with EdgeSight and I thought it would be beneficial to share some information on this topic.

The current version of XenAppPrep was designed to address the cloning process for XenApp core. This does not include any of the XenApp Platinum components, however we are planning to enhance the tool to cover all of them. In the meantime, you can use the following steps to clone a XenApp server with EdgeSight:

  1. Install XenApp.
  2. Install EdgeSight by running msiexec /i EdgeSightEPAgent.msi SERVICE_START_MANUAL=”1″. This will install the EdgeSight service in Manual start-up mode. Do not start this service before an image is taken.
  3. Install and run XenAppPrep.
  4. Set the Citrix System Monitoring Agent (RSCorSvc) service to Automatic start-up.
  5. Take an image of the server or if you’re using Provisioning Server switch the workload to standard image mode.

It’s important to ensure the Citrix System Monitoring Agent (RSCorSvc) service has never been started before an image is taken. If it has, the following steps must be taken before imaging the server:

  1. Stop the Citrix System Monitoring Agent (RSCorSvc) service.
  2. Uninstall the EdgeSight Agent.
  3. Ensure HKLM\SOFTWARE\Citrix\System Monitoring key has been removed.
  4. Verify the EdgeSight Agent database has been removed. It’s default location is C:\Documents and Settings\All User\Application Data\Citrix\System Monitoring\Data\rsdatr.fdb.
  5. Reinstall the EdgeSight Agent with the instructions above.

Joining the XenApp MX team

Since March 2006 I’ve been working on the XenApp Automation team, leading and technically contributing to many automated test suites. Prior to this I worked at a defense contractor for a few years in both IT and software engineering capacities. The Automation team has been focused on enabling Citrix to release new high quality versions of XenApp more often by automating tests. During this time, I learned a lot about XenApp and the software release processes at Citrix. I’ve also learned that I’d like to have a more direct impact on customers and get more involved technically.

So a little over a month ago I joined the XenApp Management Experience (MX) team. We develop the infrastructure and tools, such as the Access Management Console (AMC), that allow IT departments to easily manage their farms. The team has a lot of experience, technical involvement, and interesting challenges to solve. Initially I will be ramping the team up with their automation processes, infrastructure, and tests. But after this I’m expected to develop some the new management features that will be in the next version of XenApp.

There’s a long road ahead of us. We have a lot of work to get done for XenApp vNext and there’s a lot of room for innovation and new ideas. Best of all, there’s a lot of energy on the team to only do the best. With that said, I’m excited about the projects I’ll be working on and customers we’ll be helping! If you have any ideas that would improve the XenApp management experience, I’d love to hear about them.

Hot Off the Compiler: PowerShell SnapIn for XenServer Snapshots

As a follow-up to my Snapshotting with the XenServer 5.0 SDK post, I’ve written a PowerShell snapin that will allow you to take and revert snapshots with XenServer. You can download the source code and binaries here. You must have the .NET Framework 3.5 installed before you can use it. To install the snapin you will need to run the following command after you’ve downloaded and extracted the ZIP file:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe /i XenServerSnapshotPSSnapIn.dll

Then you can open up your PowerShell console and enter the following to take a snapshot of your virtual machine named Bluemoon, which by the way is my favorite beer!

Add-PSSnapin XenServerSnapshot*
Checkpoint-VM -Hostname 192.168.0.2 -Username root -Password qwerty -VM Bluemoon -Snapshot BluemoonBackup

If you decide you’d like to revert to this snapshot you can do this:

Restore-VM -Hostname 192.168.0.2 -Username root -Password qwerty -VM Bluemoon -Snapshot BluemoonBackup

And before I leave the office for the night, here are a few things to note:

  • The cmdlets return true if they were able to execute successfully, otherwise they return false.
  • Virtual machine names are case-sensitive.
  • PowerShell must be installed to compile the source. XenAPI.net is included with the download.
  • I’ve made a few tweaks to this code from the original version.

Added 09-March-2009: The snapshot feature in XenServer requires a VHD-on-EXT3 storage repository.  To change the default repository to EXT3, please see http://support.citrix.com/article/ctx116324.  Alternatively, the following script can be used:

dev=`cat /etc/xensource-inventory | grep DEFAULT_SR_PHYSDEVS | cut -d ‘=’ -f2 | grep -o -E “[^'].*[^']“`

sr_uuid=`xe sr-list type=lvm | grep uuid | cut -d ‘:’ -f2 | cut -c 2-`

pbd_uuid=`xe pbd-list sr-uuid=$sr_uuid | grep -E ‘^uuid.*’ | cut -d ‘:’ -f2 | cut -c 2-`

inst_uuid=`cat /etc/xensource-inventory | grep INSTALLATION_UUID | cut -d ‘=’ -f2 | grep -o -E “[^'].*[^']“`

xe pbd-unplug uuid=$pbd_uuid

xe sr-destroy uuid=$sr_uuid

new_sr_uuid=`xe sr-create content-type=”local SR” host-uuid=$inst_uuid type=ext device-config-device=$dev shared=false name-label=”Local File SR”`

pool_id=`xe pool-list | grep uuid | cut -d ‘:’ -f2 | cut -c 2-`

xe pool-param-set default-SR=$new_sr_uuid uuid=$pool_id

xe pool-param-set suspend-image-SR=$new_sr_uuid uuid=$pool_id

#echo $dev
#echo $sr_uuid
#echo $pbd_uuid
#echo $inst_uuid
#echo $new_sr_uuid
#echo $pool_id

Feel free to post a comment here if you have any feedback. Enjoy!

XenAppPrep is here!

I’m at Summit this week working in Tech Lab. This is the second Summit I’ve been to in the past two and a half years and as always its been a fun experience. This year its in Orlando, FL at the Dolphin Resort in Disney. If you’re here, I’d highly recommend stopping by our booth to check out our latest and greatest technologies and chat with some of the engineers that brought them to life.

I’m also proud to announce the release of XenAppPrep at http://support.citrix.com/article/CTX116063. I’d love to hear any and all feedback, so feel free to post your comments here.

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.

Follow

Get every new post delivered to your Inbox.