Skip to content
Snippets Groups Projects
Commit b0324b2c authored by sguazt's avatar sguazt
Browse files

Ditto

parent ece1de8d
No related branches found
No related tags found
No related merge requests found
from botocore.exceptions import WaiterError
from easycloud.core.metaconfmanager import MetaConfManager
import math
class AWSBaseConfManager(MetaConfManager):
......@@ -34,3 +36,38 @@ class AWSBaseConfManager(MetaConfManager):
# Filters (for images, Amazon has 30.000+ images available)
self.images_filters = self.parser.get(
"filters", "images_filters").replace(" ", "").replace("\n", "").split(",")
class AWSEC2Utils:
@staticmethod
def wait_for_instance_operation(client, operation, instances, timeout=None):
""" Wait for the given operation to complete.
Args:
client (boto.EC2.Client) the AWS EC2 client.
operation (str): the operation to wait for (e.g., 'instance_running').
instances (list): the list of instance IDs.
timeout (float): an optional value representing the max number of
seconds to wait for; if None, no timeout is enforced.
See:
- https://boto3.amazonaws.com/v1/documentation/api/latest/guide/clients.html
- https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#waiters
"""
waiter = client.get_waiter(operation)
if timeout is not None:
delay = 5
waiter_config = {'Delay': delay, 'MaxAttempts': math.ceil(timeout/delay)}
ret = True
check = True
while check:
try:
if timeout is None:
waiter.wait(InstanceIds = instances)
else:
waiter.wait(InstanceIds = instances, WaiterConfig = waiter_config)
check = False
except WaiterError:
if timeout is not None:
check = False
ret = False
return ret
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment