0
0
GCPcloud~10 mins

Instance states (running, stopped, terminated) in GCP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if a Compute Engine instance is currently running.

GCP
if instance.status == '[1]':
    print('Instance is running')
Drag options to blanks, or click blank then click option'
ATERMINATED
BSUSPENDED
CSTOPPED
DRUNNING
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'TERMINATED' or 'STOPPED' which mean the instance is not running.
2fill in blank
medium

Complete the code to stop a running Compute Engine instance using the GCP Python client.

GCP
operation = compute.instances().[1](project=project_id, zone=zone, instance=instance_name).execute()
Drag options to blanks, or click blank then click option'
Adelete
Bstart
Cstop
Dreset
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' which powers on the instance instead of stopping it.
3fill in blank
hard

Fix the error in the code to check if an instance is terminated.

GCP
if instance.status == '[1]':
    print('Instance is terminated')
Drag options to blanks, or click blank then click option'
ARUNNING
BTERMINATED
CSTOPPED
DPAUSED
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'STOPPED' which means the instance is powered off but not terminated.
4fill in blank
hard

Fill both blanks to create a dictionary that maps instance names to their current states.

GCP
instance_states = {instance.[1]: instance.[2] for instance in instances}
Drag options to blanks, or click blank then click option'
Aname
Bstatus
Czone
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'zone' or 'id' which do not represent the instance's name or state.
5fill in blank
hard

Fill all three blanks to filter instances that are currently running and create a list of their names.

GCP
running_instances = [instance.[1] for instance in instances if instance.[2] == '[3]']
Drag options to blanks, or click blank then click option'
Aname
Bstatus
CRUNNING
Dzone
Attempts:
3 left
💡 Hint
Common Mistakes
Filtering by 'zone' or using wrong status strings.