How to use describe_capacity_reservations method in localstack

Best Python code snippet using localstack_python

index.py

Source:index.py Github

copy

Full Screen

...19 if tag['Key'] == "AutoCapacityReservationId":20 instance_capacity_reservation_id = tag['Value']21 if event['detail']['state'] == "pending":22 if not instance_capacity_reservation_id:23 capacity_reservations = client.describe_capacity_reservations(24 Filters=[25 {26 'Name': 'state',27 'Values': [28 'active',29 ]30 },31 {32 'Name': 'availability-zone',33 'Values': [34 instance['Placement']['AvailabilityZone'],35 ]36 },37 {38 'Name': 'tag:Platform',39 'Values': [40 platform,41 ]42 },43 {44 'Name': 'instance-type',45 'Values': [46 instance['InstanceType'],47 ]48 },49 {50 'Name': 'tenancy',51 'Values': [52 instance['Placement']['Tenancy'],53 ]54 },55 {56 'Name': 'tag-key',57 'Values': [58 'AutoCapacityReservation',59 ]60 },61 ]62 )['CapacityReservations']63 capacity_reservation_id = None64 if len(capacity_reservations) > 0:65 print("Incrementing capacity reservation: {}".format(capacity_reservations[0]['CapacityReservationId']))66 client.modify_capacity_reservation(67 CapacityReservationId=capacity_reservations[0]['CapacityReservationId'],68 InstanceCount=capacity_reservations[0]['TotalInstanceCount'] + 1,69 )70 capacity_reservation_id = capacity_reservations[0]['CapacityReservationId']71 else:72 print("Creating capacity reservation")73 capacity_reservation = client.create_capacity_reservation(74 ClientToken=str(random.random())[2:],75 InstanceType=instance['InstanceType'],76 InstancePlatform=platform,77 AvailabilityZone=instance['Placement']['AvailabilityZone'],78 Tenancy=instance['Placement']['Tenancy'],79 InstanceCount=1,80 EndDateType='unlimited',81 InstanceMatchCriteria='open',82 TagSpecifications=[83 {84 'ResourceType': 'capacity-reservation',85 'Tags': [86 {87 'Key': 'AutoCapacityReservation',88 'Value': 'true'89 },90 {91 'Key': 'Platform',92 'Value': platform93 },94 ]95 },96 ]97 )['CapacityReservation']98 capacity_reservation_id = capacity_reservation['CapacityReservationId']99 client.create_tags(100 Resources=[101 instanceid,102 ],103 Tags=[104 {105 'Key': 'AutoCapacityReservationId',106 'Value': capacity_reservation_id107 },108 ]109 )110 elif event['detail']['state'] == "terminated":111 if instance_capacity_reservation_id:112 capacity_reservations = client.describe_capacity_reservations(113 Filters=[114 {115 'Name': 'state',116 'Values': [117 'active',118 ]119 },120 {121 'Name': 'availability-zone',122 'Values': [123 instance['Placement']['AvailabilityZone'],124 ]125 },126 {...

Full Screen

Full Screen

a.py

Source:a.py Github

copy

Full Screen

...129130131def get_reservations(client, instance_type):132 133 response = client.describe_capacity_reservations(Filters=[134 {135 'Name': 'state',136 'Values': [137 'active',138 ]139 },140 {141 'Name': 'instance-type',142 'Values': [143 instance_type,144 ]145 },146 ]147 ...

Full Screen

Full Screen

cancelODCR.py

Source:cancelODCR.py Github

copy

Full Screen

...45 }46 )47 client = boto3.client('ec2', config=my_config)48 try: 49 response = client.describe_capacity_reservations(50 CapacityReservationIds=[51 CapacityReservationId,52 ],53 )54 if response['CapacityReservations'][0]['State'] != 'active':55 print ("The state of the Capacity reservation/{} is {}. To cancel Capacity Reservation, please ensure that the state of the Capacity Reservation is active".format(CapacityReservationId, response['CapacityReservations'][0]['State']))56 sys.exit()57 except ParamValidationError as err:58 print ("Invalid Capacity Reservation ID")59 sys.exit()60 except ClientError as err:61 if (err.response['Error']['Code'] == 'InvalidCapacityReservationId.NotFound'):62 pass63 else: ...

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