How to ensure only specific instances exist?

Zaid Abdulla zaid at genieacs.com
Fri Jun 16 19:18:11 EDT 2017


On Thu, 2017-06-15 at 09:41 -0800, Dan Morphis wrote:
> We are adding the ability for customers to manage port forwarding
> (PortMapping). I'm trying to figure out how to ensure that only
> specific instances exist in the PortMapping node. For instance
> customer adds a port forward for
> ExternalPort:3000,InternalPort:3001,PortMappingProtocol:TCP,InternalC
> lient:192.168.1.50. Creating that instance will be easy enough.
> 
> Now, the customer remove that instance, and adds a mapping for
> ExternalPort:8080,InternalPort:80,PortMappingProtocol:TCP,InternalCli
> ent:192.168.1.51,
> ExternalPort:8081,InternalPort:80,PortMappingProtocol:TCP,InternalCli
> ent:192.168.1.50. How can I using provisioning scripts ensure that
> the first instance is deleted, and the second instance is created, if
> the only data I have available is what the desired state should be?

If I understand you correctly, you can do something like this:

declare("InternetGatewayDevice.WANDevice.*.WANConnectionDevice.1.WANPPP
Connection.*.PortMapping.[]", null, {path: 0});

declare("InternetGatewayDevice.WANDevice.*.WANConnectionDevice.1.WANPPP
Connection.*.PortMapping.[ExternalPort:8080,InternalPort:80,PortMapping
Protocol:TCP,InternalClient:192.168.1.51]", {path: 1}, {path: 1});

declare("InternetGatewayDevice.WANDevice.*.WANConnectionDevice.1.WANPPP
Connection.*.PortMapping.[ExternalPort:8081,InternalPort:80,PortMapping
Protocol:TCP,InternalClient:192.168.1.50]", {path: 1}, {path: 1});

This will cause all instances other than those two to be deleted. And
since there's no commit() between the declarations, it knows not to
delete and recreate said instances.

-- 
Zaid Abdulla <zaid at genieacs.com>


More information about the Users mailing list