Created
August 11, 2016 00:52
-
-
Save kozikow/71a60414f6472bf029b831959235d2c8 to your computer and use it in GitHub Desktop.
Awaint instances ready in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def await_instances_ready(instances: List[str]): | |
""" | |
Block until all instances in the list become ready. | |
Args: | |
instances: List of instances external IPs. | |
Raises: | |
Exception: If we do not own given external IPs. | |
""" | |
while True: | |
df = get_instances_df() | |
df = df[df.external_ip.isin(instances)] | |
if len(df) != len(instances): | |
missing_instances = set(instances).difference(set(df.external_ip)) | |
raise Exception( | |
"Request to await non-existent instances {}".format( | |
missing_instances)) | |
not_ready = df[df.status != "RUNNING"] | |
if len(not_ready) > 0: | |
logger.info( | |
"Awaiting ready instances. {} not ready yet".format(not_ready)) | |
time.sleep(2) | |
else: | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment