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

AWS: added class to use for implementing synchronized operations (e.g., for...

AWS: added class to use for implementing synchronized operations (e.g., for waiting until the starting of an instance is done)
parent fcf824b4
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ EasyCloud Amazon Web Services Manager
"""
import boto3
#from easycloud.common.aws import AWSEC2Utils
from easycloud.core.compute import Instance, InstanceStatus
from easycloud.core.actionbinder import bind_action
from easycloud.core.metamanager import MetaManager
......@@ -93,12 +94,30 @@ class AWSInstance(Instance):
def start(self):
self._ec2_conn.start_instances(InstanceIds=[self._ec2_inst['InstanceId']]) #, DryRun=True)
#TODO: call "AWSEC2Utils.wait_for_operation(self._ec_conn, 'instance_running', [self._ec2_inst['InstanceId'])" to perform a synchronous version of this method
return True # Boto3 will raise an exception if an operation fails (see: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/error-handling.html)
def stop(self):
self._ec2_conn.stop_instances(InstanceIds=[self._ec2_inst['InstanceId']]) #, DryRun=True)
#TODO: call "AWSEC2Utils.wait_for_operation(self._ec_conn, 'instance_running', [self._ec2_inst['InstanceId'])" to perform a synchronous version of this method
return True # Boto3 will raise an exception if an operation fails (see: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/error-handling.html)
def _wait_for_operation(self, op):
""" Wait for the given operation to complete.
Args:
operation (str): the operation Id to wait for.
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
"""
# 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 = self.ec2_client.get_waiter(op)
waiter.wait(Filters=[
{'Name': 'instance-id', 'Values': [each_instance.instance_id]}])
d
# For a list of valid filters to use with the ex_filter parameter of certain methods,
# please visit https://docs.aws.amazon.com/en_us/AWSEC2/latest/APIReference/API_Operations.html
......
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