Problems Creating Instances from provisions

Hello everyone, I am struggling with creating instances through provision scripts. I have tried many many posts and solution that is present on this forum but I can not make it work. any help would be appreciated.

This is the last one I tried:

declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.PortMapping.[]", null, {path: 0});
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.PortMapping.[ExternalPort:555,ExternalPortEndRange:555,InternalClient:192.168.1.111,InternalPort:55,InternalPortEndRange:55,PortMappingDescription:test]", {path: now}, {path: 1});

On this I get too many commits error.

I also tried this:

let d = declare('InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.PortMapping.*', null, {path: 1});

for (let instance of d) {
    declare(instance.path + '.ExternalPort', null, {value: 555});
    declare(instance.path + '.ExternalPortEndRange', null, {value: 555});
    declare(instance.path + '.InternalClient', null, {value: '192.168.1.111'});
    declare(instance.path + '.InternalPort', null, {value: 55});
    declare(instance.path + '.InternalPortEndRange', null, {value: 55});
    declare(instance.path + '.PortMappingDescription', null, {value: 'test'});
}

I get internal error and invalid parameters error.

Either I get too many commits error or Invalid Parameters error and also the issue is that it is always starting from second instance and first one is not visible at all

Also it always starts with second instance not first and I dont understand why it happens like that.

I am using 1.2.8

this is what I do according to

https://docs.genieacs.com/en/latest/provisions.html#creating-deleting-object-instances

declare( "InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.AccessControlListEnable", {
        value: Date.now( )
    }, {
        value: true
    } );
    declare( "InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*", null, {
        path: 0
    } );

    var cadena;
    cadena = "InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.[";
    cadena += "Mode:0,";
    cadena += "Priority:1,";
    cadena += "ServicePort:\"TELNET,HTTP,SSH,FTP,ICMP,SAMBA\",";
    cadena += "SrcPortType:2,";
    cadena += "SrcPortName:InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1";
    cadena += "]";
    log( "cadena: " + cadena );

    declare( cadena, {
        path: Date.now()
    }, {
        path: 1
    } );

in this particular case it set ups CPE ACL over specific wan device index.

so that is like this approach

declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.PortMapping.[ExternalPort:555,ExternalPortEndRange:555,InternalClient:192.168.1.111,InternalPort:55,InternalPortEndRange:55,PortMappingDescription:test]", {path: now}, {path: 1});

and this throws too many commit iterations error

Try putting this line first:

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

This tells GenieACS to clear out any existing port mappings and just add the given one (if it doesn’t exist).

This is part of the script I use to manage port mappings. It takes in an array of objects. In production, this provision script makes a http call to our subscriber management server to get the values.

To call it, use something like this in your provision script:

const pf = [
    {
        ExternalPort:555,
        ExternalPortEndRange:555,
        InternalClient:"192.168.1.111",
        InternalPort:55,
        InternalPortEndRange:55,
        PortMappingDescription:"port forward 1 - 555"
    },
    {
        ExternalPort:8080,
        ExternalPortEndRange:8080,
        InternalClient:"192.168.1.111",
        InternalPort:80,
        InternalPortEndRange:80,
        PortMappingDescription:"port forward 2 - 8080"
    },
];

updatePortForwards(pf);

function updatePortForwards(portForwards)
{
    let keys = [
        'InternetGatewayDevice.WANDevice.*.WANConnectionDevice.*.WANPPPConnection.*.PortMapping',
        'Device.NAT.PortMapping'
    ];

    for (let basePath of keys) {
        declare(basePath + '.[]', null, {path: 0});

        for (let forward of portForwards) {
            const path = basePath + '.[' + Object.keys(forward).map(key => key + ':' + forward[key]).join(',') + ']';

            log(`\r\n\r\nPortForwards - Updating - ${path}\r\n\r\n`, forward);

            declare(path, {path: 1}, {path: 1});
        }
    }

    log('PortForwards - Done');
}