Best Python code snippet using localstack_python
modifyODCR.py
Source: modifyODCR.py
...140# InstanceCount (integer) -- The number of instances for which to reserve capacity. The number of instances can't be increased or decreased by more than 1000 in a single request.141def modifyODCR(region):142 modify = boto3.client('ec2',region_name=region)143 if EndDateType == 'limited':144 ModifyODCR = modify.modify_capacity_reservation(145 CapacityReservationId=CapacityReservationId,146 InstanceCount= int(InstanceCount),147 EndDate=EndDate,148 EndDateType=EndDateType,149 DryRun=False150 )151 else:152 ModifyODCR = modify.modify_capacity_reservation(153 CapacityReservationId=CapacityReservationId,154 InstanceCount= int(InstanceCount),155 EndDateType=EndDateType,156 DryRun=False157 )158 return ModifyODCR['Return']159160def main():161 region = describeCapacityReservationRegion()162 if modifyODCR(region):163 print ("Capacity Modification request succeeds")164 else:165 print ("Capacity Modification request does not succeed")166
...
index.py
Source: index.py
...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 {127 'Name': 'tag:Platform',128 'Values': [129 platform,130 ]131 },132 {133 'Name': 'instance-type',134 'Values': [135 instance['InstanceType'],136 ]137 },138 {139 'Name': 'tenancy',140 'Values': [141 instance['Placement']['Tenancy'],142 ]143 },144 {145 'Name': 'tag-key',146 'Values': [147 'AutoCapacityReservation',148 ]149 },150 ]151 )['CapacityReservations']152 if len(capacity_reservations) > 0 and capacity_reservations[0]['CapacityReservationId'] == instance_capacity_reservation_id:153 if capacity_reservations[0]['TotalInstanceCount'] <= 1:154 print("Cancelling capacity reservation: {}".format(capacity_reservations[0]['CapacityReservationId']))155 client.cancel_capacity_reservation(156 CapacityReservationId=capacity_reservations[0]['CapacityReservationId']157 )158 else:159 print("Decrementing capacity reservation: {}".format(capacity_reservations[0]['CapacityReservationId']))160 client.modify_capacity_reservation(161 CapacityReservationId=capacity_reservations[0]['CapacityReservationId'],162 InstanceCount=capacity_reservations[0]['TotalInstanceCount'] - 1,163 )164 else:...
a.py
Source: a.py
...53 elif get_reservation:54 for reservation in get_reservation['CapacityReservations']:55 cancel_reservations.remove(reservation['CapacityReservationId'])56 print("It is here")57 # modify_capacity_reservation(client, reservation['TotalInstanceCount'], 20, reservation['CapacityReservationId'])58 modify_capacity_reservation(client, reservation['TotalInstanceCount'], reservation['AvailableInstanceCount'], reservation['CapacityReservationId'])59 60 else:61 get_reservation = get_reservations(client, instances['InstanceType'])62 if get_reservation:63 for reservation in get_reservation['CapacityReservations']:64 if(reservation['CapacityReservationId'] not in cancel_reservations):65 cancel_reservations.append(reservation['CapacityReservationId'])66 67 68 for reservations in get_instances['Reservations']:69 #Cancel Cpacity Reservation for stopped instance types70 for instances in reservations['Instances']: 71 get_reservation = get_reservations(client, instances['InstanceType'])72 if get_reservation:73 for reservation in cancel_reservations:74 cancel_reservation(client, reservation)75 76 if running_instances == False:77 print('No Running Instances found!')78798081def cancel_reservation(client, reservation_id):82 response = client.cancel_capacity_reservation(83 CapacityReservationId=reservation_id84 )85 return response86 878889def modify_capacity_reservation(ec2_client, total_count, available_count, reservation_id):90 print ("Invoked!")91 default_count = config.default_count92 capacity_chg_percentage = config.capacity_chg_percentage93 94 #Calculate 20% capacity of total capacity95 capacity_percentage = int((config.capacity_chg_percentage / 100 * total_count))96 #Calculate available capacity percentage97 available_percentage = int((available_count / total_count * 100))98 99 print (capacity_percentage)100 print (available_percentage)101102 #If capacity is less than 0 for example total count is low like 2 then round103 #the value to 1104 if (capacity_percentage == 0):105 capacity_percentage = 1106 elif (available_percentage == 0):107 available_percentage = 1108 109 #Increment 20% Capacity110 if (available_percentage <= capacity_chg_percentage):111 new_count = total_count + capacity_percentage112 113 #Decrement 20% Capacity114 elif (available_percentage > capacity_chg_percentage and total_count > default_count):115 new_count = total_count -capacity_percentage116 117 else:118 #Else don't change capacity119 new_count = total_count120 121 122 print (new_count)123 modify = ec2_client.modify_capacity_reservation(124 CapacityReservationId=reservation_id,125 InstanceCount=new_count126 )127 128129130131def get_reservations(client, instance_type):132 133 response = client.describe_capacity_reservations(Filters=[134 {135 'Name': 'state',136 'Values': [137 'active',
...
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!