UCSD - BLUECAT Get Next IP Integration Example

Version 2
    Task NameBlue Cat IP Request
    Description
    Prerequisites
    1. Tested on 5.3.1
    CategoryWorkflow
    ComponentsvSphere 5.x
    User Inputs

    Instructions for Regular Workflow Use:

    1. Download the attached .ZIP file below to your computer. *Remember the location of the saved file on your computer.
    2. Unzip the file on your computer. Should end up with a .WFD file.
    3. Log in to UCS Director as a user that has "system-admin" privileges.
    4. Navigate to "Policies-->Orchestration" and click on "Import".
    5. Click "Browse" and navigate to the location on your computer where the .WFD file resides. Choose the .WFD file and click "Open".
    6. Click "Upload" and then "OK" once the file upload is completed. Then click "Next".
    7. Click the "Select" button next to "Import Workflows". Click the "Check All" button to check all checkboxes and then the "Select" button.
    8. Click "Submit".
    9. A new folder should appear in "Policies-->Orchestration" that contains the imported workflow. You will now need to update the included tasks with information about the specific environment.

     

    Many thanks go out to Kevin Chua

     

     

    The Custom Task at Import:

     

    Screen Shot 2015-09-16 at 4.16.41 PM.png

     

    The Custom Task:

     

    Screen Shot 2015-09-16 at 4.17.17 PM.png

     

    The Custom Input Variables:

     

    Screen Shot 2015-09-16 at 4.17.32 PM.png

     

    The Custom Output Variables:

     

    Screen Shot 2015-09-16 at 4.17.40 PM.png

     

    The before Marshal:

     

    (generating the LoV for the Credential Policy that must be chosen during the task configuration in the workflow.)

    Screen Shot 2015-09-16 at 4.18.37 PM.png

     

     

     

    The Code in the Custom Task:

     

    importPackage(java.util);

    importPackage(java.lang);

    importPackage(java.io);

    importPackage(org.w3c.dom);

    importPackage(com.cloupia.lib.util);

    importPackage(com.cloupia.model.cIM);

    importPackage(com.cloupia.service.cIM.inframgr);

    importPackage(com.cloupia.sysmgr.upgrade.util);

    importPackage(com.cloupia.fw.objstore);

    importPackage(com.cloupia.lib.util.easytrust);

    importPackage(org.apache.commons.httpclient);

    importPackage(org.apache.commons.httpclient.cookie);

    importPackage(org.apache.commons.httpclient.methods);

    importPackage(org.apache.commons.httpclient.auth);

    importPackage(org.apache.commons.httpclient.protocol);

    importClass(org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory);

    importPackage(com.cloupia.lib.connector.account);

    importPackage(com.cloupia.lib.connector.account.credential);

     

     

     

     

    //----------------------------------------------------------------------------------------

    //

    //             Author: Kevin Chua (kevchua@cisco.com)

    //

    // Workflow Task Name: Bluecat Get IP and Hostname

    //

    //            Version: 1.0

    //

    //      Description: Script performs Authentication to Bluecat Address Manager (BAM) API

    //                     where the authentication cookie is stored for subsequent BAM API

    //                     calls to find the next available IP4 Address and Hostname

    //

    //           Bluecat: Bluecat Address Manager v4.1.0

    //

    //             Inputs: bluecatUser ;BAM API username

    //                        bluecatPassword ;BAM API password

    //                        BluecatIP                ;BAM API FQDN

    //                        BluecatTransport  ;http or https

    //                        GenCoNetwork                 ;P or N

    //                        GenCoHostOSType            ;L or W

    //                        entityId                          ;Admin Input Value -> entityId of a BAM Object

    //                        dnsViewOID                    ;Require Object ID of the DNS View

    //                        prodTagName                  ;Tag name for Production

    //                        prodTagNameEntityID       ;Tag name Object ID

    //                        nonprodTagName             ;Tag name for Non-Production

    //                        nonprodTagNameEntityID  ;Tag name Object ID

    //

    //            Outputs: CIDR ;Returns IP4 Network range

    //                     nextIP4Address ;Returns Next Available IP4 Address in IP4 Network

    //                     gateway ;Returns Gateway IP4 Address

    //                     netmask ;Returns netmask

    //                     nextHostname ;Returns Next Available Hostname

    //                     nextFQDN ;Returns Fully Qualified Next Available Hostname

    //                     nextHostNumber             ;Returns Number in the Next Available Hostname

    //

    //----------------------------------------------------------------------------------------

     

     

     

     

    //----------------------------------------------------------------------------------------

    //                                 ### FUNCTIONS ###

    //----------------------------------------------------------------------------------------

     

     

    //Get the Credentials from the Credentials policy.

    function getAccount(accountName) {

      logger.addInfo("Looking for the following account: " + accountName);

      var account = PersistenceUtil.getCredentialPolicyByName(accountName);

      if (account != null) {

      logger.addInfo("Account: " + accountName + " found.");

      return account;

      } else {

      logger.addError("Account: " + accountName + " NOT found.");

      ctxt.setFailed("No Account found with name: " + accountName);

      }

    }

     

     

     

     

    //----------------------------------------------------------------------------------------

    //

    //    Created By: Russ Whitear (rwhitear@cisco.com)

    //    Updated By: Kevin Chua (kevchua@cisco.com)

    //

    // Function Name: httpRequest()

    //

    //       Version: 1.2

    //

    //   Description: HTTP Request function - httpRequest.

    //

    //                The httpClient functionality more object like in order to

    //                make cloupia scripts more readable when making many/multiple HTTP/HTTPS

    //                requests within a single script.

    //

    //  Modification: Additional Content-Type for XML added (i.e., text/xml)

    //                Execute method customized with additional logic based on the Bluecat API

    //                name. This is required since the Login event will receive a Cookie that

    //                must be added into the HTTP header during subsequent Bluecat API calls

    //

    //      Usage: 1. var request = new httpRequest();                   // Create new object.

    //              

    //             2. request.setup("192.168.10.10","https","admin","cisco123");      // SSL.

    //          or:   request.setup("192.168.10.10","http","admin","cisco123");       // HTTP.

    //          or:   request.setup("192.168.10.10","https");           // SSL, no basicAuth.

    //          or:   request.setup("192.168.10.10","http");            // HTTP, no basicAuth.

    //

    //             3. request.getRequest("/");                    // HTTP GET (URI).

    //          or:   request.postRequest("/","some body text");  // HTTP POST (URI,BodyText).

    //          or:   request.deleteRequest("/");                 // HTTP DELETE (URI).

    //

    //  (optional) 4. request.contentType("json");            // Add Content-Type HTTP header.

    //          or:   request.contentType("xmla");            // application/xml

    //          or:   request.contentType("xmlt");            // text/xml

    //

    //  (optional) 5. request.addHeader("X-Cloupia-Request-Key","1234567890");  // Any Header.

    //

    //             6. var statusCode = request.execute(apiName);                // Send request.

    //

    //             7. var response = request.getResponse("asString");   // Response as string.

    //          or:   var response = request.getResponse("asStream");   // Response as stream.

    //

    //             8. request.disconnect();                             // Release connection.

    //

    //----------------------------------------------------------------------------------------

     

     

    var httpRequest = function () {};

     

     

    httpRequest.prototype.setup = function(serverIp, transport, username, password) {

      this.serverIp = serverIp;

      this.transport = transport;

      this.username = username;

      this.password = password;

      

      this.httpClient = new HttpClient();

      

      // Decide whether to create an HTTP or HTTPS connection based up 'transport'.

      if( this.transport == "https" ) { 

      this.factory = new SecureProtocolSocketFactory() {

      createSocket : function(socket, host, port, autoClose) {

      this.fact = new com.cloupia.lib.util.easytrust.EasySSLProtocolSocketFactory();

      this.sock = this.fact.createSocket(socket, host, port, autoClose);

      this.sock.setEnabledCipherSuites([

      "SSL_RSA_WITH_RC4_128_MD5",

      "SSL_RSA_WITH_RC4_128_SHA",

      "TLS_RSA_WITH_AES_128_CBC_SHA",

      "TLS_DHE_RSA_WITH_AES_128_CBC_SHA",

      "TLS_DHE_DSS_WITH_AES_128_CBC_SHA",

      "SSL_RSA_WITH_3DES_EDE_CBC_SHA",

      "SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",

      "SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA",

      "SSL_RSA_WITH_DES_CBC_SHA",

      "SSL_DHE_RSA_WITH_DES_CBC_SHA",

      "SSL_DHE_DSS_WITH_DES_CBC_SHA",

      "SSL_RSA_EXPORT_WITH_RC4_40_MD5",

      "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",

      "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",

      "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"]);

      return this.sock;

      }

      };

     

     

      this.easyhttps = new Protocol(

      "https",

      this.factory,

      443);

      this.httpClient.getHostConfiguration().setHost(this.serverIp,443,this.easyhttps);

      } else {

      // Create new HTTP connection.

      this.httpClient.getHostConfiguration().setHost(this.serverIp, 80, "http");     

      }

      this.httpClient.getParams().setCookiePolicy("default");

      

      // If username and password supplied, then use basicAuth.

      if( this.username && this.password ) {

      this.httpClient.getParams().setAuthenticationPreemptive(true);

      this.defaultcreds = new UsernamePasswordCredentials(this.username, this.password);

      this.httpClient.getState().setCredentials(new AuthScope(this.serverIp, -1, null), this.defaultcreds);

      }

    };

     

     

     

     

    httpRequest.prototype.contentType = function(contentType) {

      this.contentType = contentType;

      

      // Added Content-Type = text/xml for Bluecat SOAP API

      this.contentTypes = [

      ["xmlt","text/xml"],

      ["xmla","application/xml"],

      ["json","application/json"]

      ];

      

      for( this.i=0; this.i<this.contentTypes.length; this.i++)

      if(this.contentTypes[this.i][0] == this.contentType)

      this.httpMethod.addRequestHeader("Content-Type", this.contentTypes[this.i][1]);

    };

     

     

     

     

    httpRequest.prototype.addHeader = function(headerName,headerValue) {

      this.headerName = String(headerName);

      this.headerValue = String(headerValue);

      

      this.httpMethod.addRequestHeader(this.headerName, this.headerValue);

    };

     

     

     

     

    httpRequest.prototype.execute = function(apiName) {  

      //Pass in Bluecat API Name to handle first time processing on gathering the Cookie Info

      this.apiName = apiName;

     

     

      // Connection:close is hard coded here in order to ensure that the TCP connection

      // gets torn down immediately after the request. Comment this line out if you wish to

      // experiment with HTTP persistence.

      this.httpMethod.addRequestHeader("Connection", "keep-alive");

      

      this.httpClient.executeMethod(this.httpMethod);

     

     

      if (this.apiName == "login") {

      // Need to capture the Cookie (JSSESSIONID) generated with the Bluecat Login API

      var cookies = this.httpClient.getState().getCookies();

      var cookie = String(cookies[0]);

      //logger.addInfo("Value: "+cookie);

      //logger.addInfo("typeof: " +typeof cookie);

     

      var cookievalue = cookie.substring(parseInt(cookie.indexOf("="))+1);

      //logger.addInfo(cookievalue);

      }

      

      // Retrieve status code.

      this.statusCode = this.httpMethod.getStatusCode();

      

      if (this.apiName == "login") {

      return [this.statusCode, cookievalue];

      } else {

      return this.statusCode;

      }

    };

     

     

     

     

    httpRequest.prototype.getRequest = function(uri) {

      this.uri = uri;

     

     

      // Get request.

      this.httpMethod = new GetMethod(this.uri);

    };

     

     

     

     

    httpRequest.prototype.postRequest = function(uri,bodytext) {

      this.uri = uri;

      this.bodytext = bodytext;

      

      // POST Request.

      this.httpMethod = new PostMethod(this.uri);

      this.httpMethod.setRequestEntity(new StringRequestEntity(this.bodytext));

    };

     

     

     

     

    httpRequest.prototype.getResponse = function(asType) {

      this.asType = asType;

     

     

      if( this.asType == "asStream" )

      return this.httpMethod.getResponseBodyAsStream();

      else

      return this.httpMethod.getResponseBodyAsString();

    };

     

     

     

     

    httpRequest.prototype.deleteRequest = function(uri) {

      this.uri = uri;

     

     

      // Get request.

      this.httpMethod = new DeleteMethod(this.uri);

    };

     

     

     

     

    httpRequest.prototype.disconnect = function() {

      // Release connection.

      this.httpMethod.releaseConnection();

    };

     

     

     

     

    //----------------------------------------------------------------------------------------

    //

    //    Created By: Kevin Chua (kevchua@cisco.com)

    //

    // Function Name: getCount()

    //

    //       Version: 1.0

    //

    //   Description: Count the number of occurrences for an XML tag within the BAM API

    //                Response message

    //

    //        Inputs: str ;Result String to search

    //                d   ;Patter to search for

    //

    //       Outputs: #   ;Returns number of times "d" pattern found in str

    //

    //----------------------------------------------------------------------------------------

     

     

    function getCount(str,d) {

        return str.split("<"+d+">").length - 1;

    }

     

     

     

     

    //----------------------------------------------------------------------------------------

    //

    //    Created By: Kevin Chua (kevchua@cisco.com)

    //

    // Function Name: parseIP4NetworkResult()

    //

    //       Version: 1.0

    //

    //   Description: Parse the BAM API response message for an IP4 Network to split the string

    //                into IP4 Network w/CIDR, Gateway, and determine the netmask

    //

    //        Inputs: strResult ;Result string to parse

    //

    //       Outputs: entityID  ;Returns the Object/Entity ID for the IP4 Network

    //                CIDR ;Returns IP4 Network range

    //                gateway ;Returns Gateway IP4 Address

    //                netmask ;Returns netmask

    //

    //----------------------------------------------------------------------------------------

     

     

    function parseIP4NetworkResult(strResult) {

      logger.addInfo("function parseIP4NetworkResult");

     

     

      idStart = strResult.indexOf("<id>");

      idEnd = strResult.indexOf("</id>");

      entityID = strResult.substring(idStart+4,idEnd);

     

     

      cidrpos = strResult.indexOf("CIDR=");

      delimitpos = strResult.indexOf("|");

     

     

      CIDR = strResult.substring(cidrpos+5, delimitpos);

      slashpos = CIDR.indexOf("/");

      networkPrefix0 = CIDR.substring(slashpos+1);

      networkPrefix = Number(networkPrefix0);

     

     

      gatewaypos = strResult.indexOf("gateway");

      inheritddpos = strResult.indexOf("inheritDefaultDomains");

     

     

      gateway = strResult.substring(gatewaypos+8,inheritddpos-1);

     

     

    // logger.addInfo("entityID: " +entityID);

    // logger.addInfo("CIDR: " +CIDR);

    // logger.addInfo("networkPrefix: " +networkPrefix);

    // logger.addInfo("typeof: "+typeof networkPrefix);

    // logger.addInfo("Gateway: " +gateway);

     

     

      // NetMask Calculation

      switch (networkPrefix) {

      case 24:

      var netmask = "255.255.255.0";

      break;

      case 25:

      var netmask = "255.255.255.128";

      break;

      case 26:

      var netmask = "255.255.255.192";

      break;

      case 27:

      var netmask = "255.255.255.224";

      break;

      case 28:

      var netmask = "255.255.255.240";

      break;

      case 29:

      var netmask = "255.255.255.248";

      break;

      case 30:

      var netmask = "255.255.255.252";

      break; 

      default: // 31

      var netmask = "255.255.255.254";

      }

    // logger.addInfo("netmask: " +netmask);

      

      return [entityID, CIDR, gateway, netmask];

    } //function parseIP4NetworkResult

     

     

     

     

    //----------------------------------------------------------------------------------------

    //

    //    Created By: Kevin Chua (kevchua@cisco.com)

    //

    // Function Name: getNextHostNumber()

    //

    //       Version: 1.0

    //

    //   Description: Process/Read textfile stored on UCSD OVA that contains the last number

    //                used in the hostname. Increment this value to return and re-write this

    //                value into file

    //

    //        Inputs: hostnamePrefix  ;Result string to parse

    //

    //       Outputs: nextHostName    ;Returns the Object/Entity ID for the IP4 Network

    //

    //----------------------------------------------------------------------------------------

     

     

    function getNextHostNumber(hostnamePrefix) {

      this.hostnamePrefix = hostnamePrefix;

     

     

      var DIR_NAME = "/tmp";

      var PL_FILENAME = "last_plhostname";

      var PW_FILENAME = "last_pwhostname";

      var NL_FILENAME = "last_nlhostname";

      var NW_FILENAME = "last_nwhostname";

     

     

      switch (hostnamePrefix) {

      case "PL":

      var absoluteFilePath = DIR_NAME + File.separator + PL_FILENAME;

      break;

      case "PW":

      var absoluteFilePath = DIR_NAME + File.separator + PW_FILENAME;

      break;

      case "NL":

      var absoluteFilePath = DIR_NAME + File.separator + NL_FILENAME;

      break;

      default:  // NP

      var absoluteFilePath = DIR_NAME + File.separator + NW_FILENAME;

      }

     

     

    // logger.addInfo("File Path and Name: "+absoluteFilePath);

     

     

      // READ file to get the last hostname number used for that hostnamePrefix

      var br = new BufferedReader(new FileReader(absoluteFilePath));

     

     

      while(true) {

      var line = br.readLine();

      if (line == null) break;

      var lastHostNumber = line;

    // logger.addInfo("Line: " +lastHostNumber);

      }

      br.close();

     

     

      var pad = "000000"; //need right-padded zeros

      var nextHostNumber = parseInt(lastHostNumber) + 1;

    // logger.addInfo("nextHostNumber: " +nextHostNumber);

      var nextHostnameCounter = pad.substring(0, pad.length - nextHostNumber.toString().length) +  nextHostNumber.toString();

     

     

      var nextHostName = hostnamePrefix+nextHostnameCounter;

    // logger.addInfo("nextHostName: " +nextHostName);

     

     

      // WRITE file for the new hostname number used for that hostnamePrefix

      var bw = new BufferedWriter(new FileWriter(absoluteFilePath));

      bw.write(nextHostNumber.toString());

      bw.flush();

      bw.close();

     

     

      return nextHostName;

    } //function getNextHostNumber

     

     

     

     

    //----------------------------------------------------------------------------------------

    //

    //    Created By: Kevin Chua (kevchua@cisco.com)

    //

    // Function Name: BluecatLogin()

    //

    //       Version: 1.0

    //

    //   Description: BAM API Authentication

    //

    //        Inputs: bluecatTransport  ;http or https

    //                bluecatIP         ;BAM FQDN or IP

    //                bluecatUser       ;BAM API Username

    //                bluecatPassword   ;BAM API User password

    //

    //       Outputs: cookie            ;Returns JSESSIONID value

    //

    //----------------------------------------------------------------------------------------

     

     

    function BluecatLogin(bluecatTransport, bluecatIP, bluecatUser, bluecatPassword) {

      logger.addInfo("function BluecatLogin");

     

     

      this.bcTransport = bluecatTransport;

      this.bcIP = bluecatIP;

      this.bcUser = bluecatUser;

      this.bcPassword = bluecatPassword;

     

     

      var apiName = "login";

     

     

      var msgXML ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:api=\"http://api.proteus.bluecatnetworks.com\">"

      +"<soapenv:Header/>"

       +"<soapenv:Body>"

         +"<api:login>"

            +"<username>"+bcUser+"</username>"

            +"<password>"+bcPassword+"</password>"

         +"</api:login>"

       +"</soapenv:Body>"

      +"</soapenv:Envelope>"

      

      var request = new httpRequest();

     

     

      request.setup(this.bcIP,this.bcTransport,null,null);

      request.postRequest('/Services/API', msgXML);

      request.contentType("xmlt");

      var statusCode = request.execute(apiName);

      var StatusCode = statusCode[0];

      var cookie = statusCode[1];

     

     

      if (StatusCode != 200)

      { 

      logger.addError("Request Failed. HTTP response code: "+statusCode);

      logger.addError("Response = "+request.getResponse("asString"));

     

      var response = request.getResponse("asString");

      logger.addInfo("Response: " +response);

          

      request.disconnect();

      

      ctxt.setFailed("Request failed.");

      } else {

    /*

      logger.addInfo("");

      logger.addInfo("");

      logger.addInfo("<api:login>");

      logger.addInfo("");

      logger.addInfo("Response status: " +StatusCode);

      logger.addInfo("Status message : "+request.getStatusText());

      logger.addInfo("Response body: "+request.getResponseBodyAsString());

    */

      }

     

      return cookie;

     

    } //function BluecatLogin

     

     

     

     

    //----------------------------------------------------------------------------------------

    //

    //    Created By: Kevin Chua (kevchua@cisco.com)

    //

    // Function Name: BluecatGetParent()

    //

    //       Version: 1.0

    //

    //   Description: Utility function used during the development of this integration.  This

    //                function assists with determing the Parent entity ID for the inputted

    //                Entity ID (e.g., determine the Parent Entity ID for the IP4 Network

    //                which would be an IP4 Block)

    //

    //        Inputs: bluecatTransport  ;http or https

    //                bluecatIP         ;BAM FQDN or IP

    //                bluecatUser       ;BAM API Username

    //                bluecatPassword   ;BAM API User password

    //                jssessionid       ;Authentication cookie

    //                entityId          ;Object ID

    //

    //       Outputs: statusCode        ;Returns POST status

    //

    //----------------------------------------------------------------------------------------

     

     

    //

    // getParent

    // UTILITY function can be used to determine an objects parentId

    //

    function BluecatGetParent(bluecatTransport, bluecatIP, bluecatUser, bluecatPassword, jsessionid, entityId) {

      logger.addInfo("function BluecatGetParent");

     

     

      this.bcTransport = bluecatTransport;

      this.bcIP = bluecatIP;

      this.bcUser = bluecatUser;

      this.bcPassword = bluecatPassword;

    // var entityid = input.entityId;

      this.jsessionid = String(jsessionid);

     

     

      var apiName = "getParent";

     

     

      logger.addInfo(apiName+": "+entityId);

     

     

      var msgXML ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:api=\"http://api.proteus.bluecatnetworks.com\">"

      +"<soapenv:Header/>"

       +"<soapenv:Body>"

          +"<api:getParent>"

             +"<entityId>"+entityId+"</entityId>"

          +"</api:getParent>"

       +"</soapenv:Body>"

      +"</soapenv:Envelope>"

      

      var request = new httpRequest();

      var reqhead = "Cookie";

      var reqvalue = "JSESSIONID="+this.jsessionid;

     

     

      request.setup(this.bcIP,this.bcTransport,null,null);

      request.postRequest('/Services/API', msgXML);

      request.addHeader(reqhead, reqvalue);

      request.contentType("xmlt");

      var statusCode = request.execute(apiName);

     

     

      if (statusCode != 200)

      { 

      logger.addError("Request Failed. HTTP response code: "+statusCode);

      logger.addError("Response = "+request.getResponse("asString"));

     

      var response = request.getResponse("asString");

      logger.addInfo("Response: " +response);

     

     

      request.disconnect();

     

     

      ctxt.setFailed("Request failed.");

      } else {

    /*

      logger.addInfo("");

      logger.addInfo("");

      logger.addInfo("<api:getParent>");

      logger.addInfo("");

      logger.addInfo("Response status code: " +statusCode);

      logger.addInfo("Response body: "+request.getResponse("asString"));     

    */

      }

     

     

      return statusCode;

     

    } //function BluecatGetParent

     

     

     

     

    //----------------------------------------------------------------------------------------

    //

    //    Created By: Kevin Chua (kevchua@cisco.com)

    //

    // Function Name: BluecatGetEntityByName()

    //

    //       Version: 1.0

    //

    //   Description: Returns object from the database referenced by their name field.

    //                FUNCTION NOT CURRENTLY USED

    //

    //        Inputs: bluecatTransport  ;http or https

    //                bluecatIP         ;BAM FQDN or IP

    //                bluecatUser       ;BAM API Username

    //                bluecatPassword   ;BAM API User password

    //                jssessionid       ;Authentication cookie

    //                parentId          ;Parent Object ID of the Entity

    //                entityName        ;Name of the Entity

    //                entityType        ;Entity Object Type

    //

    //       Outputs: outputValue       ;Return the Entity ID

    //

    //----------------------------------------------------------------------------------------

     

     

    function BluecatGetEntityByName(bluecatTransport, bluecatIP, bluecatUser, bluecatPassword, jsessionid, parentId, entityName, entityType) {

      logger.addInfo("function BluecatGetEntityByName "+entityType+" "+entityName);

     

     

      this.bcTransport = bluecatTransport;

      this.bcIP = bluecatIP;

      this.bcUser = bluecatUser;

      this.bcPassword = bluecatPassword;

      this.jsessionid = String(jsessionid);

     

     

      var apiName = "getEntityByName";

     

     

      var msgXML ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:api=\"http://api.proteus.bluecatnetworks.com\">"

      +"<soapenv:Header/>"

       +"<soapenv:Body>"

          +"<api:getEntityByName>"

             +"<parentId>"+parentId+"</parentId>"

             +"<name>"+entityName+"</name>"

             +"<type>"+entityType+"</type>"

          +"</api:getEntityByName>"

       +"</soapenv:Body>"

      +"</soapenv:Envelope>"

      

      var request = new httpRequest();

      var reqhead = "Cookie";

      var reqvalue = "JSESSIONID="+this.jsessionid;

     

     

      request.setup(this.bcIP,this.bcTransport,null,null);

      request.postRequest('/Services/API', msgXML);

      request.addHeader(reqhead, reqvalue);

      request.contentType("xmlt");

      var statusCode = request.execute(apiName);

     

     

      if (statusCode != 200)

      { 

      logger.addError("Request Failed. HTTP response code: "+statusCode);

      logger.addError("Response = "+request.getResponse("asString"));

     

      var response = request.getResponse("asString");

      logger.addInfo("Response: " +response);

     

     

      request.disconnect();

     

     

      ctxt.setFailed("Request failed.");

      } else {

    /*

      logger.addInfo("");

      logger.addInfo("");

      logger.addInfo("<api:getEntityByName>");

      logger.addInfo("");

      logger.addInfo("Response status code: " +statusCode);

      logger.addInfo("Response body: "+request.getResponse("asString"));     

    */

      }

     

     

      var requestOut = request.getResponse("asString");

     

     

      startpos = requestOut.indexOf("<id>");

      endpos = requestOut.indexOf("</id>");

      var outputValue = requestOut.substring(startpos+4, endpos);

     

     

    // logger.addInfo("ID Value: " +outputValue);

     

      return outputValue;

     

    } //function BluecatGetEntityByName

     

     

     

     

    //----------------------------------------------------------------------------------------

    //

    //    Created By: Kevin Chua (kevchua@cisco.com)

    //

    // Function Name: BluecatGetLinkedEntities()

    //

    //       Version: 1.0

    //

    //   Description: Returns an array of entities for the provided EntityID and Object Type.

    //                BAM API can't be used to retrieve the linked entities of an IP4 Network,

    //                received response "Link request is not supported"; can't be used to

    //                retrieve sub-Tags

    //

    //        Inputs: bluecatTransport  ;http or https

    //                bluecatIP         ;BAM FQDN or IP

    //                bluecatUser       ;BAM API Username

    //                bluecatPassword   ;BAM API User password

    //                jssessionid       ;Authentication cookie

    //                entityId          ;Entity Id

    //                entityType        ;Entity Object TYpe

    //

    //       Outputs: returnResult      ;Returns the Response String for further processing

    //

    //----------------------------------------------------------------------------------------

     

     

    function BluecatGetLinkedEntities(bluecatTransport, bluecatIP, bluecatUser, bluecatPassword, jsessionid, entityId, entityType) {

      logger.addInfo("function BluecatGetLinkedEntities "+entityId+" "+entityType);

     

     

      this.bcTransport = bluecatTransport;

      this.bcIP = bluecatIP;

      this.bcUser = bluecatUser;

      this.bcPassword = bluecatPassword;

      this.jsessionid = String(jsessionid);

     

     

      var apiName = "getLinkedEntities";

     

     

      var msgXML ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:api=\"http://api.proteus.bluecatnetworks.com\">"

      +"<soapenv:Header/>"

       +"<soapenv:Body>"

          +"<api:getLinkedEntities>"

             +"<entityId>"+entityId+"</entityId>"

             +"<type>"+entityType+"</type>"

             +"<start>0</start>"

             +"<count>10</count>"

          +"</api:getLinkedEntities>"

       +"</soapenv:Body>"

      +"</soapenv:Envelope>"

      

      var request = new httpRequest();

      var reqhead = "Cookie";

      var reqvalue = "JSESSIONID="+this.jsessionid;

     

     

      request.setup(this.bcIP,this.bcTransport,null,null);

      request.postRequest('/Services/API', msgXML);

      request.addHeader(reqhead, reqvalue);

      request.contentType("xmlt");

      var statusCode = request.execute(apiName);

     

     

      if (statusCode != 200)

      { 

      logger.addError("Request Failed. HTTP response code: "+statusCode);

      logger.addError("Response = "+request.getResponse("asString"));

     

      var response = request.getResponse("asString");

      logger.addInfo("Response: " +response);

     

     

      request.disconnect();

     

     

      ctxt.setFailed("Request failed.");

      } else {

    /*

      logger.addInfo("");

      logger.addInfo("");

      logger.addInfo("<api:getLinkedEntities>");

      logger.addInfo("");

      logger.addInfo("Response status code: " +statusCode);

      logger.addInfo("Response body: "+request.getResponse("asString"));

    */

      }

     

     

      var requestOut = request.getResponse("asString");

    // logger.addInfo("requestOut typeof: " +typeof requestOut);

     

     

      //Need to count the number of xml tag <item>

      var patternCount = getCount(String(requestOut),"item");

    // logger.addInfo("Number Times <item>: "+patternCount);

    // logger.addInfo("patternCount typeof: " +typeof patternCount);

     

     

      var returnStart = requestOut.indexOf("<return>");

      var returnEnd = requestOut.indexOf("</return>");

     

     

      var ro = requestOut.substring(returnStart+8, returnEnd);

    // logger.addInfo("ro: " +ro);

     

     

    // var res = ro.slice("</item>");

    // logger.addInfo("res: " +res);

     

     

      var returnResult = new Array();

      for (i = patternCount; i > 0; i--) {

      var itemStart = ro.indexOf("<item>");

      var itemEnd = ro.indexOf("</item>");

     

     

      var roCurrent = ro.substring(itemStart+6, itemEnd);

      var ro = ro.substring(itemEnd+7);

    // logger.addInfo("roCurrent: " +roCurrent);

      returnResult.push(roCurrent);

      }

     

     

    // logger.addInfo("returnResult typeof: " +typeof returnResult);

      return returnResult;

     

    } //function BluecatGetLinkedEntities

     

     

     

     

    //----------------------------------------------------------------------------------------

    //

    //    Created By: Kevin Chua (kevchua@cisco.com)

    //

    // Function Name: BluecatGetNextAvailableIP4Network()

    //

    //       Version: 1.0

    //

    //   Description: Returns the object ID for the next available (unused) network within

    //                a block.

    //                FUNCTION NOT CURRENTLY USED

    //

    //        Inputs: bluecatTransport  ;http or https

    //                bluecatIP         ;BAM FQDN or IP

    //                bluecatUser       ;BAM API Username

    //                bluecatPassword   ;BAM API User password

    //                jssessionid       ;Authentication cookie

    //                ip4BlockOID       ;Object ID of IP4 Block

    //

    //       Outputs: statusCode        ;Returns response status code

    //                nextIP4Network    ;Returns the next IP4 Network

    //

    //----------------------------------------------------------------------------------------

     

     

    function BluecatGetNextAvailableIP4Network(bluecatTransport, bluecatIP, bluecatUser, bluecatPassword, jsessionid, ip4BlockOID) {

      logger.addInfo("function BluecatGetNextAvailableIP4Network " +ip4BlockOID);

     

     

      this.bcTransport = bluecatTransport;

      this.bcIP = bluecatIP;

      this.bcUser = bluecatUser;

      this.bcPassword = bluecatPassword;

      this.jsessionid = String(jsessionid);

     

     

      var apiName = "getNextAvailableIP4Network";

     

     

      var msgXML ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:api=\"http://api.proteus.bluecatnetworks.com\">"

      +"<soapenv:Header/>"

       +"<soapenv:Body>"

          +"<api:getNextAvailableIP4Range>"

             +"<parentId>"+ip4BlockOID+"</parentId>"

      +"<size>24</size>"

      +"<type>IP4Network</type>"

      +"</properties>"

          +"</api:getNextAvailableIP4Range>"

       +"</soapenv:Body>"

      +"</soapenv:Envelope>"

      

      var request = new httpRequest();

      var reqhead = "Cookie";

      var reqvalue = "JSESSIONID="+this.jsessionid;

     

     

      request.setup(this.bcIP,this.bcTransport,null,null);

      request.postRequest('/Services/API', msgXML);

      request.addHeader(reqhead, reqvalue);

      request.contentType("xmlt");

      var statusCode = request.execute(apiName);

     

     

      if (statusCode != 200)

      { 

      logger.addError("Request Failed. HTTP response code: "+statusCode);

      logger.addError("Response = "+request.getResponse("asString"));

     

      var response = request.getResponse("asString");

      logger.addInfo("Response: " +response);

          

      request.disconnect();

      

      ctxt.setFailed("Request failed.");

      } else {

    /*

      logger.addInfo("");

      logger.addInfo("");

      logger.addInfo("<api:getNextAvailableIP4Network>");

      logger.addInfo("");

      logger.addInfo("Response status code: " +statusCode);

      logger.addInfo("Response body: "+request.getResponse("asString"));   

    */

      }

     

     

      var strResult = request.getResponse("asString");

     

     

      returnStart = strResult.indexOf("<return>");

      returnEnd = strResult.indexOf("</return>");

      nextIP4Network = strResult.substring(returnStart+8,returnEnd);

     

     

    // logger.addInfo("Next Available IPv4 Network: " +nextIP4Network);

     

     

      return [statusCode, nextIP4Network];

     

     

    } // function BluecatGetNextAvailableIP4Network

     

     

     

     

    //----------------------------------------------------------------------------------------

    //

    //    Created By: Kevin Chua (kevchua@cisco.com)

    //

    // Function Name: BluecatGetNextAvailableIP4Address()

    //

    //       Version: 1.0

    //

    //   Description: Returns the IPv4 address for the next available (unallocated) address

    //                within a network.

    //

    //        Inputs: bluecatTransport  ;http or https

    //                bluecatIP         ;BAM FQDN or IP

    //                bluecatUser       ;BAM API Username

    //                bluecatPassword   ;BAM API User password

    //                jssessionid       ;Authentication cookie

    //                ip4NetworkOID     ;Object ID for IP4 Network

    //

    //       Outputs: cookie            ;Returns JSESSIONID value

    //

    //----------------------------------------------------------------------------------------

     

     

    function BluecatGetNextAvailableIP4Address(bluecatTransport, bluecatIP, bluecatUser, bluecatPassword, jsessionid, ip4NetworkOID) {

      logger.addInfo("function BluecatGetNextAvailableIP4Address " +ip4NetworkOID);

     

     

      this.bcTransport = bluecatTransport;

      this.bcIP = bluecatIP;

      this.bcUser = bluecatUser;

      this.bcPassword = bluecatPassword;

      this.jsessionid = String(jsessionid);

     

     

      var apiName = "getNextAvailableIP4Address";

     

     

      var msgXML ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:api=\"http://api.proteus.bluecatnetworks.com\">"

      +"<soapenv:Header/>"

       +"<soapenv:Body>"

          +"<api:getNextAvailableIP4Address>"

             +"<parentId>"+ip4NetworkOID+"</parentId>"

          +"</api:getNextAvailableIP4Address>"

       +"</soapenv:Body>"

      +"</soapenv:Envelope>"

      

      var request = new httpRequest();

      var reqhead = "Cookie";

      var reqvalue = "JSESSIONID="+this.jsessionid;

     

     

      request.setup(this.bcIP,this.bcTransport,null,null);

      request.postRequest('/Services/API', msgXML);

      request.addHeader(reqhead, reqvalue);

      request.contentType("xmlt");

      var statusCode = request.execute(apiName);

     

     

      if (statusCode != 200)

      { 

      logger.addError("Request Failed. HTTP response code: "+statusCode);

      logger.addError("Response = "+request.getResponse("asString"));

     

      var response = request.getResponse("asString");

      logger.addInfo("Response: " +response);

          

      request.disconnect();

      

      ctxt.setFailed("Request failed.");

      } else {

    /*

      logger.addInfo("");

      logger.addInfo("");

      logger.addInfo("<api:getNextAvailableIP4Address>");

      logger.addInfo("");

      logger.addInfo("Response status code: " +statusCode);

      logger.addInfo("Response body: "+request.getResponse("asString"));   

    */

      }

     

     

    // SAMPLE RETURNED RESULT

    //<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header></env:Header><env:Body><api:getNextAvailableIP4AddressResponse xmlns:api='http://api.proteus.bluecatnetworks.com'><return>10.8.132.1</return></api:getNextAvailableIP4AddressResponse></env:Body></env:Envelope>

     

      var strResult = request.getResponse("asString");

     

     

      returnStart = strResult.indexOf("<return>");

      returnEnd = strResult.indexOf("</return>");

      nextIP4Address = strResult.substring(returnStart+8,returnEnd);

     

     

    // logger.addInfo("Next Available IPv4: " +nextIP4Address);

     

     

      return [statusCode, nextIP4Address];

     

     

    } //function BluecatGetNextAvailableIP4Address

     

     

     

     

    //----------------------------------------------------------------------------------------

    //

    //    Created By: Kevin Chua (kevchua@cisco.com)

    //

    // Function Name: BluecatGetHostRecordsByHint()

    //

    //       Version: 1.0

    //

    //   Description: Returns an array of objects with host record type; Used to check if

    //                derived hostname is already used in DNS

    //

    //        Inputs: bluecatTransport  ;http or https

    //                bluecatIP         ;BAM FQDN or IP

    //                bluecatUser       ;BAM API Username

    //                bluecatPassword   ;BAM API User password

    //                jssessionid       ;Authentication cookie

    //                nextHostname      ;Derived next hostname

    //

    //       Outputs: statusCode        ;Returns response status code

    //

    //----------------------------------------------------------------------------------------

     

     

    //

    // Check to see if the Hostname exists

    //

    function BluecatGetHostRecordsByHint(bluecatTransport, bluecatIP, bluecatUser, bluecatPassword, jsessionid, nextHostname) {

      logger.addInfo("function BluecatGetHostRecordsByHint " +nextHostname);

     

     

      this.bcTransport = bluecatTransport;

      this.bcIP = bluecatIP;

      this.bcUser = bluecatUser;

      this.bcPassword = bluecatPassword;

      this.jsessionid = String(jsessionid);

     

     

      var apiName = "getHostRecordsByHint";

     

     

      var hint = "hint=^"+String(nextHostname)+"$";

     

     

      var msgXML ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:api=\"http://api.proteus.bluecatnetworks.com\">"

      +"<soapenv:Header/>"

       +"<soapenv:Body>"

          +"<api:getHostRecordsByHint>"

             +"<start>0</start>"

             +"<count>1</count>"

             +"<options>"+hint+"</options>"

          +"</api:getHostRecordsByHint>"

       +"</soapenv:Body>"

      +"</soapenv:Envelope>"

     

     

      var request = new httpRequest();

      var reqhead = "Cookie";

      var reqvalue = "JSESSIONID="+this.jsessionid;

     

     

      request.setup(this.bcIP,this.bcTransport,null,null);

      request.postRequest('/Services/API', msgXML);

      request.addHeader(reqhead, reqvalue);

      request.contentType("xmlt");

      var statusCode = request.execute(apiName);

     

     

      if (statusCode != 200)

      { 

      logger.addError("Request Failed. HTTP response code: "+statusCode);

      logger.addError("Response = "+request.getResponse("asString"));

     

      var response = request.getResponse("asString");

      logger.addInfo("Response: " +response);

          

      request.disconnect();

      

      ctxt.setFailed("Request failed.");

      } else {

    /*

      logger.addInfo("");

      logger.addInfo("");

      logger.addInfo("<api:getHostRecordsByHint>");

      logger.addInfo("");

      logger.addInfo("Response status code: " +statusCode);

      logger.addInfo("Response body: "+request.getResponse("asString"));

    */

      //StatusCode 200 received if hostname exists or not

      //if idpos > 0, then hostname exists

      var idpos = request.getResponse("asString").indexOf("<id>");

      if (idpos >= 0) {

      statusCode = 500;

      }

      }

     

      return statusCode;

     

    } //function BluecatGetHostRecordsByHint

     

     

     

     

    //----------------------------------------------------------------------------------------

    //

    //    Created By: Kevin Chua (kevchua@cisco.com)

    //

    // Function Name: BluecatAddHostRecord()

    //

    //       Version: 1.0

    //

    //   Description: Creates a new DNS A Record and Assigns the IP4 Address

    //

    //        Inputs: bluecatTransport  ;http or https

    //                bluecatIP         ;BAM FQDN or IP

    //                bluecatUser       ;BAM API Username

    //                bluecatPassword   ;BAM API User password

    //                jssessionid       ;Authentication cookie

    //                nextHostname      ;Derived hostname

    //                domain            ;Domain suffix (tst.genco.com or genco.com)

    //                nextIP4Address    ;IP4 Address to assign with hostname

    //

    //       Outputs: nextFQDN          ;Returns FQDN

    //

    //----------------------------------------------------------------------------------------

     

     

    function BluecatAddHostRecord(bluecatTransport, bluecatIP, bluecatUser, bluecatPassword, jsessionid, nextHostname, domain, nextIP4Address) {

      logger.addInfo("function BluecatAddHostRecord " +nextHostname+ " " +domain+ " " +nextIP4Address);

     

     

      this.bcTransport = bluecatTransport;

      this.bcIP = bluecatIP;

      this.bcUser = bluecatUser;

      this.bcPassword = bluecatPassword;

      var dnsViewOID = input.dnsViewOID; //internal

      this.jsessionid = String(jsessionid);

     

     

      this.domainName = "."+domain;

      nextFQDN = nextHostname.concat(this.domainName);

     

     

      var apiName = "addHostRecord";

     

     

      var msgXML ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:api=\"http://api.proteus.bluecatnetworks.com\">"

      +"<soapenv:Header/>"

       +"<soapenv:Body>"

          +"<api:addHostRecord>"

             +"<viewId>"+dnsViewOID+"</viewId>"

             +"<absoluteName>"+nextFQDN+"</absoluteName>"

             +"<addresses>"+nextIP4Address+"</addresses>"

             +"<ttl>-1</ttl>"

             +"<properties/>"

          +"</api:addHostRecord>"

       +"</soapenv:Body>"

      +"</soapenv:Envelope>"

      

      var request = new httpRequest();

      var reqhead = "Cookie";

      var reqvalue = "JSESSIONID="+this.jsessionid;

     

     

      request.setup(this.bcIP,this.bcTransport,null,null);

      request.postRequest('/Services/API', msgXML);

      request.addHeader(reqhead, reqvalue);

      request.contentType("xmlt");

      var statusCode = request.execute(apiName);

     

     

      if (statusCode != 200)

      { 

      logger.addError("Request Failed. HTTP response code: "+statusCode);

      logger.addError("Response = "+request.getResponse("asString"));

     

      var response = request.getResponse("asString");

      logger.addInfo("Response: " +response);

          

      request.disconnect();

      

      ctxt.setFailed("Request failed.");

      } else {

    /*

      logger.addInfo("");

      logger.addInfo("");

      logger.addInfo("<api:addHostRecord>");

      logger.addInfo("");

      logger.addInfo("Response status code: " +statusCode);

      logger.addInfo("Response body: "+request.getResponse("asString"));

    */

      }

     

      return nextFQDN;

     

    } //function BluecatAddHostRecord

     

     

     

     

    //----------------------------------------------------------------------------------------

    //

    //    Created By: Kevin Chua (kevchua@cisco.com)

    //

    // Function Name: BluecatLogout()

    //

    //       Version: 1.0

    //

    //   Description: Logout to close BAM API Connection

    //

    //        Inputs: bluecatTransport  ;http or https

    //                bluecatIP         ;BAM FQDN or IP

    //                bluecatUser       ;BAM API Username

    //                bluecatPassword   ;BAM API User password

    //                jssessionid       ;Authentication cookie

    //

    //       Outputs: true              ;

    //

    //----------------------------------------------------------------------------------------

     

     

    function BluecatLogout(bluecatTransport, bluecatIP, bluecatUser, bluecatPassword, jsessionid) {

      logger.addInfo("function BluecatLogout");

     

     

      this.bcTransport = bluecatTransport;

      this.bcIP = bluecatIP;

      this.bcUser = bluecatUser;

      this.bcPassword = bluecatPassword;

      this.jsessionid = String(jsessionid);

     

     

      var apiName = "logout";

     

     

      var msgXML ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:api=\"http://api.proteus.bluecatnetworks.com\">"

      +"<soapenv:Header/>"

       +"<soapenv:Body>"

         +"<api:logout/>"

       +"</soapenv:Body>"

      +"</soapenv:Envelope>"

      

      var request = new httpRequest();

      var reqhead = "Cookie";

      var reqvalue = "JSESSIONID="+this.jsessionid;

     

     

      request.setup(this.bcIP,this.bcTransport,null,null);

      request.postRequest('/Services/API', msgXML);

      request.addHeader(reqhead, reqvalue);

      request.contentType("xmlt");

      var statusCode = request.execute(apiName);

     

     

      if (statusCode != 200)

      { 

      logger.addError("Request Failed. HTTP response code: "+statusCode);

      logger.addError("Response = "+request.getResponse("asString"));

     

      var response = request.getResponse("asString");

      logger.addInfo("Response: " +response);

          

      request.disconnect();

      

      ctxt.setFailed("Request failed.");

      } else {

    /*

      logger.addInfo("");

      logger.addInfo("");

      logger.addInfo("<api:getEntityById>");

      logger.addInfo("");

      logger.addInfo("Response status code: " +statusCode);

      logger.addInfo("Response body: "+request.getResponse("asString"));

    */      

      }

     

      return true;

     

    } //function BluecatLogout

     

     

     

     

    //////////////////////////////////////////////////////////////////////////////////////////

    //

    // main();

    //

     

     

    // Workflow Inputs Mappings

    var bluecatIP = input.BluecatIP;

    var bluecatTransport = input.BluecatTransport;

    var bluecatAccount = getAccount(String(input.BluecatAccount));

     

     

    var networkType = String(input.GenCoNetwork);

    var hostOS = String(input.GenCoHostOSType);

    //logger.addInfo("Network LOV: " +networkType);

    //logger.addInfo("HostOS LOV: " +hostOS);

     

     

    var bluecatUser = bluecatAccount.getUserName();

    var bluecatPassword = bluecatAccount.getPassword();

     

     

    var session = BluecatLogin (bluecatTransport, bluecatIP, bluecatUser, bluecatPassword);

     

     

    // FUNCTION ONLY USED FOR UNIT TESTING TO DERIVE THE PARENTID IF YOU CAN'T LOCATE IN Bluecat Address Manager UI

    //var request = BluecatGetParent (bluecatTransport, bluecatIP, bluecatUser, bluecatPassword, session, input.entityID);

     

     

    switch (networkType) {

      case "P": //Production

      case "p":

      var entityID = String(input.prodTagNameEntityID);

      var domain = "genco.com";

      break;

      default: // Non-Production

      var entityID = String(input.nonprodTagNameEntityID);

      var domain = "tst.genco.com";

    }

    var entityType = "IP4Network";

    var retrieveNetwork = false;

     

     

    // Retrieve all IP4 Networks that are Tagged

    var ip4NetworkArray = BluecatGetLinkedEntities (bluecatTransport, bluecatIP, bluecatUser, bluecatPassword, session, entityID, "IP4Network");

    var arrayLength = ip4NetworkArray.length;

     

     

    //logger.addInfo("Number Tagged IP4 Networks: " +arrayLength);

     

     

    while (retrieveNetwork == false) {

      // Retrieve an IP4 Block from the returned array

      var ip4Network = ip4NetworkArray.shift();

     

     

    // logger.addInfo("ip4Network: " +ip4Network);

     

     

      // SAMPLE RETURNED RESULT

      //<id>614603</id><name xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true'/><properties>CIDR=10.8.132.0/24|allowDuplicateHost=enable|inheritAllowDuplicateHost=true|pingBeforeAssign=disable|inheritPingBeforeAssign=true|gateway=10.8.132.254|inheritDefaultDomains=true|defaultView=87576|inheritDefaultView=true|inheritDNSRestrictions=true|</properties><type>IP4Network</type>

     

     

      var ip4NetworkResults = parseIP4NetworkResult(ip4Network);

      //logger.addInfo("ip4NetworkResults typeof: " +typeof ip4NetworkResults);

      //logger.addInfo("ip4NetworkResults: " +ip4NetworkResults);

     

     

      // Retrieve IP4Network entityId

      // Retrieve IP4Network CIDR

      // Retrieve IP4Network gateway

      var ip4networkentityid = ip4NetworkResults[0];

      var cidr = ip4NetworkResults[1];

      var gateway = ip4NetworkResults[2];

      var netmask = ip4NetworkResults[3];

     

     

      //logger.addInfo("ip4networkentityid: " +ip4networkentityid);

      //logger.addInfo("cidr: " +cidr);

      //logger.addInfo("gateway: " +gateway);

      //logger.addInfo("netmask: " +netmask);

     

     

      // Based on a successfully Returned IP4 Network

      // Retrieve the next available IP4 Address

      var nextip4address = BluecatGetNextAvailableIP4Address (bluecatTransport, bluecatIP, bluecatUser, bluecatPassword, session, ip4networkentityid);

     

     

      var nextip4addressStatus = nextip4address[0];

     

     

      if (parseInt(nextip4addressStatus) == 200) {

      // Found an available IP4 Address

      // Don't need to move to the next IP4 Network to find an available IP4 Address

      var nextip4add = nextip4address[1];

    // logger.addInfo("Next IP4 Address: " +nextip4add);

     

      retrieveNetwork = true;

      }

    }

     

    // Generate the Hostname Prefix

    var hostnamePrefix = networkType+hostOS;

    //logger.addInfo("hostnamePrefix: " +hostnamePrefix);

     

     

    var hostnameExists = false;

    var heCount = 1;

     

     

    while (hostnameExists == false) {

      // Generate new hostname

      var nextHost = getNextHostNumber(hostnamePrefix);

     

     

      // Check to see if hostname has been assigned

      var hostnameStatus = BluecatGetHostRecordsByHint (bluecatTransport, bluecatIP, bluecatUser, bluecatPassword, session, nextHost);

     

     

      if (parseInt(hostnameStatus) == 200) {

      // hostname is not assigned

      hostnameExists = true;

      }

     

     

    } //while (hostnameExists == false)

     

     

    // logger.addInfo("nextHost: " +nextHost);

     

     

    // Create the DNS Entry

    var fqdnStatus = BluecatAddHostRecord (bluecatTransport, bluecatIP, bluecatUser, bluecatPassword, session, nextHost, domain, nextip4add);

     

     

    var close = BluecatLogout (bluecatTransport, bluecatIP, bluecatUser, bluecatPassword, session);

     

     

    // Workflow Outputs Mappings

    output.CIDR = cidr;

    output.nextIP4Address = nextip4add;

    output.gateway = gateway;

    output.netmask = netmask;

    output.nextHostname = nextHost;

    output.nextFQDN = nextHost + "." + domain;

     

     

    The API guide (please request from Blue Cat):

     

    Screen Shot 2015-09-16 at 4.24.15 PM.png