NAPALM for Network Engineers
Getters: Structured Facts and Interfaces
What you'll learn
- get_facts()'s real, normalized return shape
- get_interfaces()'s real, normalized return shape
- get_interfaces_ip()'s real, normalized return shape
- Why this is the module's core payoff: structured state, not CLI text to parse
Listen to a guided explanation of this lesson.
Spoken narration isn't supported in this browser.
Structured state, not a generic dictionary
This is the payoff, not a Python exercise
get_facts() doesn't return "a Python dictionary" in the generic tutorial sense -- it returns a specific, documented shape (FactsDict) that every NAPALM driver, for every supported vendor, fills in the same way. The value isn't "dictionaries exist" -- it's that this exact shape is guaranteed regardless of which vendor answered.
get_facts(): device identity, normalized
def get_facts(self) -> FactsDict: ...
# FactsDict's real fields, verified via inspect:
# os_version: str, uptime: float, interface_list: List,
# vendor: str, serial_number: str, model: str,
# hostname: str, fqdn: strVerified directly from napalm.base.models.FactsDict's real annotations -- these exact eight keys, every vendor, every time.
driver.open()
facts = driver.get_facts()
print(facts)Lesson 6 covers how this mock driver works in full -- for now, treat it as a real NAPALM feature returning real, verified output.
{'os_version': '16.9.5, RELEASE SOFTWARE (fc3)', 'uptime': 1234567.0,
'interface_list': ['GigabitEthernet0/1', 'GigabitEthernet0/2'],
'vendor': 'Cisco', 'serial_number': 'SW1-SN-001', 'model': 'Catalyst 3850',
'hostname': 'SW1', 'fqdn': 'SW1.example.local'}Real, verified output. Exactly the eight FactsDict keys -- nothing invented, nothing missing.
get_interfaces(): per-interface state, normalized
def get_interfaces(self) -> Dict[str, InterfaceDict]: ...
# InterfaceDict's real fields, verified via inspect:
# is_up: bool, is_enabled: bool, description: str,
# last_flapped: float, mtu: int, speed: float, mac_address: strVerified directly. The outer dict is keyed by interface name; each value is one InterfaceDict with these exact seven fields.
{'GigabitEthernet0/1': {'is_up': True, 'is_enabled': True,
'description': 'uplink-to-core', 'last_flapped': -1.0,
'mtu': 1500, 'speed': 1000.0, 'mac_address': 'AA:BB:CC:00:01:01'},
'GigabitEthernet0/2': {'is_up': False, 'is_enabled': True,
'description': 'unused', 'last_flapped': -1.0,
'mtu': 1500, 'speed': 1000.0, 'mac_address': 'AA:BB:CC:00:01:02'}}Real, verified output from driver.get_interfaces() against the same SW1 fixture.
get_interfaces_ip(): addressing, normalized
def get_interfaces_ip(self) -> Dict[str, InterfacesIPDict]: ...
# InterfacesIPDict: {"ipv4": Dict[str, {"prefix_length": int}], "ipv6": Dict[str, {"prefix_length": int}]}Verified directly. Keyed by interface, then by IP-family, then by the actual address string, each holding a prefix_length.
{'GigabitEthernet0/1': {'ipv4': {'10.10.10.1': {'prefix_length': 24}}, 'ipv6': {}}}Real, verified output. The IP address itself is a dict key, not a value -- worth noting since it's an easy shape to get wrong on a first guess.
The same question, three vendors (documentation-derived)
Verified locally: the shape. Not verified locally: cross-vendor identical output.
Everything above was executed for real against NAPALM's own IOS-family model and mock driver in this environment -- that's Category A. Whether a real Juniper or Arista device returns an identically-shaped get_interfaces() dict is NAPALM's own design contract (documented, widely relied on by the community) but was not independently executed here, since no Juniper or Arista device or driver was available -- that claim is Category C, stated honestly rather than implied as tested.
Key takeaways
- get_facts() returns exactly eight fields (os_version, uptime, interface_list, vendor, serial_number, model, hostname, fqdn) -- verified against the real model and real execution.
- get_interfaces() returns a dict keyed by interface name, each holding is_up/is_enabled/description/last_flapped/mtu/speed/mac_address.
- get_interfaces_ip() nests IP addresses as dict keys, each holding a prefix_length -- an easy shape to get wrong without checking it directly, which is why it was verified rather than assumed.
- This lesson's local verification covers the IOS-family shape (Category A). The cross-vendor identical-shape guarantee is real and documented but not independently tested here (Category C) -- stated honestly, not overstated.