added functionality for loadBalancer
This commit is contained in:
parent
7c167c70b4
commit
c86f56c5b7
@ -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'])
|
||||
|
||||
if origins[idx]['address'] != ip['ip']:
|
||||
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):
|
||||
api_token = config['authentication']['api_token']
|
||||
if api_token != '' and api_token != 'api_token_here':
|
||||
if api_token != '':
|
||||
headers = {
|
||||
"Authorization": "Bearer " + api_token, **headers
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user