• View Communities
    • Citrix Developer Network
      The place for unfiltered straight talk on Citrix products. Blogs, code downloads, best practices, APIs, and more can all be found here.
    • Citrix Ready Community Verified
      Does it work with Citrix? Application compatibility questions are a thing of the past with the new Citrix Community Verified site.
    • Blogs
      Learn the latest from the Citrix employees who are building application delivery infrastructure technologies.
    • Blogosphere
      The Citrix Blogosphere is a window into the thousands of conversations taking place about Citrix and Application Delivery.
  •  Sign In
XenServer Developer Network

XenCenter Plugins - Hello World Example

Introduction

Here is a short example which will guide you through the creation of a XenCenter plugin.
Objective: We would like a new menu item in XenCenter which says "hello from ..." where "..." denotes the name of the object selected in the treeview.
In this example we shall achieve this by using the XenServerPSSnapIn PowerShell bindings.

Requirements

The first step is to install the following requirements:

Requirement
Download Location
.Net Framework v2.0
http://msdn.microsoft.com/en-us/netframework/aa731542.aspx
.Net Framework v2.0 SDK
http://msdn.microsoft.com/en-us/netframework/aa731542.aspx
Microsoft PowerShell v1.0 http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx
Citrix XenCenter v5.5
http://www.citrix.com/xenserver/download
Citrix XenServerPSSnapIn v5.5
http://community.citrix.com/cdn/xs/sdks
Create-PluginInstaller.ps1
Create-PluginInstaller.ps1

XCPlugin file

Now we need to create a plugin descriptor file.
We start with the XenCenterPlugin node with the following attributes:

  • xmlns - Specifies the schema of the XML file.
  • version - The XenCenter Plugins version, we are using version 1.
  • plugin_version - The version number of this plugin.
<XenCenterPlugin xmlns="http://www.citrix.com/XenCenter/Plugins/schema"
 version="1" plugin_version="1.0.0.0">

To create a menu item we add a MenuItem node under the XenCenterPlugin node. We give this three attributes:

  • name - For identfying the menu item, used to reference the label in the resources file.
  • menu - The name of the menu under which the menu item should appear. Let's use the 'View' menu.
  • serialized - Decides if copies of the plugin running simutaneously are allowed for the same object. Here we do not limit this so we set to "none".
<MenuItem name="hello-menu-item" menu="view" serialized="none">

Next we add the XenServerPowerShell tag which points to a PowerShell script to run:

  • filename - The filepath relative to the install directory of the XenCenter executable of a PowerShell script to run (or an absolute filepath).
  • window - Show the console window which runs the script. We don't want this.
<XenServerPowerShell filename="Plugins\Citrix\HelloWorld\HelloWorld.ps1" window="false" />

Close off all the tags and save as HelloWorld.xcplugin.xml. The name of this file must be the same name as the name of the plugin directory in which it resides.

Resources

The next step is to add some resources which provide strings and images for the plugin. These are stored in DLLs so that the correct language (if other cultures are provided) can be loaded at run-time.

First we need to create the resx file. This can be done using Visual Studio. Add strings for the menu-item labels, copyright statements, filepaths to icons etc. The names of the resources strings should be <name>.<property>, where <name> is the name given to the tag and <property> is one of the properties found in the specification. Here is the resources table for this plugin.

Name
Value
HelloWorld.description XenServer PowerShell plugin example.
HelloWorld.copyright © Citrix Systems Inc. 2009
HelloWorld.link http://community.citrix.com/xencenter
hello-menu-item.label Hello World!
hello-menu-item.description Displays 'Hello World' from the selected object.
hello-menu-item.icon Plugins\Citrix{nl:HelloWorld}{nl:HelloWorld}.png

 The final step is to convert this .resx into a DLL. We do this with two tools:

  1. ResGen.exe - Creates a .resources file from the resx. This can be found in the .NET framework SDK.
  2. Al.exe - Embeds the .resources file into a DLL. We specify we want to create a library, the file we wish to embed, that we need the invariant culture and the name of the DLL file. Al.exe is in the .NET framework directory. 
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\ResGen.exe HelloWorld.resx
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\al.exe /t:lib /embed:HelloWorld.resources
 /culture:0x007F /out:HelloWorld.resources.dll

Attachments: HelloWorld.resx, HelloWorld.resources.dll

PowerShell

We can put any PowerShell in the script. This example makes use of the context sensitive data which is passed to the PowerShell script. XenCenter sets up the following variables before executing the script:

  • $url - The URL of the server which owns the object selected in the tree view
  • $uuid - An authenticated session ID for the server (allows the script to log into the server)
  • $class - The type of the object selected: Server, VM etc
  • $objUuid - The UUID for the selected object.

Before any server commands can be used create a new connection with the session. We can do this in PowerShell.

Connect-XenServer -url $url -opaqueref $uuid

We can then use XenServer commands without having to provide credentials for each PowerShell statement.

Get-XenServer:VM -properties @{ uuid='$uuid' } #gets the selected VM

 Finally we can also make .NET Windows Forms to create an alert box. We have to load the correct DLL before we request the MessageBox.

[Reflection.Assembly]::loadwithpartialname('system.windows.forms')
[System.Windows.Forms.MessageBox]::show("Hello from {0}!" -f $obj.name_label, "Hello World!")

 The full PowerShell script is HelloWorld.ps1

Deployment

The best way to distribute your XenCenter plugin is to package your plugin into a single MSI (Windows Installer) file.

Using a Windows Installer allows you to make sure the plugin is being installed into the correct place (by checking the XenCenter InstallDir registry key) and it gives versioning. A newer version will automatically uninstall the old version and then install the new one.

You can use the Create-PluginInstaller.ps1 PowerShell script to do this. The following command was used to make HelloWorld.msi:

 .\Create-PluginInstaller.ps1 -out HelloWorld.msi -title "XenCenter Hello World Plugin"
 -description "Sample plugin for XenCenter" -manufacturer Citrix -upgrade_code $([System.Guid]::NewGuid().ToString())

Screenshots



 




Enter tags to add to this page:
Please wait 
Looking for a tag? Just start typing.
  1. Sep 30

    Anonymous says:

    Will there be a way to submit plugins back to citrix, for the purpose of expandi...

    Will there be a way to submit plugins back to citrix, for the purpose of expanding xencenter's capabilities? it's quite limited when it comes to going off the beaten path, and more and more often we find ourselves on the cli.

    1. Oct 16

      Ewan Mellor says:

      It would be great to have these extensions available here on the community site....

      It would be great to have these extensions available here on the community site. If you have something that you'd like to share, let me know and I'll post them here.

      If what you've done is useful generally, then sure, we'll roll the feature into XenCenter too.

Add Comment

Related Links