Ravello PowerShell Module – Examples

This post introduces the first set of example PowerShell scripts that use the Ravello PowerShell module to automate your Ravello Systems environment.

rav-title-examples

The examples serve primarily to demonstrate the use of the Ravello module cmdlets. But also how easy it is to automate your Ravello environment with the help of the Ravello PowerShell module. Note that the examples directory is introduced in v1.1.2.4 of the Ravello PowerShell module.

Ravello-Framework

This script is in fact a framework that you can use to start your scripts that use the Ravello PowerShell module. The script uses the region directive to clearly show the three parts. The “Start” region handles connecting to your Ravello environment. The region “Your Ravello Automation Script” should be self-explanatory. The third region, named “Stop”, is where you disconnect from your Ravello environment.

Annotation

Line 10,17: I use this logic that allows me to use the same script to connect to my Ravello environment from multiple locations. In this example that would be work and home. My work connection requires different credentials, which the script fetches from a CSV file.

Line 14: Note that the Connect-Ravello cmdlet supports running from behind a proxy.

Ravello-Import-vSphere-VM

This example shows how to upload a VM from your vSphere environment into your Ravello Image library. Once in the Image library, you can then use the VM in any of your Ravello Applications.

Prepare your VM(s) locally, upload them to the Ravello cloud and then give access through for example Ephemeral Tokens (see an example in Ravello PowerShell module v1.1) to specific users.

Annotation

Line 9: provide the DisplayName of the VM that you want to import

Line 12-15: provide credentials to connect to the ESXi node hosting the VM you want to import into the Ravello Image library

Line 21-28: This will load the core PowerCLI cmdlets, which we will need to connect and retrieve the target VM.

Line 40: The target VM needs to be powered off, due to consistency reasons.

Line 45-49: We remove any Images with the same name that might already be there. Note that Ravello allows having Images with identical names in the library.

Line 52-58: For the Import-Ravello cmdlet I’m using splatting to have a cleaner and more readable script. Note that such an import might take some time, depending on the speed of your Internet connection and the size of the VM.

Line 64-68: In a loop we check the Status of the Image. That way we can determine when the upload is completed.

Test-VNC-RDP

This script will check for a number of VMs in an Application if the RDP and VNC connectivity is ready.

Annotation

Line 7-11: The script requires an Application name and one or more VM names inside that Application for which you want to test the VNC and RDP connectivity readiness. Optionally you can provide a DateTime when the testing should stop. The default is that the tests will run for 5 minutes.

Line 14-20: This helper function uses the Invoke-WebRequest cmdlet to verify if the VNC connectivity is there.

Line 31-56: Another helper function that verifies if the RDP connectivity is available. This testing is a bit more complex, since we first have to verify if the DNS entry for the RDP connection is already there. Once that DNS entry is there, the function tests if a socket to port 3389 can be opened.

Line 68-79: The results of the tests are entered into an [ordered] custom object.

Line 84-85: The result is displayed on screen, but also saved to an array, named $report, which you can eventually save to a file.

The result looks something like this (this comes from running the script against 2 VMs in one my Applications).

vnc-rdp-test

Check-Maintenance

This is a script that I used recently to verify if any of my applications was impacted by a maintenance intervention that Ravello had announced.

In the announcement, the impacted systems were described like this

maint

I didn’t want to browse through all my applications and their VMs to verify if this had any impact on me. That’s why I quickly threw together the following script.

Annotation

Line 2-6: The 1st set of definitions, packaged in an inline CSV file

Line 9-19: Run through all the Applications, and for each deployed VM, check if it has a Public IP and is hosted in any of the affected clouds/regions.

Line 22: The Elastic IPs from the affected region as an array

Line 24: Get all the Elastic IPs in the Organisation, and check if they are in the affected region.

This concludes my first set of examples that I included with the Ravello PowerShell module, starting from build v1.1.24.

ravello-v1.1.2.4

If you have suggestions for other example scripts, or even better, if you want to contribute your own example script(s), feel free to create a Pull Request on GitHub.

Enjoy!

One Comment

    Julius Kovac

    +1

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

1 × four =

This site uses Akismet to reduce spam. Learn how your comment data is processed.