Top

Custom XML objects in vRealize Orchestrator

by

Matthias Eisner

By
Matthias Eisner
and

Lately I had the issue that I needed to create custom XML objects based on variables. In first place it sounds simple, but in the end, there are a couple of different methods doing this. This article will discuss these options.

The first method is a simple string, but if the object gets a bit larger, this is not very useful.

var xmlString = "
";

The advantage of this method is, that the string can be directly used within a REST call but converting an XML object into a string is not rocket science.

The second method is creating the XML object directly in the code.

var xmlObject =
;

For the sufficiency of this article, this can be done with the following line of code. Be aware, before converting an object into a string, we need to create the object.

var xmlString = xmlObject.toString();

Now that we’ve covered creating really basic XML objects and/or strings, let’s look into a more complex XML structure. For the examples I am going to use the firewall ruleset XML of the distributed firewall of NSX-v. I’ve chosen this example because firewall rules are highly dynamic and sometimes you need just a few entries and sometimes maybe 50 rules or even more.

Of course, using E4X, enables us to easy add information to the XML object, but to add information, the part of the XML object needs to exist.

Before we start adding dynamic content, we need to build a base object for the rules which is identical for each rule and of course the section XML object. That can be built more dynamic but for this example we start with some basic content. The section object was shown before, even though, more information for the section is needed, but that is part of the NSX documentation.


var rule =

      ruleName
      allow
      1000
      
      
var destination =

      ipAddress
      Ipv4Address
;
destination.value = << here goes the looping object >>;

This is an example for the destination. Objects for source and services are built the exact same way. Now that we have created the dynamic content, and imagine we did the same for source and service, we need to add these to the rule using the following method:

rule.destinations.destination += destination;
rule.sources.source += source;
rule.services.service += service;

The above code block adds the corresponding newly created XML object to the previously built XML object at the right places within the rule object. The last step is to add the newly dynamic built rule to the main object for the distributed firewall ruleset creation.

section.rule += rule;

I hope this helps giving you guys an idea how to dynamically create XML objects in JavaScript and vRealize Orchestrator.

Questions?

Questions?

Ask

Matthias

Thank you! Your message has been sent!
Oops! Something went wrong while submitting the form.