@@ -63,13 +63,11 @@ def stop_instance(
63
63
instance_types = pick_random_instance (filters , client )
64
64
65
65
if not instance_types :
66
- raise FailedActivity ("No instances in availability zone: {}" . format ( az ) )
66
+ raise FailedActivity (f "No instances in availability zone: { az } " )
67
67
else :
68
68
instance_types = get_instance_type_by_id ([instance_id ], client )
69
69
70
- logger .debug (
71
- "Picked EC2 instance '{}' from AZ '{}' to be stopped" .format (instance_types , az )
72
- )
70
+ logger .debug (f"Picked EC2 instance '{ instance_types } ' from AZ '{ az } ' to be stopped" )
73
71
74
72
return stop_instances_any_type (
75
73
instance_types = instance_types , force = force , client = client
@@ -113,7 +111,7 @@ def stop_instances(
113
111
instance_types = list_instances_by_type (filters , client )
114
112
115
113
if not instance_types :
116
- raise FailedActivity ("No instances in availability zone: {}" . format ( az ) )
114
+ raise FailedActivity (f "No instances in availability zone: { az } " )
117
115
else :
118
116
instance_types = get_instance_type_by_id (instance_ids , client )
119
117
@@ -228,7 +226,7 @@ def terminate_instances(
228
226
"No instances found matching filters: %s" % str (filters )
229
227
)
230
228
231
- logger .debug ("Instances in AZ %s selected: %s}." % ( az , str (instance_types )) )
229
+ logger .debug (f "Instances in AZ { az } selected: { str (instance_types )} }}." )
232
230
else :
233
231
instance_types = get_instance_type_by_id (instance_ids , client )
234
232
@@ -281,7 +279,7 @@ def start_instances(
281
279
"No instances found matching filters: %s" % str (filters )
282
280
)
283
281
284
- logger .debug ("Instances in AZ %s selected: %s}." % ( az , str (instance_types )) )
282
+ logger .debug (f "Instances in AZ { az } selected: { str (instance_types )} }}." )
285
283
else :
286
284
instance_types = get_instance_type_by_id (instance_ids , client )
287
285
return start_instances_any_type (instance_types , client )
@@ -333,7 +331,7 @@ def restart_instances(
333
331
"No instances found matching filters: %s" % str (filters )
334
332
)
335
333
336
- logger .debug ("Instances in AZ %s selected: %s}." % ( az , str (instance_types )) )
334
+ logger .debug (f "Instances in AZ { az } selected: { str (instance_types )} }}." )
337
335
else :
338
336
instance_types = get_instance_type_by_id (instance_ids , client )
339
337
return restart_instances_any_type (instance_types , client )
@@ -435,9 +433,9 @@ def list_instances_by_type(
435
433
Return all instance ids matching the given filters by type
436
434
(InstanceLifecycle) ie spot, on demand, etc.
437
435
"""
438
- logger .debug ("EC2 instances query: {}" . format ( str (filters )) )
436
+ logger .debug (f "EC2 instances query: { str (filters )} " )
439
437
res = client .describe_instances (Filters = filters )
440
- logger .debug ("Instances matching the filter query: {}" . format ( str (res )) )
438
+ logger .debug (f "Instances matching the filter query: { str (res )} " )
441
439
442
440
return get_instance_type_from_response (res )
443
441
@@ -601,7 +599,7 @@ def stop_instances_any_type(
601
599
client .describe_instances (InstanceIds = instance_types ["spot" ])
602
600
)
603
601
604
- logger .debug ("Canceling spot requests: {}" . format ( spot_request_ids ) )
602
+ logger .debug (f "Canceling spot requests: { spot_request_ids } " )
605
603
client .cancel_spot_instance_requests (SpotInstanceRequestIds = spot_request_ids )
606
604
logger .debug ("Terminating spot instances: {}" .format (instance_types ["spot" ]))
607
605
@@ -623,7 +621,7 @@ def terminate_instances_any_type(
623
621
response = []
624
622
625
623
for k , v in instance_types .items ():
626
- logger .debug ("Terminating %s instance(s): %s" % ( k , instance_types [k ]) )
624
+ logger .debug (f "Terminating { k } instance(s): { instance_types [k ]} " )
627
625
if k == "spot" :
628
626
instances = get_spot_request_ids_from_response (
629
627
client .describe_instances (InstanceIds = v )
@@ -644,7 +642,7 @@ def start_instances_any_type(
644
642
"""
645
643
results = []
646
644
for k , v in instance_types .items ():
647
- logger .debug ("Starting %s instance(s): %s" % ( k , v ) )
645
+ logger .debug (f "Starting { k } instance(s): { v } " )
648
646
response = client .start_instances (InstanceIds = v )
649
647
results .extend (response .get ("StartingInstances" , []))
650
648
return results
@@ -656,7 +654,7 @@ def restart_instances_any_type(instance_types: dict, client: boto3.client):
656
654
"""
657
655
results = []
658
656
for k , v in instance_types .items ():
659
- logger .debug ("Restarting %s instance(s): %s" % ( k , v ) )
657
+ logger .debug (f "Restarting { k } instance(s): { v } " )
660
658
client .reboot_instances (InstanceIds = v )
661
659
return results
662
660
@@ -712,7 +710,7 @@ def attach_instance_volume(
712
710
response = client .attach_volume (
713
711
Device = mount_point , InstanceId = instance_id , VolumeId = volume_id
714
712
)
715
- logger .debug ("Attached volume %s to instance %s" % ( volume_id , instance_id ) )
713
+ logger .debug (f "Attached volume { volume_id } to instance { instance_id } " )
716
714
except ClientError as e :
717
715
raise FailedActivity (
718
716
"Unable to attach volume %s to instance %s: %s"
0 commit comments