Best Python code snippet using localstack_python
convertVolumesToGP3.py
Source:convertVolumesToGP3.py
...34 self.number_of_volumes_still_in_progress35 36 def run( self ):37 # run until all volumes have been modified. use counter to check on status 38 # volume_modification_progress = ec2_client.describe_volumes_modifications() 39# todo create volume modification progress thread which is separate from the modification itself40# wait for a producer to run describe volume status on all volumes41class monitor_volume_modification_progress ( Thread ):42 def __init__( self, volume_id, modification_in_progress ):43 Thread.__init__(self)44 self.volume_id = volume_id45 self.modification_in_progress = modification_in_progress46 47 def run( self ):48 self.modification_in_progress.wait()49 volume_modification_progress = ec2_client.describe_volumes_modifications(50 VolumeIds=[self.volume_id]51 )["VolumesModifications"][0]["Progress"]52 53 while volume_modification_progress != 100:54 time.sleep(10)55 volume_modification_progress = ec2_client.describe_volumes_modifications(56 VolumeIds=[self.volume_id]57 )["VolumesModifications"][0]["Progress"]58 print('{:%Y-%m-%d %H:%M:%S} UTC'.format(datetime.datetime.now()))59 print(f"Volume modification progress for {self.volume_id} at {volume_modification_progress}")60ec2_client = boto3.client('ec2', region_name='us-west-2')61with open('gp3_change_set', mode='r') as filehandle:62 volumes_to_change = json.load(filehandle)63 filehandle.close()64for volume_info in volumes_to_change:65 print(f"Modifying {volume_info[0]} from " + 66 f"[{volume_info[1]} iops and {volume_info[2]} thoughput] " +67 f"to [{volume_info[3]} iops and {volume_info[4]} throughput]")68if not input("Are you sure these are the changes you want? (y/n): ").lower().strip()[:1] == "y": sys.exit(1)69# only allow 10 simultaneous modify volume requests at a time ...
modify_volume.py
Source:modify_volume.py
...31 instance_id32 ]33 )34 volume_id = volume['Reservations'][0]['Instances'][0]['BlockDeviceMappings'][0]['Ebs']['VolumeId']35 response = client.describe_volumes_modifications(36 VolumeIds=[37 volume_id38 ]39 )40 while True:41 time.sleep(45)42 logger.info(f'Volume state...\n{json.dumps(response["VolumesModifications"][0]["ModificationState"], default=json_datetime_serializer, indent=4)}')43 response = client.describe_volumes_modifications(44 VolumeIds=[45 volume_id46 ]47 )48 volume_modification_state = response['VolumesModifications'][0]['ModificationState']49 50 if volume_modification_state == 'optimizing':51 logger.info('Volume is being optimized...')52 elif volume_modification_state == 'completed':53 logger.info('Volume has been optimized...')54 break55 else:56 logger.info('Volume is being modified...')57modify_volume = check_modification_state(modify_volumes('i-0f606e1b556bc9a57'))...
describe_volume_using_volume_id.py
Source:describe_volume_using_volume_id.py
...25 )26 return response27def check_modification_state(volume_id):28 client = boto3.client('ec2')29 response = client.describe_volumes_modifications(30 VolumeIds=[31 volume_id32 ]33 )34 while response['VolumesModifications'][0]['ModificationState'] == 'modifying':35 time.sleep(1)36 response = client.describe_volumes_modifications(37 VolumeIds=[38 volume_id39 ]40 )41 if response['VolumesModifications'][0]['ModificationState'] == 'optimizing':42 logger.info('Volume is being optimized...')43 elif response['VolumesModifications'][0]['ModificationState'] == 'completed':44 logger.info('Volume has been optimized...')45 break46 else:47 logger.info('Volume is being modified...')48 return response['VolumesModifications'][0]['ModificationState']49volume_info = describe_volume()50modify_volume = modify_volumes(volume_info['VolumeId'])...
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!!