Create a plug-in for a REST based web service in minutes - Part 3

Part 1 of the plug-in generator v2 series covered how to create new plug-in inventory types, part 2 how to create their child object types. This part will focus on how to define object methods and associated workflows. Having Orchestrator inventory types is a necessity to use with vRealize Automation (formerly vCAC) Advanced Service Designer. Once you have these inventory objects you may wonder how to use these in workflows. This is what this article covers.

If you have been going through the NSX implementation of these series the prerequisite for this part is to have created a securityTag object (see the table at the end of the article to see the specific inputs to create a securityTag).

Let’s say you need to create, delete security tags and apply them to VM.

Defining the object methods

In the same way the plug-in generator has a wizard based workflow to bind new types to HTTP URLs it has a workflow to associate object methods to HTTP URLs & content.

Define a Create Security Tag method

Looking at the NSX API guide creating a security tag is defined this way.

Run the “Define an object method” workflow

Select the securityTag type (under Dynamic Types / Type Hierarchy / NSXHost / securityTagFolder). Click next.

Fill the parameters as below:

  • Method type : create
  • Template URL : /api/2.0/services/securitytags/tag
  • HTTP method : POST
  • Content template: <securityTag> <name>‹name›</name> <description>‹description›</description> </securityTag>
  • Content Type : application/xml

The content template contains either XML or JSON and uses specific small brackets (‹› different from regular <> and different from the curly brackets used for URL parameters {} ) Here it was shrunk to only specify name and description holding the 2 parameters (objectTypeName, type tags are not mandatory)

Define a custom Security Tag method

Looking at the NSX API guide apply a security tag to VM is defined this way.

Run define an object method

Select the securityTag type. Click next.

Fill the parameters as below:

  • Method type : other
  • Method name: applyToVM
  • Template URL : /api/2.0/services/securitytags/tag/{securityTag}/vm/{vmMoid}
  • HTTP method : PUT
  • Content template:
  • Content Type : application/xml

The template URL contains 2 parameters in curly brackets : the securityTag the apply VM will apply to and the VM Managed object ID (vm.id for a VCenter:ViertualMachine object type)

Define a Delete Security Tag method

Looking at the NSX API guide deleting a security tag is defined this way.

Run the “Define an object method” workflow

Select the securityTag type. Click next.

Fill the parameters as below:

  • Method type : delete
  • Template URL : /api/2.0/services/securitytags/tag/{securityTag}
  • HTTP method : DELETE

The template URL has a single parameter : the securityTag the delete will apply to

Invoking the methods

Now that the operations have been defined we can invoke them. For this there is a distinct workflow to call create, delete or other object methods. The invoke workflows will need to be duplicated so the inputs can be changed for a given type.

  • Create a workflow folder (“NSX Dynamic Types”).
  • Create a Security Tag folder in this folder
  • Duplicate Invoke a create object method in this folder. Edit it to change the parentObject parameter type to DynamicTypes:NSX.NSXHost
  • Duplicate Invoke an object method in this folder. Edit it to change the object parameter type to DynamicTypes:NSX.securityTag
  • Duplicate Invoke a delete object method in this folder. Edit it to change the object parameter type to DynamicTypes:NSX.securityTag

Invoke the create securityTag method

Now that we have set the parent object type to NSXHost (securityTagFolder would have also worked) we can run the duplicated workflow.

  • Object type: securityTag
  • Parent object: NSX

The URL field is just informal. It is loaded from the definition we made earlier and does not need to be changed. The parent object field is used to know where to create the object.

Click next.

The content is displayed is populated from the definition we made earlier. It does not need to be changed but could be if for example the content had to be very different from one invocation to another and / or set by a workflow calling this workflow.

Click next.

  • name : your tag name
  • description : your tag description

These inputs are generated based on the parameters you defined between the small brackets. There can be up to nine parameters.

Submit : Check the inventory for the new tag.

Invoke the applyToVm securityTag method

  • In your inventory click a vCenter VM you want to apply the security rule to. Make a note of its ID property on the right panel (vm-xx)
  • Run the Invoke an object method workflow you duplicated
  • Object : The security tag you created
  • Method: applyToVM
  • securityTag: will be automatically set with your object id
  • vmMoId: enter a valid VM managed object id you noted earlier

Click next

  • Content : keep empty

Submit.

Invoke the delete securityTag method

  • Run the delete workflow you duplicated in a previous step
  • Object : The security tag you created
  • securityTag: will be automatically set with your object id

Submit and check the inventory.

You can now define as many methods you need for your objects.