As we all know, VMware vCloud Director is a widely adopted IaaS platform for the service provider market. VMware vCloud Director offers a self-service web portal to manage your vApps, VMs, networks, and network functions (Edge Firewall, NAT, VPN, Load Balancer, DFW, and Rrouting). But there is also a RESTful API, and a PowerShell Module offered for the administrators and tenants. With the help of the API, some third- party vendors offer an extended web portal (for example, OnApp). In this article, I’ll show you how to use the VMware vCloud Director PowerShell Module (part of the famous VMware PowerCLI) to extend the default UI with a vCloud Director Tenant HTML Report for your most important objects. Unfortunately, there is no reporting option offered by the self-service web portal itself.
The problem with extensive HTML reports created with PowerShell is that the ConvertTo-HTML Cmdlet is not really flexible. So I was looking for alternative ways and found the PowerShell module PowerStartHTML from Timothy Dewin. This module combines PowerShell with Bootstrap, a open source toolkit for developing with HTML, CSS, and JS. With this toolkit, I was able to create a report that contains the necessary information’s in a nice-looking format.
VMware PowerCLI for vCloud Director Basics
The latest version of VMware PowerCLI is available on PowerShell Gallery. So if you use PowerShell 5.0 or newer, you can install PowerCLI modules with one simple command:
|
|
After installation is successful, you can load all VMware modules using this command:
|
|
One of the loaded modules is VMware.VimAutomation.Cloud, which is for VMware vCloud Director. But be aware that not all commands work as a tenant. Some Ccmdlets are for administrative use only and others are for vCloud Air (which was sold to OVH).
All available vCloud Director Cmdlets (and one function) on version 6.5.1:
The aliases for vCloud Air are removed from this screenshot.
To connect to your VMware vCloud Director organization, the Cmdlet Connect-CIServer works as a provider administrator and also as a tenant. Tenants simply need to add their organization during connection:
|
|
Other PowerCLI vCloud Director examples:
- PowerCLI vCloud Director Customer Provisioning
- PowerCLI – Create vCloud Director Edge Gateway
- vCloud Director Edge-Gateway IP Report
Some interesting Cmdlets
Search-Cloud
The Search-Cloud Cmdlet is the fastest way to get vCloud Director objects via PowerCLI. You can also list some objects for that since no typical Get-* command is available (for example, Edge Gateways).
Example: List Edge Gateways:
|
|
All QueryTypes can be found in the VMware vSphere 6.5 Documentation Center.
Get-CIVApp
The Get-CIVApp Cmdlet lists all vCloud Director vApps. vApps are also known from VMware vSphere but are way more important in vCloud Director. A vApp can contain objects like VMs, networks, and network functions.
Example: List vApp ‘NetApp-HA’:
|
|
Get-CIVM
The Get-CIVM Cmdlet lists all vCloud Director VMs. VMs are in vCloud Director always children from vApps and also the Cmdlet can use Get-CIVApp as piped input.
Example: List all VMs from vApp ‘NetApp-HA’:
|
|
Bootstrap with PowerShell Basics
Firs I have to say I am no HTML pro and I would not have been able to create the report without the help of this great example from Timothy Dewin. Timothy created an awesome Veeam Backup & Replication HTML Report with his PowerStartHTML PowerShell Module.
The function New-PowerStartHTML creates a new object with the necessary methods to create a full Bootstrap HTML page. The newly created object already includes the stylesheet for Bootstrap.
The two main methods to create your HTML page are:
|
|
Here’s an explanation from the README on GitHub:
The difference between Add is that it will remember the new element as the as the element. With Append, it remember the parent, so you can add an element at the same depth.
All the possible types and classes can be found in the Bootstrap documentation.
To get started with a simple HTML file, I created a report for all available modules on my PC. The main part of the report is a simple table.
|
|
This Eexample is not very complex and it maybe also be possible to create a simple table like this with the ConvertTo-HTML Cmdlet. But let’s get a little bit more complex and add the commands of each Module in a sub-section of the table.
|
|
Okay, so that table is definitely more complex than what you can create with the ConvertTo-HTML Ccmdlet!
The vCloud Director Tenant HTML Report
Now that we’re familiar with the VMware PowerCLI vCloud Director Module and the basics of Bootstrap PowerShell handling, let`s get started with the report.
The first step is to decide which data is necessary for the vCloud Director Tenant HTML Report. This is my selection:
With this set of data, we are now able to collect the object details from our VMware vCloud Director server using VMware PowerCLI.
Object details
Get Users
|
|
Get Catalogs
|
|
Get Catalog Items
|
|
Get VDCs
|
|
Get VDC Edge Gateways
|
|
Get VDC Networks
|
|
Get VDC vApps
|
|
Get VDC vApp VMs
|
|
Final vCloud Director Tenant HTML Report
I wanted to ship the vCloud Director Tenant HTML Report script as a PowerShell Module since that is the best way to also include the PowerStartHTML Module.
How to Create a Module
To create my PowerShell modules in a standardized way I use the Plaster Module with a customized template. For more details about Plaster and Plaster templates, you can read my blog article.
The ‘VMware-vCD-TenantReport’ Module
With my Plaster template and some manual modifications, I have created a Module with PowerStartHTML as a Sub-Module. The module also ships with a basic Pester test.
]
The Report Script
The script to create the vCloud Director Tenant HTML Report is embedded in the exported Get-VcdTenantReport function, The usage is quite simple:
|
|
The report will be automatically opened in your default browser.
vCloud Director Tenant HTML Report PowerShell Code
|
|
The complete Module is also available as a GitHub repository.
Get the Module
I love automation, so I created a simple script to get the latest release of the vCloud Director Tenant HTML Report Module:
|
|