⚑ IT Wisdom I asked my manager for more memory. He told me to try meditation.
Skilled Practitioner
4249 XP 1751 to Expert
Objective: Write a custom exception and a validate_device() function that checks required fields, IP format, and VLAN range.
Instructions

Inside capstone/, write validator.py from scratch.

It must define:

  1. InvalidDeviceRecord(Exception) β€” a custom exception class
  2. REQUIRED_FIELDS β€” a list of the five fields every record must have
  3. validate_device(record) β€” raises InvalidDeviceRecord with a specific message for each failure:
  4. If a required field is missing: Missing field: <field>
  5. If the IP does not look like four dot-separated groups of digits: Invalid IP: <ip>
  6. If the VLAN is not between 1 and 4094: VLAN out of range: <vlan>
  7. Returns True if all checks pass

Check fields in the order listed above β€” missing fields first, then IP, then VLAN.

Do not copy from the lesson. You wrote a custom exception in Unit 8 and used regex in Unit 10.

Paste your completed validator.py below and submit.

πŸ’‘ Show Hint
class InvalidDeviceRecord(Exception): pass. Loop through REQUIRED_FIELDS and raise if field not in record. Use re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", record["ip"]) for the IP check. int(record["vlan"]) to check the range.
Submit Your Code
Next Lab β†’