⚑ IT Wisdom Python 2 is dead. Stop trying to resuscitate it. Let it go. It's gone.
Skilled Practitioner
4249 XP 1751 to Expert
Objective: Write main.py that loads devices.json, validates each record, creates NetworkDevice objects, and logs the result of each.
Instructions

Inside capstone/, create devices.json:

[
  {"name": "sw-core-01",  "ip": "10.1.1.1",   "type": "switch",   "site": "HQ",  "vlan": 10},
  {"name": "sw-access-01","ip": "10.1.1.2",   "type": "switch",   "site": "HQ",  "vlan": 20},
  {"name": "rtr-edge-01", "ip": "10.1.1.254", "type": "router",   "site": "HQ",  "vlan": 1},
  {"name": "bad-device",  "ip": "not-an-ip",  "type": "switch",   "site": "HQ",  "vlan": 10},
  {"name": "fw-dmz-01",   "ip": "10.1.2.1",   "type": "firewall", "site": "DMZ", "vlan": 100}
]

Then write main.py from scratch. It must:

  1. Configure logging with format="%(levelname)s %(message)s" at INFO level
  2. Load devices.json with json.load()
  3. For each record: validate it, create a NetworkDevice on success (log INFO with the device name), log WARNING on failure (with the device name and reason)
  4. Print Loaded X of Y records after the loop

Your logging output must match exactly:

INFO Loaded sw-core-01
INFO Loaded sw-access-01
INFO Loaded rtr-edge-01
WARNING Skipped bad-device: Invalid IP: not-an-ip
INFO Loaded fw-dmz-01
Loaded 4 of 5 records

Paste your completed main.py below and submit.

πŸ’‘ Show Hint
Import NetworkDevice from device and validate_device + InvalidDeviceRecord from validator. Use try/except inside the loop. logging.info(f"Loaded {record['name']}") on success. logging.warning(f"Skipped {record.get('name', '?')}: {e}") on failure. Print the count after the loop.
Submit Your Code
Next Lab β†’