MKH
MKH

Reputation: 1

How can I send a request to the Apache2.4 loadbalancer to disable/Enable/Drain a worker using python?

I have Apache2.4 on windows. I would like to be able to enable, disable, or drain each worker whenever I want. I cannot change the config file and restart the load balancer, since the load balancer should never stop processing the stream of requests. I want to do this task using python.

I have copied the nonce code from html response. The runs and prints the worker status changed but I cannot see any changes in the loadbalancer page or services window.

# Define the base URL for the balancer manager
base_url = "https://x.com/balancer-manager"
response = requests.get(base_url)
if response.status_code == 200:
    html = response.text

    # Extracted parameters from the provided HTML
    balancer = "mybalancerName"
    worker =  "https://x.com:8445//Invoke"

    nonce = "wbfcb4f6-fe6b-104f-35d3-945c1h856443"

    # Construct the URL to change the worker's status to "Init Drn Ok"
    url = "{}?b={}&w={}&nonce={}&dw=drain".format(base_url, balancer, worker, nonce)

    # Sending the GET request to change the status without any headers
    response = requests.get(url, verify=True)
    
    # Check the response
    if response.status_code == 200:
        print("Worker status changed to 'Init Drn Ok' successfully.")
    else:
        print("Failed to change status. HTTP status code: ")
        print(response.text)
    
else:

    print("Failed to access balancer manager: {}".format(response.status_code))

Upvotes: 0

Views: 29

Answers (0)

Related Questions