Created
October 26, 2018 22:31
-
-
Save dlinsley/7da40e12eee1d73083d48545bdc7ec5e to your computer and use it in GitHub Desktop.
Get vSphere Datastore by name
This file contains hidden or 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
// VMware vRealize Orchestrator action sample | |
// Searches a vCenter or all known vCenters for a Datastore | |
// | |
// ensures the search only matches one Datastore | |
// | |
//Action Inputs: | |
// vCenter - VC:SdkConnection (Optional) | |
// datastoreName - String | |
// | |
//Return type: VC:StoragePod | |
var found; | |
if (vCenter) { | |
found = vCenter.getAllDatastores(null, "xpath:info/name[matches(.,'" + datastoreName + "')]"); | |
} else { | |
found = VcPlugin.getAllDatastores(null, "xpath:info/name[matches(.,'" + datastoreName + "')]"); | |
} | |
if (found.length > 1) { | |
throw(datastoreName+" matched more than one datastore"); | |
} | |
if (found.length == 0) { | |
throw(datastoreName+" datastore does not exist"); | |
} | |
return found[0]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment