To use this function add it to the class library file named vCenterVAPIService.ts
GitHub Repository: https://github.com/SimonSparksUK/Orchestrator
Filename: vCenterVAPIService.ts
Function getObjectsByTag
private getObjectsByTag(objVcSdkConnection: VcSdkConnection, strTagName: string): com_vmware_vapi_std_dynamic__ID[] {
this.objLogger.info(`Start - Getting all Virtual Machines attached to Tag '${strTagName}'.`);
let arrVAPIDynamicID: com_vmware_vapi_std_dynamic__ID[] = [];
try {
let objVAPIEndpoint: VAPIEndpoint = VAPIManager.findEndpoint(`https://${objVcSdkConnection.id}/api`);
let objVAPIClient: VAPIClient = objVAPIEndpoint.client(null, null);
arrVAPIDynamicID = this.getAllObjectsByTag(objVAPIClient, strTagName)
objVAPIClient.close();
} catch (objException) {
throw objException;
} finally {
this.objLogger.info(`End - Getting all Virtual Machines attached to Tag '${strTagName}'.`);
}
return arrVAPIDynamicID;
}Function getVcVirtualMachineIDsByTag
public getVcVirtualMachineIDsByTag(objVcSdkConnection: VcSdkConnection, strTagName: string, strType: string = "VirtualMachine"): string[] {
let arrVAPIDynamicID: com_vmware_vapi_std_dynamic__ID[] = this.getObjectsByTag(objVcSdkConnection, strTagName);
arrVAPIDynamicID = arrVAPIDynamicID.filter((objVAPIDynamicID: com_vmware_vapi_std_dynamic__ID): boolean => {
return objVAPIDynamicID.type == strType;
});
let arrVcVirtualMachineID: string[] = arrVAPIDynamicID.map((objVAPIDynamicID: com_vmware_vapi_std_dynamic__ID): string => {
return objVAPIDynamicID.id;
});
return arrVcVirtualMachineID;
}Discover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
