How to use describe_import_image_tasks method in localstack

Best Python code snippet using localstack_python

importImage.py

Source:importImage.py Github

copy

Full Screen

...38import_id=import_output['ImportTaskId']39logging.info('[%s] Import started. TaskId: %s', s3key, import_id)40client = boto3.client('ec2')41print "Waiting for import task to finish"42while client.describe_import_image_tasks(DryRun=False,ImportTaskIds=[import_id,])['ImportImageTasks'][0]['Status'] == 'active':43 sleep(SLEEP_TIME)44# try:45# sys.stdout.write("\rProgress: %s" % client.describe_import_image_tasks(DryRun=False,ImportTaskIds=[import_id,])['ImportImageTasks'][0]['Progress'])46# sys.stdout.flush()47# except KeyError:48if client.describe_import_image_tasks(DryRun=False,ImportTaskIds=[import_id,])['ImportImageTasks'][0]['Status'] == 'completed':49 ami_id=client.describe_import_image_tasks(DryRun=False,ImportTaskIds=[import_id,])['ImportImageTasks'][0]['ImageId']50 logging.info('[%s] Import successfull. New AMI id: %s', s3key, ami_id)51 print "Import task "+import_id+" have successfully created AMI "+ami_id+". Proceeding ...\n"52else:53 print "Import task "+import_id+" FAILED. Exiting ...\n"54 status_message=client.describe_import_image_tasks(DryRun=False,ImportTaskIds=[import_id,])['ImportImageTasks'][0]['StatusMessage']55 logging.error('[%s] Import failed. Reason: %s',s3key, status_message)56 sys.exit()57# load AMI object58ec2_resource=boto3.resource('ec2')59image=ec2_resource.Image(ami_id)60#print "Setting Name tag for new AMI"61currDate=strftime("%Y%m%d-%H:%M:%S")62image.create_tags(DryRun=False,Tags=[{'Key': 'Name', 'Value': s3key}, {'Key' : 'Created', 'Value' : currDate}])63logging.debug('[%s] Setting \'Name\' and \'Created\' tag for new AMI', s3key)64# run instance from ami65ec2_client=boto3.client('ec2')66response=ec2_client.run_instances(ImageId=ami_id,MinCount=1,MaxCount=1,SubnetId=subnet_id,InstanceType=instance_type,PrivateIpAddress=ip_addr)67instance_id=response['Instances'][0]['InstanceId']68logging.info('[%s] Starting new instance (%s)',s3key, instance_id)...

Full Screen

Full Screen

transport.py

Source:transport.py Github

copy

Full Screen

...45def list_export_task(request):46 response = ec2_client(request).describe_export_tasks()47 return to_wrapping_list(response, "ExportTasks", ExportTask)48def list_import_image_task(request):49 response = ec2_client(request).describe_import_image_tasks()50 return to_wrapping_list(response, "ImportImageTasks", ImportTask)51def get_export_task(request, task_id):52 response = ec2_client(request).describe_export_tasks(ExportTaskIds=[task_id])53 return ExportTask(response.get("ExportTasks")[0])54def get_import_image_task(request, task_id):55 response = ec2_client(request).describe_import_image_tasks(ImportTaskIds=[task_id])56 return ImportTask(response.get('ImportImageTasks')[0])57def cancel_export_task(request, task_id):58 ec2_client(request).cancel_export_task(ExportTaskIds=[task_id])59def cancel_import_task(request, task_id):...

Full Screen

Full Screen

ec2orchestrator.py

Source:ec2orchestrator.py Github

copy

Full Screen

...20 DiskContainers = self.disk_containers)21 return response['ImportTaskId']22 def monitor_import_task(self, taskId):23 while True:24 response = self.ec2client.describe_import_image_tasks(ImportTaskIds=[taskId])25 for task in response['ImportImageTasks']:26 if task['ImportTaskId'] == taskId:27 if 'ImageId' in task.keys():28 self.imageid = task['ImageId']29 print "Image ID : " + self.imageid30 if task['Status'] in ['active', 'converting', 'updating']:31 print "Import in Progress. Progress : " + task['Progress'] + "% Completed."32 sleep(40)33 elif task['Status'] in ['deleted', 'deleting']:34 print "Import Cancelled. Error! Retry"35 return None36 elif task['Status'] == 'completed':37 print "AMI Ready to Launch Instance. Image ID : " + self.imageid38 return self.imageid

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful