To use this function add it to the class library file named InfobloxService.ts
GitHub Repository: https://github.com/SimonSparksUK/Orchestrator
Filename: InfobloxService.ts
Description: Orchestrator Function to delete an A Record from Infoblox
Function InfobloxDeleteARecord
publicInfobloxDeleteARecord(objRESTHost:RESTHost,strARecord:string):void{
try{
letstrUrl:string="/wapi/v1.1/record:host?_return_type=json&name="+strARecord;
letobjRESTRequest:RESTRequest=objRESTHost.createRequest("GET",strUrl,null);
objRESTRequest.contentType="application/json";
objRESTRequest.setHeader("Accept","application/json");
letobjRESTResponse:RESTResponse=objRESTRequest.execute();
if (objRESTResponse.statusCode==200){
letstrContentAsString:string=objRESTResponse.contentAsString;
try{
letarrRecords:any[]=JSON.parse(strContentAsString);
letobjRegExp:RegExp=/(record:(cname|a|host|mx|ptr|txt))\/([A-Za-z0-9]+):([a-z0-9\-\.]+)\/default/;
for (letiiii=0;iiii<arrRecords.length;iiii++){
letobjRecord:any=arrRecords[iiii];
letstrRecordReference:string=objRecord._ref;
letstrRecordCanonical:string=objRecord.canonical;
letstrRecordName:string=objRecord.name;
letobjRegExpExecArray:RegExpExecArray=objRegExp.exec(strRecordReference);
letstrObjectType:string=objRegExpExecArray[1];
letstrObjectReference:string=objRegExpExecArray[3];
letstrObjectName:string=objRegExpExecArray[4];
this.objLogger.info("RECORD REFERENCE:"+strRecordReference);
this.objLogger.info("RECORD CANONICAL:"+strRecordCanonical);
this.objLogger.info("RECORD NAME:"+strRecordName);
this.objLogger.info("OBJECT TYPE:"+strObjectType);
this.objLogger.info("OBJECT REFERENCE:"+strObjectReference);
this.objLogger.info("OBJECT NAME:"+strObjectName);
if (strObjectName==strARecord){
letstrUrl:string="/wapi/v1.1/record:host/"+strObjectReference+"?_return_type=json";
letobjRESTRequest:RESTRequest=objRESTHost.createRequest("DELETE",strUrl,null);
objRESTRequest.contentType="application/json";
objRESTRequest.setHeader("Accept","application/json");
this.objLogger.info("ATTEMPTING To DELETE A RECORD:"+strObjectName);
letobjRESTResponse:RESTResponse=objRESTRequest.execute();
if (objRESTResponse.statusCode==200){
this.objLogger.info("SUCCESSFULLY DELETED A RECORD:"+strObjectName);
}
else{
this.objLogger.info("HTTP Error:"+objRESTResponse.statusCode);
}
}
}
}
catch (objException){
this.objLogger.info("JSON Error:"+objException);
}
}
else{
this.objLogger.info("HTTP Error:"+objRESTResponse.statusCode);
}
}
catch (objException){
this.objLogger.info("objException ="+objException);
}
}Discover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
