########################################################################### # CLOUD SERVER API DOCUMENTATION # # Name: reconfigureLoadBalancer # Language: Python # # Description: this function changes the features of load balancers ########################################################################### from urllib.request import Request, urlopen import urllib import json #ID access to API TOKEN = "{YOUR_API_TOKEN}" # e.g.: "f03c3c76cc853ee690b879909c9c6f2a" url = "https://cloudpanel-api.ionos.com/v1" def _reconfigureLoadBalancer(id, content): #Configure the request _command = url + "/load_balancers/" + id _method = 'PUT' request = Request(_command, data=content.encode(encoding='utf_8'), headers={'X-TOKEN':TOKEN, 'content-type':'application/json'}, method=_method) #Try to get the response try: response = urlopen(request) content = response.read() return (content.decode()) #Fetch error except urllib.error.URLError as e: return("Error " + str(e.code) + ":" + e.reason) #PARAMETERS id = "{YOUR_BALANCER_ID}" # e.g.: "5340033E7FBBC308BC329414A0DF3C20" name = 'My load balancer api rename' description = 'My load balancer api rename description' health_check_test = 'TCP' health_check_interval = 20 persistence = False persistence_time = 1000 method = 'LEAST_CONNECTIONS' data = json.dumps({'name':name, 'description':description, 'health_check_test': health_check_test, 'health_check_interval':health_check_interval, 'persistence':persistence, 'persistence_time':persistence_time, 'method':method}) #Rename load balancer print(_reconfigureLoadBalancer(id, data))