Here you are missing information, you may be adding a new service, which doesn't require to be the default, for a port that already has another service set as the  'default', however, your code is assuming that all additions will be set as the default service. Other than that, I think it's ok. Tomorrow I will reuse this with UserCorner. Captive portal is not using haproxy with 3.4 due a technical problem.