⚑ IT Wisdom OSPF: Open Shortest Path First. My career took OSPF everywhere. Still ended up in on-call rotation.
Skilled Practitioner
4249 XP 1751 to Expert
Objective: Write a Python module with two reusable functions for processing device data.
Instructions

Create a file called device_utils.py with two functions:

  1. format_hostname(name) β€” strips whitespace and lowercases the name
  2. get_device_type(hostname) β€” returns "switch" if the name starts with sw, "router" if it starts with rtr, "firewall" if it starts with fw, otherwise "unknown"

Then create a file called lab2.py that imports device_utils and runs these calls:

import device_utils

print(device_utils.format_hostname("  SW-CORE-01  "))
print(device_utils.get_device_type("rtr-edge-01"))
print(device_utils.get_device_type("sw-access-01"))

Run python3 lab2.py. Paste your output below and submit.

Starter Code
# device_utils.py β€” paste this into device_utils.py (not lab2.py)

def format_hostname(name):
    return name.strip().lower()

def get_device_type(hostname):
    if hostname.startswith("sw"):
        return "switch"
    elif hostname.startswith("rtr"):
        return "router"
    elif hostname.startswith("fw"):
        return "firewall"
    else:
        return "unknown"
πŸ’‘ Show Hint
Create two separate files: device_utils.py (the module) and lab2.py (the script that imports it). Both must be in the same directory.
Paste Your Output
Next Lab β†’