diff --git a/cloudflare-ddns.py b/cloudflare-ddns.py index 9820489..e1840cc 100755 --- a/cloudflare-ddns.py +++ b/cloudflare-ddns.py @@ -192,23 +192,26 @@ def updateLoadBalancer(ip): pools = cf_api('user/load_balancers/pools', 'GET', option) if pools: + name = option['origin'] idxr = dict((p['id'], i) for i, p in enumerate(pools['result'])) - idx = idxr.get(option['pool_id']) + idx = idxr.get(name) origins = pools['result'][idx]['origins'] idxr = dict((o['name'], i) for i, o in enumerate(origins)) idx = idxr.get(option['origin']) - origins[idx]['address'] = ip['ip'] - data = {'origins': origins} + if origins[idx]['address'] != ip['ip']: + origins[idx]['address'] = ip['ip'] + data = {'origins': origins} - response = cf_api(f'user/load_balancers/pools/{option["pool_id"]}', 'PATCH', option, {}, data) + print("📡 Updating LB Pool: " + name) + response = cf_api(f'user/load_balancers/pools/{option["pool_id"]}', 'PATCH', option, {}, data) def cf_api(endpoint, method, config, headers={}, data=False): api_token = config['authentication']['api_token'] - if api_token != '' and api_token != 'api_token_here': + if api_token != '': headers = { "Authorization": "Bearer " + api_token, **headers }