Complete the code to check if a Compute Engine instance is currently running.
if instance.status == '[1]': print('Instance is running')
The status 'RUNNING' indicates the instance is active and operational.
Complete the code to stop a running Compute Engine instance using the GCP Python client.
operation = compute.instances().[1](project=project_id, zone=zone, instance=instance_name).execute()The 'stop' method is used to stop a running instance.
Fix the error in the code to check if an instance is terminated.
if instance.status == '[1]': print('Instance is terminated')
The correct status for a terminated instance is 'TERMINATED'.
Fill both blanks to create a dictionary that maps instance names to their current states.
instance_states = {instance.[1]: instance.[2] for instance in instances}The 'name' attribute identifies the instance, and 'status' gives its current state.
Fill all three blanks to filter instances that are currently running and create a list of their names.
running_instances = [instance.[1] for instance in instances if instance.[2] == '[3]']
This code collects the names of instances whose status is 'RUNNING'.