update to not require a 'load balancer' section
This commit is contained in:
parent
a21d71cb62
commit
3b677cd582
@ -187,26 +187,28 @@ def commitRecord(ip):
|
|||||||
|
|
||||||
|
|
||||||
def updateLoadBalancer(ip):
|
def updateLoadBalancer(ip):
|
||||||
|
try:
|
||||||
|
for option in config["load_balancer"]:
|
||||||
|
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'])
|
||||||
|
|
||||||
for option in config["load_balancer"]:
|
origins = pools['result'][idx]['origins']
|
||||||
pools = cf_api('user/load_balancers/pools', 'GET', option)
|
|
||||||
|
|
||||||
if pools:
|
idxr = dict((o['name'], i) for i, o in enumerate(origins))
|
||||||
name = option['origin']
|
idx = idxr.get(option['origin'])
|
||||||
idxr = dict((p['id'], i) for i, p in enumerate(pools['result']))
|
|
||||||
idx = idxr.get(option['pool_id'])
|
|
||||||
|
|
||||||
origins = pools['result'][idx]['origins']
|
if origins[idx]['address'] != ip['ip']:
|
||||||
|
origins[idx]['address'] = ip['ip']
|
||||||
|
data = {'origins': origins}
|
||||||
|
|
||||||
idxr = dict((o['name'], i) for i, o in enumerate(origins))
|
print("📡 Updating LB Pool: " + name)
|
||||||
idx = idxr.get(option['origin'])
|
response = cf_api(f'user/load_balancers/pools/{option["pool_id"]}', 'PATCH', option, {}, data)
|
||||||
|
except:
|
||||||
if origins[idx]['address'] != ip['ip']:
|
print("No load balancer section found")
|
||||||
origins[idx]['address'] = ip['ip']
|
|
||||||
data = {'origins': origins}
|
|
||||||
|
|
||||||
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):
|
def cf_api(endpoint, method, config, headers={}, data=False):
|
||||||
|
|||||||
Reference in New Issue
Block a user