Created
May 15, 2023 04:32
-
-
Save imtrinity94/8fdcfa680c6280b08842232791778d59 to your computer and use it in GitHub Desktop.
vRO Script to find if VCD pVDC is NSXT backed or NSXV?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (! System.getModule("actions.mayank.goyal").aValidInput(pVDCName)) { | |
throw "'pVDCName' input parameter either null or undefined !"; | |
} | |
// Get Local VCD URL | |
var vcdHostUrl = System.getModule("actions.mayank.goyal").getTransientRestHostFor("VCD").url; | |
// Get Auth Token for VCD | |
var authToken = System.getModule("actions.mayank.goyal").getAPIToken(); | |
// Get pVDC Details | |
var headers = '[{"key":"Accept","value":"application/*+json;version=38.0.0-alpha;multisite=global"}, {"key":"Authorization","value":"Bearer ' + authToken + '"}]'; | |
var queryString = "/api/query?type=providerVdc&format=records&page=1&pageSize=50&sortAsc=name"; | |
try { | |
var response = System.getModule("actions.mayank.goyal").invokeRestOperationMultipleHeaders("VCD", "", "", queryString, "GET", "", headers, ""); | |
if (response.statusCode == 200) { | |
var contentAsString = JSON.parse(response.contentAsString); | |
var records = contentAsString.record; | |
for (var i = 0; i < records.length; i++) { | |
var record = records[i]; | |
if (record.name === pVDCName && record.href.indexOf(vcdHostUrl) != -1) { | |
var networkProviderType = record.networkProviderType.replace("_", "-").toLocaleUpperCase(); | |
if (networkProviderType) { | |
return networkProviderType; | |
} else { | |
throw "Network Provider Type is not found in pVDC details !"; | |
} | |
} | |
} | |
throw "No record found for pVDC: " + pVDCName; | |
} else { | |
throw "Response Status Code: " + response.statusCode; | |
} | |
} catch (ex) { | |
throw "Failed to fetch pVDCs details. " + ex; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment