
. /opt/control.setloki/library/celery.sh

if [ -n "${reason}" ]; then
    case "$reason" in
     BOUND)
        # here we need to check if new ip address is set otherwise ignore.
        if [ -n "${new_ip_address}" ]; then
            # just the new ip has been provided so it is assumed to be unique.
            kwargs=$(generate_celery_kwargs "network.wan_update" '{"interface": "'"${interface}"'", "ip": "'"${new_ip_address}"'", "netmask": "'"${new_subnet_mask}"'", "gateway": "'"${new_routers}"'"}')
            /opt/venv3/bin/celery --workdir "/opt/control.setloki" -A tasks.task_manager call network.wan_update -k "$kwargs"
        fi
     ;;
     RENEW|REBIND)
        # these calls are provided with new and old parameter sets.
        if [ -n "${new_ip_address}" ]; then
            if [ -n "${old_ip_address}" ]; then
                # an old ip is provided in data so we need to check for changes
                if [ "${old_ip_address}" != "${new_ip_address}" ]; then
                    kwargs=$(generate_celery_kwargs "network.wan_update" '{"interface": "'"${interface}"'", "ip": "'"${new_ip_address}"'", "netmask": "'"${new_subnet_mask}"'", "gateway": "'"${new_routers}"'"}')
                    /opt/venv3/bin/celery --workdir "/opt/control.setloki" -A tasks.task_manager call network.wan_update -k "$kwargs"
                fi
            else
                # just the new ip has been provided so it is assumed to be unique.
                kwargs=$(generate_celery_kwargs "network.wan_update" '{"interface": "'"${interface}"'", "ip": "'"${new_ip_address}"'", "netmask": "'"${new_subnet_mask}"'", "gateway": "'"${new_routers}"'"}')
                /opt/venv3/bin/celery --workdir "/opt/control.setloki" -A tasks.task_manager call network.wan_update -k "$kwargs"
            fi
        fi
     ;;
    esac
fi