During the preparations of my presentation with Hendricus Kramer on NetScaler Automation with Puppet at E2EVC in Lisbon, I used a lot of PowerShell scripts to test the interaction with NetScaler’s NITRO. Where Hendricus is the Puppet Expert, I’m having a lot of fun building PowerShell scripts to automate deployments and common administrative tasks. I’m no PowerShell expert and my code can probably be improved in many ways, it does however get the job done (and offers a great learning experience as I improve with every script I built).
At the Dutch Citrix User Group meeting I was talking with Sander Bierman and sharing my enthusiasm on automating the NetScaler configuration with NITRO and PowerShell. We both agreed that NITRO offers many possibilities to automate the NetScaler configuration, but still requires you to provide a NetScaler IP-address to connect. “Wouldn’t it be great if you could automatically deploy a NetScaler VPX with a given IP-address, to automate the NetScaler deployment on your Hypervisor as well” I asked Sander. He just smiled and told me the answer could be found in a Citrix KnowledgeBase article! And those of you that attended his session, know he also found the answer to script a NetScaler VPX deployment on vSphere with a fixed IP-address.
So let me share the PowerShell script I created to do this for XenServer!
CTX128236: How To Auto-Provision NetScaler VPX on XenServer
There is a great Citrix KnowledgeBase article on How To Auto-Provision NetScaler VPX on XenServer that offers a step-by-step guide on how to import a NetScaler VPX onto XenServer and provide it with a pre-configured NetScaler IP-address, using the CommandLine Interface (CLI) of XenServer. Even though the instructions are very clear, I needed more than just the xe commands to make it work. So I decided to translate the instructions to my new favorite scripting language: PowerShell.
The XenServer 6.5.1 SDK
To create a PowerShell script for the given instructions in the above mentioned article, I downloaded the XenServer 6.5.1 SDK that includes a PowerShell Module. So with the PowerShell Module at hand I could simply translate the instructions into the right PowerShell cmdlets and build my script.
My PowerShell script
So without further ado, here’s my PowerShell script to automatically import a NetScaler VPX in XenServer and give it a fixed NetScaler IP-address:
# based upon CTX article: http://support.citrix.com/article/CTX128236 # Import XenServer 6.5.1 SDK Import-Module "C:\PSModules\XenServerPSModule" # Configure script variables $XSServer = "192.168.10.51" # Hostname or IP-address of XenServer Poolmaster $sourcePath = ".\NSVPX-XEN-11.0-63.16_nc.xva" # location of NS VPX image on machine running PowerShell $nsIPAddress = "192.168.10.6" # fixed IP-address to configure for the NetScaler VPX $nsNetmask = "255.255.255.0" # Netmask to configure for the NetScaler VPX $nsGateway = "192.168.10.1" # Default Gateway to configure for the NetScaler VPX # Open a connection to XenServer (poolmaster) and make it the default session (required) $oXSSession = Connect-XenServer -Server $XSServer -SetDefaultSession # Import the NetScaler image to the default SR Import-XenVm -XenHost $XSServer -Path $sourcePath # Get the imported NS VPX VM uuid by it's default name $oVM = Get-XenVM -Name "NetScaler Virtual Appliance" # Change the name of the VM Set-XenVM -Uuid $oVM.uuid -NameLabel "NetScaler VPX" # Get current VM XenStoreData values $newHash = $oVM.xenstore_data # Add required values for fixed IP settings for the NetScaler VPX $newHash.add("vm-data/ip",$nsIPAddress) $newHash.add("vm-data/netmask",$nsNetmask) $newHash.add("vm-data/gateway",$nsGateway) # Add new values to current VM XenStoreData (works only once, before NS is booted) Set-XenVM -VM $oVM -XenstoreData $newHash # Start the NS Appliance Invoke-XenVM $oVM -XenAction Start # Disconnect the session Get-XenSession -Server $XSServer | Disconnect-XenServer
And here’s the recorded demo video:
With a big thanks to TechSmith for providing me with a copy of Camtasia for the recording.