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 createTag
publiccreateTag(strTagName:string,strTagCategoryName:string):string{
letstrResult:string="";
this.objLogger.info(`Start - Creating Tag '${strTagName}'`);
letobjVCenterServer:vCenterServer=this.arrVCenterServers[0];
letstrVCenterServerName:string=objVCenterServer.Name;
letobjVAPIClient: VAPIClient;
try{
letobjVAPIEndpoint: VAPIEndpoint=VAPIManager.findEndpoint(`https://${strVCenterServerName}/api`);
objVAPIClient=objVAPIEndpoint.client(null,null);
letstrTagCategoryID:string=this.findTagCategoryIDByName(objVAPIClient,strTagCategoryName);
this.objLogger.info(`===== vCenter Server = '${strVCenterServerName}' for Tag Category Name = '${strTagCategoryName}' - Checking`);
if (strTagCategoryID){
this.objLogger.info(`===== vCenter Server = '${strVCenterServerName}' for Tag Category Name = '${strTagCategoryName}' - Found`);
strResult=this.createTagInVCenterServer(objVAPIClient,strTagCategoryID,strTagName);
while (this.isTagExistsInAllVCenterServers(strTagName,strTagCategoryName)===false){
this.objLogger.info("Sleeping 5 seconds and retrying...");
System.sleep(5*1000);
}
}
else{
this.objLogger.warn(`===== vCenter Server = '${strVCenterServerName}' for Tag Category Name = '${strTagCategoryName}' - Not Found`);
}
}catch (objException){
throwobjException;
}finally{
objVAPIClient.close();
}
this.objLogger.info(`End - Creating Tag '${strTagName}' with result :${strResult}`);
returnstrResult;
}Discover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
