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.

DTG-040a.png

Run the "Define an object method" workflow

b_600_0_16777215_01_images_phocagallery_tutorials_DTG-040.png

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


b_600_0_16777215_01_images_phocagallery_tutorials_DTG-041.png

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.

b_600_0_16777215_01_images_phocagallery_tutorials_DTG-042a.png


Run define an object method

b_600_0_16777215_01_images_phocagallery_tutorials_DTG-040.png

Select the securityTag type. Click next.

b_600_0_16777215_01_images_phocagallery_tutorials_DTG-042.png

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.

DTG-043a.png

Run the "Define an object method" workflow

b_600_0_16777215_01_images_phocagallery_tutorials_DTG-040.png

Select the securityTag type. Click next.


b_600_0_16777215_01_images_phocagallery_tutorials_DTG-043.png


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.


b_600_0_16777215_01_images_phocagallery_tutorials_DTG-044.png

• 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.

b_600_0_16777215_01_images_phocagallery_tutorials_DTG-045.png

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.

b_600_0_16777215_01_images_phocagallery_tutorials_DTG-046.png

• 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


b_600_0_16777215_01_images_phocagallery_tutorials_DTG-047.png

•    Object : The security tag you created
•    Method: applyToVM

b_600_0_16777215_01_images_phocagallery_tutorials_DTG-048.png

•    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
b_600_0_16777215_01_images_phocagallery_tutorials_DTG-049.png


•    Object : The security tag you created


b_600_0_16777215_01_images_phocagallery_tutorials_DTG-050.png
•    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.

NUC Lab Kit

Below are my thoughts for a vSAN nuc lab. Since I already have cables, not including them here. I ordered (and received by Nov 30, 2016)
3 x nuc, 3 x 32GB Crucial mem, 3 x Toshiba NVMe drive, 3 x Startech USB to GB NIC, and 3 x Crucial 1TB SSD. I've also been very happy with my Cisco SG300-10 so I bought one more since my existing one only has one port available. Each of the items listed here are linked below - all were purchased using the provided links below.
single NIC (See this post for details on using the USB -> GB NIC item listed below

I stayed with the i5 for the power consumption and form factor vs. the i7 Skull Canyon ;)

 

Search

Experts Exchange