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 a CName record from InfoBlox
Function InfobloxCNameRecordDelete
public InfobloxCNameRecordDelete(objRESTHost: RESTHost, strCName: string): void {
let objRESTRequest: RESTRequest = objRESTHost.createRequest("GET", "/wapi/v1.1/record:cname?_return_type=json&name=" + strCName, null);
objRESTRequest.setHeader("Accept", "application/json");
objRESTRequest.contentType = "application/json";
let objRESTResponse: RESTResponse = objRESTRequest.execute();
if (objRESTResponse.statusCode === 200) {
let strContent: string = objRESTResponse.contentAsString;
try {
let arrRecord: any = JSON.parse(strContent);
let objRegExp: RegExp = /(record:(cname|a|host|mx|ptr|txt))\/([A-Za-z0-9]+):([a-z0-9\-\.]+)\/default/;
this.objLogger.info("==================================================");
arrRecord.forEach((objRecord: any): void => {
let strRecordReference: string = objRecord._ref;
let strRecordCanonical: string = objRecord.canonical;
let strRecordName: string = objRecord.name;
let objRegExpExecArray: RegExpExecArray = objRegExp.exec(strRecordReference);
let strObjectType: string = objRegExpExecArray[1];
let strObjectReference: string = objRegExpExecArray[3];
let strObjectName: 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 == strCName) {
let objRESTRequest: RESTRequest = objRESTHost.createRequest("DELETE", "/wapi/v1.1/record:cname/" + strObjectReference + "?_return_type=json", null);
objRESTRequest.setHeader("Accept", "application/json");
let objRESTResponse: RESTResponse = objRESTRequest.execute();
if (objRESTResponse.statusCode == 200) {
this.objLogger.info("SUCCESSFULLY DELETED CNAME: " + strObjectName);
}
else {
this.objLogger.info("HTTP Error: " + objRESTResponse.statusCode);
}
}
});
this.objLogger.info("==================================================");
}
catch (objException) {
this.objLogger.info("JSON Error: " + objException);
}
}
else {
this.objLogger.info("HTTP Error: " + objRESTResponse.statusCode);
}
}Discover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
