Working with objects using the API

Adding/removing objects via the API is going to be fraught with issues as there is no guarantee of what id the CPE will assign to an instance. It is possible to figure this out, you will have to add the instance. Then refreshing the param. Then try to determine what the id is of the new instance. For some items where you will only have one item, its pretty straight forward.

I find its far easier to manage this by either pre-configuring the CPE with the exact number of instances there can be, and then enabling/disabling the instance instead of deleting it. And because the CPE is preconfigured with all the instances needed, I know the exact instance ID. For example, our DSL CPEs can be configured in routed or bridged mode. They com preconfigured with a pppoe instance for every WAN interface. And also with a bridged instance, with a status of disabled. When a CM wants the CPE in bridged mode, its a simple matter to disable PPP and enable the bridged interface.

For other things, this isn’t possible. We allow customers to create an arbitrary number of port forwarding instances. Managing this via the API would be fraught with peril. So the way I handle this is via a tag called UpdatePortForwards. When that tag is set, a provision script fires off that queries our subscriber management platform for the port forwards for the CM. Then its a simple matter of telling GenieACS that there should be 0 instances of the port forwards, except for the ones. Here is part of the script I use to manage port forwards:

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});
        }
    }
}
1 Like