Pages

Monday, October 11, 2021

Using VRO to query tags for a VRA-Cloud Assembly dropdown

We've just started building servers in our vSphere with NSX-T environment using VRA to deploy the servers. The security group placement is controlled via NSX policies that are determined by the machine's tagging. I wanted to provide a dynamic dropdown in VRA so that I did not have to recode the cloud template and subsequent service broker custom form each time a new tag value was added to vSphere. I noticed in VRA that the NSX tags were being discovered there. 

This routine runs from VRO to read the tags in VRA (/iaas/api/tags) with a specific KEY, and returns the VALUE in a sorted array.

Prerequisites:

  1. VRO server integrated with VRA-Cloud Assembly. 
  2. VRA Plug-in to VRO (reference: here) - need to download and install on your VRO server.
  3. Cloud template that needs a dropdown of tag values. 
Warning:  Without a filter, we have over 7,000 tags coming from NSX. When I tried to query all our tags, I crashed my VRO server and needed to reboot it to kill the query. 
   
Configuration:
  1. Set default VRA host 
    1. VRO - select Configurations - vRA plug-in
    2. Variables tab - click on defaultHost
    3. Click on the value field and select the VRA host you want to query.
    4. Save
  2. Create new Action
    1. VRO - select Library - Actions menu item 
    2. New Action
    3. type in a name and module name 
      1. typing in a 'new' name for the module will create a new module. 
    4. Click on the Script tab and make sure Javascript is selected for Runtime.
    5. On the right, click Add New Input button and create a new input
      1. name: tagFilter
      2. type: string
    6. Change the Return type to string and check the checkbox for Array.
    7. Paste the code below.
    8. Save.
Last step, TEST! Click the RUN option up top before closing the Action screen and enter a tagFilter value that matches a tag showing in your VRA - Configure - Tags. 

Replication:
  1. Log into your VRA instance
  2. Scroll down to Integrations and open the VRO integration
  3. Click the Start Data Collection button and wait...


Use:
  1. Log into your VRA instance
  2. Open a cloud template
  3. Browse to the Inputs menu. 
  4. Locate or create a new input. Mine:
    1. Name: ApplicationTag
    2. Display name: Application
    3. Type: string
    4. Default Value: leave blank.
  5. Scroll to the bottom of the screen and expand More Options
    1. Pairs: External Source
    2. Action: click Select and search for the name you input into 2.3 in VRO above. 
    3. Unselect BIND and type in the tag KEY value to filter on. 
    4. SAVE to save select.
    5. SAVE to close Input properties
  6. Test cloud template - The dropdown should load for a few seconds then complete. 



No comments:

Post a Comment