Feature Image of custom dynamic groups

Automatically create custom dynamic groups in vROps as per vCenter Tags

Purpose:

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.

Introduction:

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:

Data gathering:

  • 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:
    • adapterKind
    • resourceKind
    • Properties (with which to match the members)
    • operator (method of checking, e.g., IS|CONTAINS| IS NOT etc.)
    • adapterKindkey
    • create_by_tag_category

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.

Required environment:

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.

Acknowledgement:

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:

Download the scripts and store them in the same folder.

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:

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.
Next run:

This will create the custom groups in vROps server. Watch the video for further explanation of the scripts and run-time information.

Conclusion:

You can use the script to dynamically create dynamic groups in vROps inline with the vCenter Serer tags .

No Comments

Leave a Comment