newspaint

Documenting Problems That Were Difficult To Find The Answer To

GenieACS Provision Script Helper Functions

The following are some helper functions that can be added to a GenieACS provision script to make things easier.

// getFirstValue() - takes iterator and returns the first value found
//
// Usage (to create new branch and return the path to it):
//   var softwareVersion = getFirstPath(
//     declare( "InternetGatewayDevice.DeviceInfo.SoftwareVersion", {value:0} )
//   );
//
//   if ( ! softwareVersion ) {
//     softwareVersion = getFirstPath(
//       declare( "Device.DeviceInfo.SoftwareVersion", {value:0} )
//     );
//   }

function getFirstValue( iterator ) {
  for (let element of iterator) {
    if ( element.value && ( element.value[0] != undefined ) ) {
      return element.value[0];
    }
  }

  return undefined;
}
// getFirstPath() - takes iterator and returns the first path found
//
// Usage (to create new branch and return the path to it):
//   const newPathWANPPPConnection = getFirstPath(
//     declare(
//       `${pathWANConnectionDevice}.WANPPPConnection.[Name:MyNewPPP]`,
//       {path: now},
//       {path: 1}
//     )
//   );

function getFirstPath( iterator ) {
  for (let element of iterator) {
    if ( element.path ) {
      return element.path;
    }
  }

  return undefined;
}

Leave a comment