Do you want to create custom dynamic groups in vROps which matches the tags created in vCenter server? You can do this manually, but you have large number of tags created. How to tackle that programmatically? This post covers the exact point. Read on to know how you can automatically create custom dynamic groups in vROps server. These groups will match the tags created in vCenter server.
Last week I got a request from my friend Sunny Dua about a script which will automatically create custom groups in vROps server as per vCenter server tags. This started me thinking. If you have a large environment and you want to keep it organized, then tags in vCenter server is a must. Also creating custom dynamic groups in vROps matching to these vCenter Tags makes sense. So I created scripts to achieve this. Provided below are details of the scripts.
The purpose of the script is two-fold.
So essentially you get custom groups in vROps server with names equal to tag names in vCenter server. The members of the group are the respective VM’s tagged with tagname.
Provided below are a list of capabilities of the script:
Custom Group Creation:
Create the custom group as per the vCenter tag name
Provided below are the limitation of the custom group creation In vROps server we can have two different custom dynamic groups with the same name, provided they are part of different “Group Type”. The script currently checks for duplicate custom group name but does not check for the Group type. So you will not be able to create two custom dynamic groups with same name in any way. To do: If a match for custom group name found then further check for the Group Type field.
I tested the scripts in the following environment.
To run the script you would need Nagini module (python client) for vROps REST API. Please check this blog for details on how you can download and use this module.
Before I start writing this blog I need to say thanks to few people.
Question is, why I wrote script which does the similar task for which Vinith Menon already had a script? Provided below are my reasons:
Note, in PowerShell way you will actually have to do the bare bone Invoke-RestMethod. Python already handles those for you. Just call the methods and you are good.
I have created a GitHub repository from where you can download the scripts. The following scripts are available:
Download the scripts and store them in the same folder.
First you need to run the Get-TagNames.ps1 script. Follow the following process to run the script. I am assuming you are running the script from VMware PowerCLI console. Note, I am dot sourcing [.] the Get-TagNames.ps1 script so that the function defined in it is available in the environment.
PS:> $server = Connect-VIserver -Server <vcenter server="" ip="" fqdn=""> PS:> . .\Get-TagNames.ps1 PS:> Export-Tag -Server $server [-Category <tag-category-name>] </tag-category-name></vcenter>
Note, the -Category option is optional. If specified, script will get the tag names from that tag category only.
Running the script will generate a “taglist.json” file which has the data (tagName and categoryName).
Next run, python scripts from command prompt:
C:\> python set-env.py
This will ask inputs for configuring the environment and will generate a “env.json” file which will have the environment information to be used later.
C:\> python create-custom-group-vrops.py
This will create the custom groups in vROps server. Watch the video for further explanation of the scripts and run-time information.
You can use the script to dynamically create dynamic groups in vROps inline with the vCenter Serer tags .