Help with improvements

I have this fairly functional provisioning script and I’d like to improve it. I tried using the other method, but the parameters I use with ZTE have (-) and I couldn’t get it to work. Also, I’d like to know how I can delete a WAN parameter with a specific VLAN (104)

const now = Date.now();

// Clear cached data model to force a refresh
clear("Device", now);
clear("InternetGatewayDevice", now);
log ('INICIO');

const cpe_model = declare("DeviceID.ProductClass", {value: 1}).value[0];
let cpe_sn = declare("DeviceID.SerialNumber", {value: now}).value[0];
const proveedor = "xxxx-";
const cpe_pass1 = "xxxx123456";
let cpe_sn_4
let cpe_pass
let wifi
let wan_internet
log ('Se inicializa ONT modelo zte...');
cpe_sn_4 = cpe_sn.substring(cpe_sn.length - 4);
cpe_pass = cpe_sn.substr(0,8);
wifi=(proveedor.concat(cpe_sn_4));
log ('se configura wifi 2.4g');
declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.SSID",null, {value: wifi.concat("-2g")});
declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.KeyPassphrase",null, {value: cpe_pass1});
log ('se configura wifi 5g');
declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.5.SSID",null, {value: wifi.concat("-5g")});
declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.5.KeyPassphrase",null, {value: cpe_pass1});
log ('habilitando acceso remoto');
declare("InternetGatewayDevice.Firewall.*.*", {path: now}); // refrescar subtree
declare("InternetGatewayDevice.Firewall.X_ZTE-COM_ServiceControl.IPV4ServiceControl.*", null, {path: 1});
declare("InternetGatewayDevice.Firewall.X_ZTE-COM_ServiceControl.IPV4ServiceControl.1.Enable", {value: now}, {value: true});
declare("InternetGatewayDevice.Firewall.X_ZTE-COM_ServiceControl.IPV4ServiceControl.1.IPEnd", {value: now}, {value:"0.0.0.0"});
declare("InternetGatewayDevice.Firewall.X_ZTE-COM_ServiceControl.IPV4ServiceControl.1.IPStart", {value: now}, {value:"0.0.0.0"});
declare("InternetGatewayDevice.Firewall.X_ZTE-COM_ServiceControl.IPV4ServiceControl.1.Ingress", {value: now}, {value:"WAN_ALL"});
declare("InternetGatewayDevice.Firewall.X_ZTE-COM_ServiceControl.IPV4ServiceControl.1.Mode", {value: now}, {value:"Accept"});
declare("InternetGatewayDevice.Firewall.X_ZTE-COM_ServiceControl.IPV4ServiceControl.1.Name", {value: now}, {value:"Acceso_remoto_mngmt"});
declare("InternetGatewayDevice.Firewall.X_ZTE-COM_ServiceControl.IPV4ServiceControl.1.ServiceType", {value: now}, {value:"HTTP,PING"});
log ("acceso remoto activado");
//log ("name and nat for tr69wan");
//desactivo cambiarle el nombre recrea en un reboot declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.Name",null, {value:"TR069-MNGMT-V1001"});
//declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.NATEnabled",null, {value:false});
log ("cambiando pasw user administrador");
declare("InternetGatewayDevice.User.*.*", {path: now}); // refrescar subtree)
declare("InternetGatewayDevice.User.1.Password", {value: now}, {value:"xxxxxxx"});
log ("pasw user admin cambiado")
log ("creando dhcp con vlan 1004 ");
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.[]", null, {path: 2});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.2.*", {path: now});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.2.AddressingType",null, {value:"DHCP"});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.2.ConnectionType",null, {value:"IP_Routed"});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.2.Enable",null, {value: true});
//luego de pruebas se bugeo declare queda desactivado ("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.2.NATEnabled",null, {value: true});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.2.Name",null, {value:"INTERNET-IPV4-V1004"});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.2.X_ZTE-COM_ServiceList",null, {value:"INTERNET"});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.2.X_ZTE-COM_VLANEnable",null, {value: true});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.2.X_ZTE-COM_VLANID",null, {value:"1004"});
log ("creando dhcp con vlan 1006 ");
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.[]", null, {path: 3});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.3.*", {path: now});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.3.AddressingType",null, {value:"DHCP"});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.3.ConnectionType",null, {value:"IP_Routed"});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.3.Enable",null, {value: true});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.3.Name",null, {value:"INTERNET-IPV6-V1006"});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.3.X_ZTE-COM_ServiceList",null, {value:"INTERNET"});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.3.X_ZTE-COM_8021P",null, {value:"1"});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.3.X_ZTE-COM_IPMode",null,	{value: "IPv6"});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.3.X_ZTE-COM_Dhcpv6IAPDEnable",null, {value:true});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.3.X_ZTE-COM_Dhcpv6IANAEnable",null, {value:true});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.3.X_ZTE-COM_VLANEnable",null, {value: true});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.3.X_ZTE-COM_VLANID",null, {value:"1006"});

