OscarNorden
Contributor
Contributor

workflow variables in NSX REST request body

Jump to solution

hiho, i'm trying to use the REST plugin to communicate to NSX REST api and create edges and logical switches, when i've created an operation to create new edge, i use the "generate workflow from REST operation" woekflow to get a workflow where i only have to edit the body of the response with the appropiate xml string.

so far everything works and as long as i hard code every part of the body i can create edges and switches. But i dont really get how to change out parts of the body with user inputs, such as edge name or edge IP, because if i for example change out the name of the edge in the body to my "edgeName" variable, the edge will be named "edgeName" 😕

Is there any way to make a string that spans over several lines in the orchestrator version of javascript?

thanks of advice for any answers Smiley Happy

EDIT:

Apparently it works if i concatenate the xml as several strings like this: crap.PNG

and insert the variables, but this makes the content borderline unreadable, isn't there a nicer way to do this? :smileysilly:

question number two has to do with my workflow timing out before the nsx API responds that the edge is created because vcenter takes longer to deploy it than my workflow wants to wait for a response,

javascript:;

// OscarCap2ture.PNG

is there a way to make the custom condition wait longer before deciding that the action failed? Smiley Happy

0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee

Hi Oscar,

There is no 'orchestrator version of Javascript'. We use standard Javascript as implemented by Mozilla Rhino engine.

In Javascript, there is a thing called E4X, or 'ECMAScript for XML'. which provides a nicer syntax to work with XML. Here is a simple example how a XML can be constructed without string concatenation:

var edgeName = "edge1 sample name"; // or get it as input parameter

var edgeDesc = "edge1 sample description"; // or get is an input parameter

var content =

  <edge>

    <name>{edgeName}</name>

    <description>{edgeDesc}</description>

  </edge>;

System.log(content);

Makes the content structure more readable, doesn't it Smiley Happy

View solution in original post

0 Kudos
3 Replies
iiliev
VMware Employee
VMware Employee

Hi Oscar,

There is no 'orchestrator version of Javascript'. We use standard Javascript as implemented by Mozilla Rhino engine.

In Javascript, there is a thing called E4X, or 'ECMAScript for XML'. which provides a nicer syntax to work with XML. Here is a simple example how a XML can be constructed without string concatenation:

var edgeName = "edge1 sample name"; // or get it as input parameter

var edgeDesc = "edge1 sample description"; // or get is an input parameter

var content =

  <edge>

    <name>{edgeName}</name>

    <description>{edgeDesc}</description>

  </edge>;

System.log(content);

Makes the content structure more readable, doesn't it Smiley Happy

View solution in original post

0 Kudos
OscarNorden
Contributor
Contributor

That was way better than my first aproach, thanks alot Smiley Happy

0 Kudos
JamesMW
Enthusiast
Enthusiast

In response to your second question, you can change the timeout values for the RESTHost, specifically the 'operation timeout' value.

Run the workflow Library -> HTTP-REST -> Configuration -> Update a REST Host.

Select your NSX Rest host, and then specify a higher value for the operation timeout.

-James