Provision Script with unique Token

Hello,

I have a problem with a provision script which calls an EXT script.
The provision script makes a request via an External script with an IMSI.
The remote API does not return information directly, but returns a Token.

This Token is subsequently used to retrieve the information necessary for provisioning the device.

However, the provisioning script runs several times (to detect a stable state? cf. Administration FAQ — GenieACS Documentation 1.2.9 documentation) therefore I obtain a new Token each time

How can I make the script only run once?

Thank you in advance for your help

Laurent

const DEBUG = false;
const now = Date.now();

let provisioned = declare("Tags.Basic_Provisioned", {value: 1});
if (provisioned.value !== undefined) {
    DEBUG && log('CPE is (already) provisioned, returning');
    return;
}

let device = declare("DeviceID.ID", {value: 1}).value[0];
 DEBUG && log('DeviceID: ' + device);
device = encodeURI(device);
 DEBUG && log('DeviceID encoded: ' + device);

let ProductClass = declare("DeviceID.ProductClass", {value: 1}).value[0];
let imsi = declare("InternetGatewayDevice.WANDevice.2.X_ATP_WANUMTSInterfaceConfig.IMSI", {value: 1}).value[0];

let token_sdm_info = declare("VirtualParameters.TokenSdmInfo", {value: now}).value[0];
let msisdn = '--';


if(!imsi){ // If imsi is empty => exit
  DEBUG && log('No IMSI returned by the CPE, ');
  return;
} 

let args = {device: device , imsi: imsi };

DEBUG && log('Args ' + JSON.stringify(args));

if(!token_sdm_info){ // If token_sdm_info is empty launch request_sdm_info else query_sdm_info
  DEBUG && log('TokenSdmInfo est vide, launch request_sdm_info()');
  request_sdm_info(args);
} else{
  DEBUG && log('TokenSdmInfo est PRESENT, EXIT');
  return;
  
}


function request_sdm_info(args){ // Demande les infos radius
  //Get the params from api
  DEBUG && log('Launch ext script fnt request_sdm_info');
  
  let config = ext('cpe-config-new', 'request_sdm_info', JSON.stringify(args));  
  DEBUG && log('Config values from API: ' + JSON.stringify(config));

  if (!config) {
    DEBUG && log('No config returned from API');
    push_metrics('Basic_Provisioning_request', JSON.stringify({ "msg": "No answer from NEP", "status": "ko" }));
    return;
  }

  if (config.code !== 202) {
    DEBUG && log('No config returned from API (' + config.message + ')');
    push_metrics('Basic_Provisioning_request', JSON.stringify({ "code": config.code, "msg": config.message, "status": "ko" }));
    return;
  }
  
  let Token = config.data.token;
  DEBUG && log('New Token value ' + Token);
  declare("VirtualParameters.TokenSdmInfo", {value: now}, {value: Token}); // Set  Token in VirtualParameters.TokenSdmInfo
  commit();
  DEBUG && log('End Fnt request_sdm_info ');
  push_metrics('Basic_Provisioning_request', JSON.stringify({ "code": config.code, "msg": config.message,"token":Token, "status": "ok" }));
  return; 

}

function push_metrics(event_value, datajson) {
    let metrics_data = { "table": 'acs_events', data: { time: Math.floor(now / 1000), "device_id": device, "dept": 0, "idur": '', "event_type": "basic_provisioning", "event_value": event_value, "data": datajson } };
    DEBUG && log('Metrics_data ' + JSON.stringify(metrics_data));

    let config = ext('push-metrics-tms', 'metrics', JSON.stringify(metrics_data));
    DEBUG && log('Callback from API: ' + JSON.stringify(config));
}

very simple: you don’t call the api from the extension. Something as I suggested here

Hi,

Thanks for your return.
The idea is good, but I have to make do with existing infrastructure.

To provide context, the ACS server is completely isolated from the rest of the IS (BDD).
The data for provisioning is retrieved via a server (Swagger + RabbitMq) which receives the requests, gives a Token, after which we query the same server with the token which finally gives us the response with the parameters useful for provisioning.

Laurent

One way to accomplish this is to set a vparam for the CPE with that token. Then if there is a token set, you know the process is in motion and use that token to correlate things.

Hello,

I already use a VParm

let token_sdm_info = declare("VirtualParameters.TokenSdmInfo", {value: now}).value[0];

But the problem is that the EXT script is executed 3 times each time, and therefore I generate 3 Tokens (and I only store the last one)
Slts,

L.F.

In your provision script check for a value in the TokenSdmInfo vparam. If one exists, then don’t run your ext script again.

Good morning,

Indeed, this is the operation I expect.

I notice by doing a ps -edf that the EXT provisioning scripts are present 3 times, is this normal?

ps -edf | grep cpe-config
genieacs 2536350 2536323  0 02:20 ?        00:00:10 node /opt/genieacs/dist/bin/genieacs-ext cpe-config
genieacs 2536369 2536323  0 02:21 ?        00:00:05 node /opt/genieacs/dist/bin/genieacs-ext cpe-config-new
genieacs 2537050 2537026  0 05:57 ?        00:00:03 node /opt/genieacs/dist/bin/genieacs-ext cpe-config-new
genieacs 2537062 2537026  0 05:57 ?        00:00:06 node /opt/genieacs/dist/bin/genieacs-ext cpe-config
genieacs 2537714 2537687  0 09:16 ?        00:00:01 node /opt/genieacs/dist/bin/genieacs-ext cpe-config
genieacs 2537749 2537687  0 09:17 ?        00:00:00 node /opt/genieacs/dist/bin/genieacs-ext cpe-config-new

Thanks

Laurent

Yes. I’m going to presume you either have 3 cores, or have changed the config to allocate 3 workers for the NBI process.

Please note that if you make a change to an ext script you will need to restart the NBI process for changes to take effect.