This will delete a specific instance:

declare('InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.[X_ZTE-COM_VLANID:103]', null, {path: 0});

Now to explain what is going wrong with your script.

declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.[]", null, {path: 3});

This causes GenieACS to delete all but 3 instances. Which may appear on the surface to be what you want. But if you don’t supply the parameters for all 3 instances, I’m not sure what Genie would do, but the answer probably is ‘not what you want.’

If I were to guess based on what you have, this is probably what you want:

const params = [
    {
        AddressingType: "DHCP",
        ConnectionType: "IP_Routed",
        Enable: true,
        Name: "INTERNET-IPV4-V1004",
        "X_ZTE-COM_ServiceList": "INTERNET",
        "X_ZTE-COM_VLANEnable": true,
        "X_ZTE-COM_VLANID": 1004
    },
    {
        AddressingType: "DHCP",
        ConnectionType: "IP_Routed",
        Enable: true,
        Name: "INTERNET-IPV6-V1006",
        "X_ZTE-COM_ServiceList": "INTERNET",
        "X_ZTE-COM_8021P": "1",
        "X_ZTE-COM_IPMode": "IPv6",
        "X_ZTE-COM_Dhcpv6IAPDEnable": true,
        "X_ZTE-COM_Dhcpv6IANAEnable": true,
        "X_ZTE-COM_VLANEnable": true,
        "X_ZTE-COM_VLANID": 1006,
    }
];

const basePath = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection";

/*
 * Delete all instances. No changes are made until after the end of the script
 * when GenieACS builds the delta between the cached state and the desired state.
 * Which means this will realistically only execute on the CPE 1 one time, the initial time.
 * So there is no need to worry about unnecessary network traffic/churn on the CPE flash memory.
 */
declare(basePath + '.[]', null, {path: 0});

for (let param of params) {
    const path = basePath + '.[' + Object.keys(param).map(key => `${key}:${param[key]}`).join(',') + ']';

    log(`\r\n\r\nWANIPConnection - Updating - ${path}\r\n\r\n`, param);

    // Add back each desired instance
    declare(path, {path: 1}, {path: 1});
}

You mentioned an issue with X_ZTE- above, if I understand the issue correctly and my script doesn’t work due to the same issue, replace the equivalent line above with this (untested) modification:

    const path = basePath + '.[' + Object.keys(param).map(key => `'${key}':'${param[key]}'`).join(',') + ']';
1 Like

Thank you very much, akcoder.
I think you hit the nail on the head. With the new method for passing parameters, I had a problem with the ZTE subvalues ​​and the “-”. Now I’m going to try this method again.

Surprisingly, the original script I had was quite functional. If the ONU was without any configuration, it left all three WANs correctly configured. TR069 was sent via IPhost from the OLT, and from there, parameter 43 was sent to reconfigure the other two VLANs (1004 and 1006). However, if it was a ONU recovered or removed from an old client that had the old VLAN 104, it deleted WAN TR069 and received the other two (1004 and 1006), and additionally retained VLAN 104.

Well, I was able to try the improved version of the script

Edited
It works correctly but deletes the first WAN (tr069 ) received by OMCI

The instance is being deleted because params aren’t provided. Modify the const params = [... block to add params that match the instance being deleted. You don’t need to provide every param, just a name param should be fine.