Bird
Raised Fist0
Azurecloud~15 mins

VM states (running, stopped, deallocated) in Azure - Mini Project: Build & Apply

Choose your learning style10 modes available
Azure VM States Management
📖 Scenario: You are managing virtual machines (VMs) in Microsoft Azure. Each VM can be in one of three states: running, stopped, or deallocated. You want to create a simple configuration that tracks the state of each VM in your resource group.
🎯 Goal: Build a dictionary in Python that holds VM names as keys and their states as values. Then, add a configuration variable to filter VMs by a specific state. Finally, write code to list all VMs currently in that state.
📋 What You'll Learn
Create a dictionary called vm_states with exact VM names and states
Add a variable called filter_state to specify which VM state to filter
Use a for loop with variables vm and state to iterate over vm_states.items()
Create a list called filtered_vms that contains VM names matching filter_state
💡 Why This Matters
🌍 Real World
Cloud administrators often need to track and manage the states of virtual machines to optimize costs and performance.
💼 Career
Understanding how to represent and filter VM states programmatically is essential for roles in cloud operations and infrastructure management.
Progress0 / 4 steps
1
Create the VM states dictionary
Create a dictionary called vm_states with these exact entries: 'vm1': 'running', 'vm2': 'stopped', 'vm3': 'deallocated', 'vm4': 'running', 'vm5': 'stopped'.
Azure
Hint

Use curly braces {} to create a dictionary with VM names as keys and their states as values.

2
Add a filter state variable
Add a variable called filter_state and set it to the string 'running' to filter VMs by this state.
Azure
Hint

Just assign the string 'running' to the variable filter_state.

3
Filter VMs by state
Use a for loop with variables vm and state to iterate over vm_states.items(). Inside the loop, add VMs to a list called filtered_vms if their state matches filter_state. Initialize filtered_vms as an empty list before the loop.
Azure
Hint

Start with an empty list, then loop through each VM and its state. Add the VM to the list if the state matches filter_state.

4
Complete the VM filtering configuration
Add a final line that sets a variable called result equal to the filtered_vms list to complete the configuration.
Azure
Hint

Assign the list filtered_vms to a new variable result to complete the setup.

Practice

(1/5)
1. What does the deallocated state mean for an Azure VM?
easy
A. The VM is off and resources are freed.
B. The VM is running and using resources.
C. The VM is off but still reserving resources.
D. The VM is paused but still running.

Solution

  1. Step 1: Understand VM states

    Azure VMs can be running, stopped, or deallocated. Running means active, stopped means off but resources reserved, deallocated means off and resources freed.
  2. Step 2: Identify deallocated meaning

    Deallocated means the VM is turned off and Azure releases the compute resources, so you don't pay for them.
  3. Final Answer:

    The VM is off and resources are freed. -> Option A
  4. Quick Check:

    Deallocated = off + freed resources [OK]
Hint: Deallocated means VM off and no resources reserved [OK]
Common Mistakes:
  • Confusing stopped with deallocated
  • Thinking deallocated still uses resources
  • Assuming deallocated means paused
2. Which Azure CLI command correctly stops a VM and releases its resources?
easy
A. az vm pause --name MyVM --resource-group MyGroup
B. az vm stop --name MyVM --resource-group MyGroup
C. az vm shutdown --name MyVM --resource-group MyGroup
D. az vm deallocate --name MyVM --resource-group MyGroup

Solution

  1. Step 1: Review Azure CLI commands for VM states

    To stop a VM but keep resources, use az vm stop. To stop and free resources, use az vm deallocate.
  2. Step 2: Identify command that releases resources

    az vm deallocate stops the VM and releases compute resources, matching the question.
  3. Final Answer:

    az vm deallocate --name MyVM --resource-group MyGroup -> Option D
  4. Quick Check:

    Deallocate command frees resources [OK]
Hint: Use 'deallocate' to stop VM and free resources [OK]
Common Mistakes:
  • Using 'stop' which keeps resources reserved
  • Confusing 'shutdown' with deallocate
  • Using non-existent 'pause' command
3. If an Azure VM is in the stopped state, what happens to billing for compute resources?
medium
A. Billing doubles due to stopped state overhead.
B. Billing stops immediately as VM is off.
C. Billing continues because resources are reserved.
D. Billing pauses but storage costs continue.

Solution

  1. Step 1: Understand billing for stopped VMs

    When a VM is stopped (not deallocated), compute resources are still reserved, so billing continues for compute.
  2. Step 2: Differentiate from deallocated state

    Only when VM is deallocated are compute resources freed and billing stops for compute.
  3. Final Answer:

    Billing continues because resources are reserved. -> Option C
  4. Quick Check:

    Stopped = billing continues [OK]
Hint: Stopped VMs still reserve resources and incur charges [OK]
Common Mistakes:
  • Assuming billing stops when VM is stopped
  • Confusing storage billing with compute billing
  • Thinking stopped means deallocated
4. You tried to start a VM but got an error because it is in the deallocated state. What should you do to fix this?
medium
A. Run az vm start to allocate and start the VM.
B. Run az vm stop to release resources first.
C. Run az vm restart to reset the VM state.
D. Run az vm deallocate again to confirm.

Solution

  1. Step 1: Understand VM start from deallocated

    A VM in deallocated state has no resources allocated. To use it, you must start it which allocates resources and powers it on.
  2. Step 2: Identify correct command to allocate and start

    az vm start allocates resources and powers on the VM, fixing the error.
  3. Final Answer:

    Run az vm start to allocate and start the VM. -> Option A
  4. Quick Check:

    Start command allocates resources [OK]
Hint: Use 'start' to allocate and power on deallocated VM [OK]
Common Mistakes:
  • Trying to stop or deallocate an already deallocated VM
  • Using restart which requires VM to be running
  • Not allocating resources before starting
5. You want to save costs by stopping your VM but keep its IP address and disk data intact. Which state should you use and why?
hard
A. Use running state but reduce VM size to save costs.
B. Use stopped state because it keeps resources reserved including IP and disks.
C. Use deallocated state because it frees all resources including IP address.
D. Use stopped state because it frees compute resources but keeps IP.

Solution

  1. Step 1: Understand resource reservation in stopped state

    When a VM is stopped (not deallocated), compute resources are reserved, so the IP address and disk data remain intact.
  2. Step 2: Compare with deallocated state

    Deallocated frees compute resources and may release dynamic IP addresses, so IP might change.
  3. Final Answer:

    Use stopped state because it keeps resources reserved including IP and disks. -> Option B
  4. Quick Check:

    Stopped = keep IP and disks reserved [OK]
Hint: Stopped keeps IP and disks; deallocated frees resources [OK]
Common Mistakes:
  • Choosing deallocated and losing IP address
  • Thinking stopped frees compute resources
  • Trying to save costs by resizing while running
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard