01 / ADDRESSING AND INVENTORY · LESSON 04

Separate administrative intent from link state

Classify interface observations without reporting intentionally disabled ports as faults.

15 min · learn at your pace

Intent and observation answer different questions

An administrative state describes whether an interface is enabled by configuration. An operational state describes the observed link. An interface that is administratively down should not be reported as a failed enabled link simply because its operational state is also down.

This lesson uses explicit exported values: up and down. A known administrative down state becomes disabled. If administration is up, operational up is healthy and operational down needs attention. Missing or unrecognized evidence remains unknown.

Preserve uncertainty in the report

Do not coerce an arbitrary string to a Boolean: both "up" and "down" are truthy. Do not turn a missing field into a healthy default either. An unknown administrative state takes precedence because the tool cannot establish whether the interface was intended to be enabled.

Use the pair of device and interface as the identity. Names such as wan0 occur on many devices. Normalize both labels for this fictional export, reject duplicate pairs, and sort the output. Include a short reason alongside the status so an operator can distinguish an actual down link from missing collection data.

This classification is a snapshot assessment. Even an up link does not demonstrate end-to-end application reachability. No live interface is queried or changed by this browser exercise.

Try an example.py
row = {"admin":"down", "oper":"down"}
print(bool(row["admin"]))
print(row["admin"] == "up")
YOUR TURN

Put it into practice.

Define interface_health(rows). Each row has string device/interface and optional admin/oper. Normalize identity with strip().casefold(); empty or duplicate pairs raise ValueError. Exact state values: admin down => disabled/administratively down; unknown admin => unknown/administrative state unavailable; admin up with oper up => healthy/link up; oper down => attention/link down; otherwise unknown/operational state unavailable. Return device, interface, status, reason sorted by identity, preserving inputs.

See an explained solution
One way to solve it.py
def interface_health(rows):
    results, seen = [], set()
    for row in rows:
        device, interface = row["device"].strip().casefold(), row["interface"].strip().casefold()
        key = (device, interface)
        if not device or not interface or key in seen:
            raise ValueError("Empty or duplicate interface identity")
        seen.add(key)
        admin, oper = row.get("admin"), row.get("oper")
        if admin == "down":
            status, reason = "disabled", "administratively down"
        elif admin != "up":
            status, reason = "unknown", "administrative state unavailable"
        elif oper == "up":
            status, reason = "healthy", "link up"
        elif oper == "down":
            status, reason = "attention", "link down"
        else:
            status, reason = "unknown", "operational state unavailable"
        results.append({"device":device,"interface":interface,"status":status,"reason":reason})
    return sorted(results,key=lambda row:(row["device"],row["interface"]))

if __name__ == "__main__":
    print(interface_health([{"device":"edge-a","interface":"wan0","admin":"up","oper":"down"}]))

Administrative intent determines whether a down port is expected. Explicit unknown states avoid turning incomplete exports into false evidence of health.