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)
|
pools = cf_api('user/load_balancers/pools', 'GET', option)
|
||||||
|
|
||||||
if pools:
|
if pools:
|
||||||
|
name = option['origin']
|
||||||
idxr = dict((p['id'], i) for i, p in enumerate(pools['result']))
|
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']
|
origins = pools['result'][idx]['origins']
|
||||||
|
|
||||||
idxr = dict((o['name'], i) for i, o in enumerate(origins))
|
idxr = dict((o['name'], i) for i, o in enumerate(origins))
|
||||||
idx = idxr.get(option['origin'])
|
idx = idxr.get(option['origin'])
|
||||||
|
|
||||||
origins[idx]['address'] = ip['ip']
|
if origins[idx]['address'] != ip['ip']:
|
||||||
data = {'origins': origins}
|
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):
|
def cf_api(endpoint, method, config, headers={}, data=False):
|
||||||
api_token = config['authentication']['api_token']
|
api_token = config['authentication']['api_token']
|
||||||
if api_token != '' and api_token != 'api_token_here':
|
if api_token != '':
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": "Bearer " + api_token, **headers
|
"Authorization": "Bearer " + api_token, **headers
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user