We often get questions from customers about the best way to automate their cloud environments. As iland provides Infrastructure-as-a-Service based on VMware vCloud Director, we expose a RESTful API that can be used to automate things at the vCD level.
We also offer a higher level REST API for the iland cloud console which exposes other services that iland has curated into the console, such as vSphere performance data, security and compliance data, disaster recovery services with Zerto, etc.
More information on the iland REST API is available here.
As well as RESTful APIs, another set of tools which leverage these APIs has proved extremely popular over the past few years.
Microsoft Powershell, and the extensions provided by VMware as PowerCLI, provide an excellent environment to automate a VMware-based cloud infrastructure such as that provided by the iland Secure Cloud platform.
Anyone who has done any development during their careers should be able to understand the syntax of PowerCLI for simple scripting or full-blown applications.
Microsoft provide an excellent integrated scripting environment (ISE) that enables a PowerCLI developer to easily discover commands, known as cmdlets, and interrogate the data that is returned from these. The IntelliSense capability helps to automatically complete commands and object names.
I don’t propose to go into great detail about how to get PowerCLI running, but suffice to say it can be downloaded from Microsoft and VMware websites. In recent news, Powershell, which traditionally only ran on Windows operating systems due to its dependence on .NET, has just been ported to both Linux and Apple Mac. PowerCLI cmdlets for Linux and Mac should be available soon. In the meantime, I use PowerCLI running on Windows 10 on my Mac inside VMware Fusion.
Powershell ISE can be made to automatically load all the PowerCLI cmdlets using the profile feature, whereby you can specify all the PowerCLI. There are several additional PowerShell functions that have been written by ecosystem members that can be included in this way, and can be downloaded from various forums and blogs on the Internet.
PowerCLI can be used for a variety of automation tasks. Generally speaking, there are a small number of main functions:
- GET – retrieve information about stuff
- SET – change attributes
- NEW – create new things (but also ADD)
- REMOVE – to delete things
- START/STOP/SUSPEND for virtual machine operations
- CONNECT/DISCONNECT to login/out of a vCloud environment
The full set of PowerCLI cmdlets can be found at: http://pubs.vmware.com/vsphere-60/index.jsp?topic=%2Fcom.vmware.powercli.cmdletref.doc%2FOverview.html
Simple GET cmdlets
A good starting point is querying the vCloud environment using GET commands. As the name suggests, this gets information without changing anything, so is safe for beginners!
Before we can do anything, we’ll need to connect to the vCloud environment, using the same URL as indicated by the iland cloud console interface when you choose to interact with vCloud Director.
The PowerCLI cmdlet Connect-CIserver is used with –server, -user, -password and –org to specify those details.
Having successfully connected, you can start running GET commands. Many of the vCloud cmdlets have ‘CI’ in front (cloud infrastructure), to differentiate them from vSphere/vCenter cmdlets. So, Get-CIVM instead of Get-VM.
In the example below, Get-OrgVdc is used to get information about our two Org Virtual Data Centres, both of which are Pay As You Go.
Then, Get-CIVapp is used to list all the vApps that are currently deployed. Finally, listing all the VMs using Get-CIVM.
You can use the format table command (ft) to format the output neatly, and specify the column headings you’d like to see.
Rather than using individual cmdlets on the command line, you can start to produce scripts that perform a similar function to the above.
In the example below, $vApps is an array that contains all the vApps and their configuration data, while $VMs is an array for all the VMs that are discovered. $vApp and $VM are then objects which contain individual data.
The IntelliSense feature within Powershell ISE allows you to see what information is stored within an object.
When the script is executed, the following output is produced. Rather than writing to the screen, it could be exported to an Excel or CSV file.
Automating the deployment of vApps
PowerCLI can be used to deploy new vApps from existing vApp templates within the vCloud catalog. This could be either from your own catalog or from the Public catalog offered by iland. The cmdlet get-civapptemplate will show you all the vApp templates available.
In this example we want to deploy the Travel App vApp template from my Test catalog, and call the new vApp ‘Travel App 1’.
This short script deploys the new vApp in a matter of minutes. By default, the vApp will be powered off.
We may want to make some changes to the VMs within the vApp once deployed. For example, I may want to give the ‘MySQL server’ 4GB of RAM – it currently has only 750MB.
Unfortunately, there isn’t a nice, easy Set-CIVM cmdlet, so we need to do some jiggery-pokery using extension data. Fortunately, a quick trundle round the Internet found the commands to use.
And, we can see that the RAM value has been increased on the ‘MySQL server’ VM.
Finally, the vApp can be started up.
Hopefully, this short article has been useful to whet the appetite for Powershell and PowerCLI.
Watch this space for more articles on this exciting topic!
For further reading, I can recommend my old VMware friend and colleague, Alan Renouf and his blog site at http://www.virtu-al.net/ – what he doesn’t know about PowerCLI isn’t worth knowing!