From 6d81f69b9a25969ae0169f8c382b4c9ef6fc503e Mon Sep 17 00:00:00 2001 From: John Bowdre <61015723+jbowdre@users.noreply.github.com> Date: Tue, 14 Jun 2022 09:00:21 -0500 Subject: [PATCH] Create vraGetNetworksSorted.js --- .../vraGetNetworksSorted.js | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Orchestrator/Actions/com.virtuallypotato.inputs/vraGetNetworksSorted.js diff --git a/Orchestrator/Actions/com.virtuallypotato.inputs/vraGetNetworksSorted.js b/Orchestrator/Actions/com.virtuallypotato.inputs/vraGetNetworksSorted.js new file mode 100644 index 0000000..b8f21ff --- /dev/null +++ b/Orchestrator/Actions/com.virtuallypotato.inputs/vraGetNetworksSorted.js @@ -0,0 +1,52 @@ +/* JavaScript: vraGetNetworksSorted action + Retrieves a (sorted) list of network names and corresponding constraint tags available for deployment in a given zone. + Inputs: zoneName (string) + Return type: Properties +*/ +if (!(zoneName == "" || zoneName == null)) { + var regionUri = null; + var token = System.getModule("com.virtuallypotato.utility").vraLogin(); + var zones = JSON.parse(System.getModule("com.virtuallypotato.utility").vraExecute(token, "GET", "/iaas/api/zones", null)).content; + System.debug("Zones: " + JSON.stringify(zones)); + for each (zone in zones) { + if (zone.name === zoneName) { + System.debug("Matching zone: " + zone.name); + regionUri = zone._links.region.href; + } + if (regionUri != null) { break; }; + } + System.debug("Matching region URI: " + regionUri); + + var networkProfiles = JSON.parse(System.getModule("com.virtuallypotato.utility").vraExecute(token, "GET", "/iaas/api/network-profiles", null)).content; + System.debug("Network profiles: " + JSON.stringify(networkProfiles)); + networks = new Array(); + networkProfiles.forEach( + function (networkProfile) { + if (networkProfile._links.region.href === regionUri) { + for each (uri in networkProfile._links["fabric-networks"].hrefs) { + var networkProps = JSON.parse(System.getModule("com.virtuallypotato.utility").vraExecute(token, "GET", uri, null)); + System.debug(JSON.stringify(networkProps)); + var networkTag = null; + for each (tag in networkProps.tags) { + if (tag.key === "network") { + networkTag = "network:" + tag.value; + } + if (networkTag != null) { break; }; + } + networks.push(new Properties({value: networkTag, label: networkProps.name})); + } + } + } + ); + + networks.sort( + function (a, b) { + return a.label > b.label ? 1 : (a.label < b.label ? -1 : 0); + } + ); + + System.getModule("com.virtuallypotato.utility").vraLogout(token); + return networks; +} else { + return [""]; +}