Sleep python script execution until process completes

3/3/2019

I know this question has been asked prior, but I found no answer that addressed by particular problem.

I have a Python script to create kubernetes clusters and nodes in Azure, which takes anywhere between 5-10 mins. There's a function(get_cluster_end) to get the cluster endpoint, but this fails as the endpoint is not yet ready when this function is call. The func I wrote(wait_for_end)does not seem to be correct.

def wait_for_endpoint(timeout=None):
    endpoint = None
    start = time.time()
        while not endpoint:
        if timeout is not None and (time.time() - start > timeout):
            break
        endpoint = **get_cluster_end()**
        time.sleep(5)
    return endpoint

My main func:

def main():
    create_cluster()
       start = time.time()
       job.set_progress("Waiting for cluster IP address...")
       endpoint = wait_for_endpoint(timeout=TIMEOUT)
       if not endpoint:
          return ("FAILURE","No IP address returned after {} seconds".format(TIMEOUT),
               "")

The script fails, because no endpoint has yet been created. How do I set the sleep after the cluster has been created and before the "wait_for_endpoint()" is called?

-- ghenzi83
azure
azure-aks
kubernetes
python
sleep

0 Answers