Categories in Nutanix Prism Central are used to group entities together based on a key value pairing. They are a similar concept to Tags. Categories are used to control many different aspects of an environment. Some common uses are outlined below:
- Protection Policies
- Flow Network Segmentation policies
- Calm Workflows
- Self Service Capability
- X-Play
- Storage Policies
Many Citrix environments will use Citrix Provisioning Services or Citrix Machine Creation Services to quickly deploy thousands of virtual machines. These environments may require Categories to be applied to these virtual machines post provisioning.
Nutanix provides a way to automate the management of tags via the Prism v3 API for Prism Central, so naturally, we can automate the process at scale with PowerShell
The Script Purpose and Logic
To help automate the assignment or removal of Categories to virtual machines, we have written a PowerShell script example. The script operates with the following logic:
- Connects to the specified Prism Central (PC) instances via Nutanix Prism Central v3 APIs.
- Validates the provided Category Key:Value pair exists within Prism Central.
- Queries the API for a list of machines matching either the included name list, or a name pattern match using wildcard logic.
- Loops through each virtual machine and either assigns or removes the Category depending on the script mode (add or remove).
Operational Model
The envisaged model of operation is as follows:
- A Category is created in Nutanix Prism Central, for example Citrix_Provisioning_Type:MCS or Citrix_Provisioning_Type:PVS.
- A Citrix Administrator creates a machine Catalog via either Citrix Machine Creation Services or Citrix Provisioning Services.
- The script is executed with a mode of “Add” to apply the tag to all machines matching the name MCS* with a Category Name of Citrix_Provisioning_Type and a Value of MCS.
- The Nutanix administrator applies the appropriate services to the now Categorized virtual machines, for example, Flow Micro Segmentation policies.
The administrator repeats the process as required for any additions or removals of Categories.
The script is not limited to any form of Citrix use, it will work for any virtual machine within Prism Central, however, Citrix workloads offer a great example of where this script will help.
In a scenario where a Citrix environment contains a range of Catalogs, Delivery Groups and Tags within Studio, an administrator could easily use the Citrix PowerShell capability to query machine objects, and then pass them as an array (IncludeList) to the UpdatePCVMVategopries.ps1 script to either apply or remove Nutanix Categories.
Nutanix Automation Components Used
The script used the following API components as an example of what can be achieved via v3 APIs:
api/nutanix/v3/categories/{name}/{value}:
To validate the existence of the specified Category Key:Value pairapi/nutanix/v3/vms/list
: To retrieve a list of virtual machinesapi/nutanix/v3/vms/{uuid}
: To get and set the category against the appropriate virtual machine
Summary and Technical Requirements
To successfully execute the script, the following requirements must be met:
- An appropriate credential for the Prism Central tasks. We recommend a service account is used. For our testing of all components in the script, we used a Super Admin level account.
- PowerShell 5.1 onwards can be used, including PowerShell 7.
You can find the script below on our GitHub Repository: