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.
Purpose of the scripts:
The purpose of the script is two-fold.
- First, it should gather the tag names and tag category names from vCenter
- Second, it would create custom dynamic groups in vROps server with matches the following criteria’s
- The name of the group is same as the tag names.
- Also the membership of the group is dynamic in nature. Those VM’s will be part of a group for which “vSphere Tag” is equal to or contains the tag name/group name
- If a “Group Type” is created in vROps server which is
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.
Capabilities and limitations:
Provided below are a list of capabilities of the script:
- Default behavior is to return all the tag names and their respective tag category names.
- You can specify if you need the tag names of a particular tag category. If you specific the category name then only the tag names belonging to that category will be returned
Custom Group Creation:
Create the custom group as per the vCenter tag name
- The VM’s with the tag names will be part of those custom groups
- If “Group Type” is pre-created in vROps server (as per the Tag Category name), then the custom groups will be part of the respective “Group Type”
- You can specify the following custom values:
- Properties (with which to match the members)
- operator (method of checking, e.g., IS|CONTAINS| IS NOT etc.)
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.
- vCenter Server 6.0 U3
- vROps server 6.6
- PowerCLI 6.5 R1
- PowerShel 5.0
- Python 2.7.x
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.
- To save time, for data gathering, I used the ExportImportTags.ps1 given here (originally created by Dimitar Barfonchovski). It is a small and simple script and I made many changes to the original script (removed the import portion and exported data in JSON format in place or original XML format). Instead of saving the entire data, I am saving a subset of it.
- My friend Vinith Menon already written a script similar to this. His original blog was further re-created by John Dias. You can find details here. Vinith written the script in PowerShell.
Why similar script for creating custom dynamic groups?
Question is, why I wrote script which does the similar task for which Vinith Menon already had a script? Provided below are my reasons:
- Vinith mainly showed how you can access vROps internal REST API’s to create custom groups. My script provides a more complete solution.
- I always stressed that when it comes to vROps REST API, python is a far more cleaner and easier way to do it.
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.
Where to get the scripts and what is included?
I have created a GitHub repository from where you can download the scripts.
The following scripts are available:
How to run the scripts?
PS:> $server = Connect-VIserver -Server <vcenter server Ip/FQDN> PS:> . .\Get-TagNames.ps1 PS:> Export-Tag -Server $server [-Category <tag category name>]
C:\> python set-env.py
C:\> python create-custom-group-vrops.py
You can use the script to dynamically create dynamic groups in vROps inline with the vCenter Serer tags .