JavaScript Examples - BlueCat vRO Plug-in - 8.0.1-9.2.0

IPAM Automation Guide

Locale
English
Product name
BlueCat vRO Plug-in
Version
8.0.1-9.2.0

Refer to the following JavaScript examples.

Using APIEntity and passing a Long object

This script will demonstrate how to use APIEntity and how to correctly pass a Long object into to API method. It will create Configuration, TFTP Group and finally delete the Configuration.

/* Copyright 2020 BlueCat Networks (USA) Inc. and its affiliates. All Rights Reserved. */
var result
var configId;
try 
{
       var testConfig = BCNProteusAPI.createAPIEntity( new java.lang.Long(0),configName,"","Configuration" );
       var args = new Array( new java.lang.Long(0), testConfig );
       configId = new java.lang.Long( BCNProteusAPI.call( profileName,"addEntity",args ));
       System.log( "New configuration was created, id=" + configId );
       var addTFTPGroupArgs = new Array( configId, "tftpGroupName1", "" );
       var tftpGroupId = new java.lang.Long( BCNProteusAPI.call( profileName,"addTFTPGroup", addTFTPGroupArgs ) );
       System.log( "New TFTP Group was created, id=" + tftpGroupId );
} 
catch( err ) 
{
       System.log( "ERROR: " + err.message );
       throw( err );
} 
finally 
{
       var deleteConfigArgs = new Array( configId );
       BCNProteusAPI.call( profileName, "delete", deleteConfigArgs );
       System.log( "Configration was deleted, id=" + configId );
}

Finding the DNS deployment role and changing the role type

The script will find the DNS deployment role and change the role type to MASTER if it is SLAVE, and change to SLAVE if it is MASTER. To run this script, the following entities must be created:
  • Configuration—the configuration's name will be used a parameter of this workflow.
  • DNS View—under the configuration with name default.
  • DNS deployment role—under the view configured to be deployed to the master or slave server.
var args = new Array( new java.lang.Long(0), configName, "Configuration" );
var result;

System.log ( “calling API with: ” + args.toString() );

try
{
  result = BCNProteusAPI.call( profileName, "getEntityByName", args );
 
  System.log( result.getType() + "," + result.getId() );
  var configId = new java.lang.Long( result.getId() );
  args = new Array( configId,"default", "View" );
  result = BCNProteusAPI.call( profileName, "getEntityByName", args );
  var viewId = new java.lang.Long( result.getId() );
  args = new Array( viewId );
  result = BCNProteusAPI.call( profileName, "getDeploymentRoles", args );
  System.log( "type of return " + typeof result + ",keys:" + Object.keys(result.getItem()) );
  for (var key in result.getItem() ) 
  {
    if ( result.getItem().hasOwnProperty(key)) 
    {
      var v = result.getItem()[key];
      System.log( key + " -> " + v.getType() + "," + v.getId() + "," + v.getServerInterfaceId() + "," + v.getProperties() );
      if( v.getType() == "MASTER" )
      {
        v.setType( "SLAVE" );
      }
      else if( v.getType() == "SLAVE" )
      {
        v.setType( "MASTER" );
      }
      args = new Array( v );
      result = BCNProteusAPI.call( profileName, "updateDNSDeploymentRole", 
      args );
    }
  }
}
catch( err )
{
  System.log( "ERROR: " + err.message );
  throw( err );
}