Automating the iland Cloud with Microsoft Powershell – Part Two, Automatic Shutdown and Startup

ByOctober 11, 2016
GearsIn Part One of this series, we looked at using Powershell to report on aspects of the iland cloud, and to create new vApps and VMs using simple GET-, NEW- and SET- commands.

One of the great things about cloud computing environments is the ability to shutdown workloads when they are not needed, and therefore not pay for the resources (except storage).  Dev/Test is an excellent example of this, where whole development environments can be shutdown at night or at weekends, and then started up again just in time for the developers to use them.

This blog post will look at the concept of storing metadata against the vApps that details when they should be started up and then shut down again. This metadata can then be read by a Powershell script that is run every hour from a management server.

In VMware vCloud Director, metadata key/value pairs can be stored against most objects within the environment – for example, virtual data centers, vApps and VMs.

There are several ways that these tasks could be performed, but the metadata I have created as shown below seems to work quite well:

  • Day of the week (Every, or MonTueWed, SatSun, etc)
  • Start Time in 24 hour clock format (07, 09)
  • Stop Time in 24 hour clock format (19, 22)
  • AutoOnOff (Yes,No)
Metadata can be stored against objects in vCloud Director either by using the iland ECS console or the native vCloud Director web interface, or as we’ll see later, via Powershell. In the iland ECS Console, the metadata can be viewed or edited as shown here:Cloud Console 1 Having clicked on Metadata, the following dialog will be shown, and you see the key/value pairs already created against the Pet Clinic vApp. Cloud Console 2 The same process works using the vCloud Director native web interface vcd_meta_1 Clicking on ‘Properties’ pulls up the key/values pairs for the vApp.vcd_meta_2 The ‘AutoOnOff’ key on its own can be used for a really simple script that checks for the existence of the key and the value being set to ‘Yes’, and will then shut it down. In the code snippet above, you can see the Get-CIMetaData cmdlet in use. This is a custom-developed cmdlet that I was able to find out on the interwebs.  This can be referenced as part of your Powershell profile, or just included at the top of your script. The all-singing, all-dancing version of the script can take the following form. If you had a large number of vApps that you wanted to add metadata to then Powershell can also be used to set that, using input from an Excel spreadsheet in CSV format.

Create a spreadsheet in Excel similar to the one below. ExcelSave it in comma delimited format.

The following script can then be used to update the metadata on the named vApps. Firstly we’ll need to define a cmdlet to create the metadata called New-CIMetaData Main body of the script. Similarly, this short script will enable you to dump out all your metadata into a CSV. This assumes you are already connected to the cloud. Watch this space for more interesting ways to use Powershell to automate the iland cloud.
Richard Stinton

Richard Stinton

Richard is an Enterprise Solutions Architect for the iland EMEA business and has over 30 years’ experience in the IT industry, most recently in the Cloud space with iland, Microsoft Azure and VMware. Starting out in Engineering CAD/CAM and GIS systems with McDonnell Douglas and EDS, he moved to mainstream IT and Systems/Service Management with HP, BMC Software and Mercury Interactive, before joining VMware in its early days. Richard has a breadth of experience having worked in customer support, sales, partner management and product marketing. In his current role as EMEA solutions architect, Richard works with customers to implement and optimise cloud technologies.