THEORY · TH-PY-007
AUTOCOR topic 1.4 asks you to construct a network automation solution with Python to manage the same five things as topic 1.3: VLANs, OSPF, asset management, interface settings and ACLs. TH-REST-004 sent each RESTCONF request by hand. This page turns those requests into one Python tool that reads the device, compares it with what you want, changes only what differs, checks the result and saves. It also covers CCIE Automation v1.2 topic 3.2 in Python: interfaces (3.2.a), VLANs (3.2.c), ACLs (3.2.d) and OSPF neighbors (3.2.g). Static routes and BGP (3.2.b, e, f) follow the same pattern with the models shown in TH-REST-007.
BLUEPRINT · AUTOCOR 350-901 v2.0: 1.4 · CCIE Automation v1.2: 3.2
Jump to: One loop for every use case · Intent as typed data · Normalize before you compare · Interface settings (CCIE 3.2.a) · VLANs and access ports (CCIE 3.2.c) · ACLs (CCIE 3.2.d) · OSPF (AUTOCOR 1.4 and CCIE 3.2.g) · Asset inventory · Plan and apply · What the exam expects · Exam check · References
Prerequisites: TH-REST-004 (the five use cases over RESTCONF), TH-PY-002 (HTTP clients) and TH-PY-001 (environment and data structures).
What you will be able to do after this page
- Design a Python tool around the desired-state loop: intent, read, normalize, compare, plan, apply, verify, save.
- Turn YAML intent into typed, validated Python objects before anything reaches a device.
- Normalize what IOS XE returns so the comparison is about meaning, not formatting.
- Manage interface settings, VLANs and access ports, ACLs and OSPF with the right RESTCONF method, in dependency order.
- Verify the result in operational models and build a hardware inventory report.
- Run the tool as a plan (dry run) and as an apply, with exit codes a pipeline can use.
SECTION 1
One loop for every use case
A script that sends a fixed list of requests is fragile: it fails on the second run, overwrites changes it does not own and cannot tell you what it is about to do. The pattern that solves this is the desired-state loop, the same idea behind Ansible resource modules and Terraform plans, written in plain Python:
| Stage | What the tool does | Python |
|---|---|---|
| Intent | Read what the device should look like | YAML file → dataclasses |
| Validate | Reject impossible values before contacting the device | ipaddress, range checks |
| Read | GET the current configuration of each object | requests.Session |
| Normalize | Convert the device reply into the same shape as the intent | small pure functions |
| Compare and plan | List only the changes needed, in dependency order | plan() returns Change objects |
| Apply | Send each change with the right method | PUT, PATCH, DELETE |
| Re-read | Plan again: an empty plan proves convergence | plan() a second time |
| Save and verify | Copy running to startup; check operational state | cisco-ia:save-config, -oper models |

Each use case maps to one target and one method:
| Use case | RESTCONF target (under native) | Method | Verify in |
|---|---|---|---|
| ACL | ip/access-list/Cisco-IOS-XE-acl:extended=<name> | PUT the whole ACL | GET the ACL |
| VLAN | vlan/Cisco-IOS-XE-vlan:vlan-list=<id> | PUT per VLAN, DELETE only VLANs you own | GET native/vlan |
| Interface settings, access port | interface/<type>=<number> | PATCH the fields you own; DELETE shutdown | Cisco-IOS-XE-interfaces-oper |
| OSPF | router (process) and .../network=<ip>,<wildcard> | PATCH to add, DELETE to remove a statement | Cisco-IOS-XE-ospf-oper neighbors |
| Asset inventory | Cisco-IOS-XE-device-hardware-oper:... (not under native) | GET only (config false) | — |
RESTCONF is the transport here because every object has a model and the replies are structured. The same loop works with NETCONF when you need all-or-nothing changes on the candidate datastore (TH-PY-004), and with CLI plus parsing when a feature has no model (TH-PY-005); only the read and apply functions change.
SECTION 2
Intent as typed data
The intent describes only what the tool owns. Here, R1 and SW1:
# intent/r1.yaml - what R1 should look like (owned fields only)
acls:
MGMT-IN:
- {seq: 10, action: permit, proto: tcp, src: 10.1.99.0/24, dst: any, dst_eq: 22}
- {seq: 20, action: deny, proto: tcp, src: any, dst: any, dst_eq: telnet, log: true}
- {seq: 30, action: permit, proto: ip, src: any, dst: any}
interfaces:
- name: GigabitEthernet2
description: Link to R2
ipv4: 10.1.12.1/24
enabled: true
acl_in: MGMT-IN
ospf:
process: 1
router_id: 1.1.1.1
networks:
- {prefix: 10.1.12.0/24, area: 0}
- {prefix: 10.1.1.1/32, area: 0}
# intent/sw1.yaml - VLANs 10-99 belong to this tool
vlans:
- {id: 10, name: USERS}
- {id: 20, name: VOICE}
prune_vlans: [10, 99]
interfaces:
- name: GigabitEthernet1/0/10
description: User access port
access_vlan: 10
Prefixes are written as /24, not as wildcards: people read prefixes, and the tool converts them. The loader turns each entry into a frozen dataclass and validates it with the same limits the YANG model has:
@dataclass(frozen=True)
class Interface:
name: str # full name, e.g. GigabitEthernet2
description: str | None = None
ipv4: ipaddress.IPv4Interface | None = None
enabled: bool = True
acl_in: str | None = None
access_vlan: int | None = None # switch ports only (switchport-config)
@property
def split(self) -> tuple[str, str]: # native model keys type and number separately
m = re.fullmatch(r"([A-Za-z-]+)(\d[\d/.:]*)", self.name)
if not m:
raise ValueError(f"bad interface name {self.name!r}")
return m.group(1), m.group(2)
@dataclass(frozen=True)
class Ace:
seq: int
action: str # permit | deny
proto: str # ip | tcp | udp | icmp
src: str = "any" # any | host A.B.C.D | prefix
dst: str = "any"
dst_eq: int | None = None
log: bool = False
for v in raw.get("vlans", []):
if not 1 <= int(v["id"]) <= 4094: # same range as vlan-list/id in Cisco-IOS-XE-vlan
raise ValueError(f"VLAN {v['id']} out of range 1..4094")
it.vlans[int(v["id"])] = str(v["name"])
Why it pays off:
ipaddress.IPv4Interface("10.1.12.1/24")rejects a typo such as10.1.12.300/24before any request, and gives you.ip,.netmaskand.networkfor free.- A VLAN 5000 fails in the loader with a clear message instead of an
invalid-valueerror from the device. The same body, checked with yanglint against the 26.2.1 models, fails withvalue "5000" is out of the allowed range. frozen=Truemakes the objects hashable, so ACL entries and OSPF networks can be compared as tuples and sets.prune_vlanssays which VLAN IDs the tool owns. VLANs outside that range (VLAN 1, a management VLAN 100) are never deleted, even though they are not in the file.
SECTION 3
Normalize before you compare
The device stores the same meaning in a different shape from your intent. Compare raw JSON with the intent and every run finds “changes” that are not real, and the tool never converges. These are the differences this page handles:
| Item | In the intent | What IOS XE can return | Normalize to |
|---|---|---|---|
| OSPF area | 0 | 0 or "0.0.0.0" (ospf-area-type is a union of uint32 and ipv4-address) | integer |
| OSPF network, ACL source | prefix 10.1.12.0/24 | address + wildcard 0.0.0.255 | IPv4Network |
| ACL port | 22, telnet | 22 or "telnet" (acl-tcp-port-type: union of uint16 and named ports) | port number |
| ACL sequence | 10 | "10" (uint64 is a string in JSON, RFC 7951) | integer |
| Member names | extended | Cisco-IOS-XE-acl:extended (module prefix where the namespace changes) | name without prefix |
| One list entry | an object | a one-item list under the entry name | the object |
| OSPF neighbor ID (oper) | 2.2.2.2 | 33686018 (nbr-id is uint32) | dotted quad |
The helpers are small and pure, so they are easy to test:
# Port names are YANG enum values with fixed numbers (Cisco-IOS-XE-types, acl-tcp-port-type)
PORTS = {"bgp": 179, "domain": 53, "ftp": 21, "smtp": 25, "telnet": 23, "www": 80}
def to_port(value: int | str | None) -> int | None:
if value is None:
return None
return int(value) if str(value).isdigit() else PORTS[str(value)]
def to_area(value: int | str) -> int:
"""OSPF area is a union of uint32 and dotted quad: compare both as integers."""
return int(ipaddress.IPv4Address(value)) if "." in str(value) else int(value)
def from_wildcard(ip: str, wildcard: str) -> ipaddress.IPv4Network:
"""Build a network from an IOS wildcard. Do not use IPv4Network(f"{ip}/{wildcard}"): ipaddress
tries a netmask first, so 0.0.0.0 becomes /0 and 255.255.255.255 becomes /32."""
wc = int(ipaddress.IPv4Address(wildcard))
if wc & (wc + 1): # a usable wildcard is 0...01...1
raise ValueError(f"non-contiguous wildcard {wildcard}")
return ipaddress.IPv4Network((ip, 32 - wc.bit_length()))
def strip(d):
"""Drop module prefixes from member names, so 'Cisco-IOS-XE-acl:extended' == 'extended'."""
if isinstance(d, dict):
return {k.split(":")[-1]: strip(v) for k, v in d.items()}
if isinstance(d, list):
return [strip(x) for x in d]
return d
def first(reply: dict) -> dict:
"""A GET on a list entry returns a one-item list under the entry name."""
(value,) = strip(reply).values()
return value[0] if isinstance(value, list) else value
The port numbers in PORTS are not invented: each named port in acl-tcp-port-type is a YANG enum with a value statement (telnet is 23, www is 80, bgp is 179). There is no ssh enum, so SSH is always 22.
TRAP
ipaddress.IPv4Network("10.0.0.0/0.0.0.255") works and gives 10.0.0.0/24, which makes it tempting to pass IOS wildcards to ipaddress. But the parser tries a netmask first, and the CPython source says it plainly: “the two ambiguous cases (all-ones and all-zeroes) are treated as netmasks”. So 10.1.1.1/0.0.0.0, the wildcard of a single host, is read as /0 and raises ValueError: 10.1.1.1/0 has host bits set, and 0.0.0.0/255.255.255.255, the wildcard for “any”, becomes a /32. Convert wildcards yourself, as from_wildcard() does.
strip() drops module prefixes only for comparison. Requests always go out with the prefixes RFC 7951 requires, built by the render functions.
SECTION 4
Interface settings (CCIE 3.2.a)
For an interface, the tool owns a few fields (description, IPv4 address, inbound ACL, access VLAN, administrative state) and leaves everything else alone. So it reads the interface, collects the fields that differ into one PATCH (a merge), and handles shutdown separately:
def intf_path(i: Interface) -> str:
typ, num = i.split
return f"{NATIVE}/interface/{typ}={quote(num, safe='')}"
for i in it.interfaces:
typ, num = i.split
cur = first(dev.get(intf_path(i)) or {typ: [{}]})
merge: dict = {}
if i.description is not None and cur.get("description") != i.description:
merge["description"] = i.description
prim = cur.get("ip", {}).get("address", {}).get("primary", {})
have = ipaddress.IPv4Interface(f"{prim['address']}/{prim['mask']}") if prim else None
if i.ipv4 and have != i.ipv4:
merge.setdefault("ip", {})["address"] = {
"primary": {"address": str(i.ipv4.ip), "mask": str(i.ipv4.netmask)}
}
acl = cur.get("ip", {}).get("access-group", {}).get("in", {}).get("acl", {}).get("acl-name")
if i.acl_in and acl != i.acl_in:
merge.setdefault("ip", {})["access-group"] = {
"in": {"acl": {"acl-name": i.acl_in, "in": [None]}}
}
sw = cur.get("switchport-config", {}).get("switchport", {})
if i.access_vlan and sw.get("access", {}).get("vlan", {}).get("vlan") != i.access_vlan:
merge["switchport-config"] = {
"switchport": {
"Cisco-IOS-XE-switch:access": {"vlan": {"vlan": i.access_vlan}},
"Cisco-IOS-XE-switch:mode": {"access": {}},
}
}
if not i.enabled and "shutdown" not in cur:
merge["shutdown"] = [None]
if merge:
body = {f"Cisco-IOS-XE-native:{typ}": [{"name": num, **merge}]}
changes.append(Change("PATCH", intf_path(i), body, f"{i.name}: {', '.join(merge)}"))
if i.enabled and "shutdown" in cur: # an empty leaf is removed with DELETE, not PATCH
changes.append(
Change(
"DELETE",
f"{intf_path(i)}/shutdown",
None,
f"{i.name}: no shutdown",
missing_ok=True,
)
)
What to notice:
- Key encoding.
quote("1/0/10", safe="")gives1%2F0%2F10. The defaultquote()keeps/unencoded and would build a wrong path. - IP comparison as objects.
IPv4Interface("10.1.12.1/255.255.255.0") == IPv4Interface("10.1.12.1/24")isTrue, so the format of the mask never causes a false change. shutdownis anemptyleaf. Shutting down is a merge of[None]; bringing up is a DELETE of the leaf, because a merge cannot remove anything. The tool marks that DELETE asmissing_ok.- The interface must exist. A plain PATCH only merges into an existing resource: RFC 8040 says the server must not create the target with PATCH. Physical interfaces always exist; a new Loopback or VLAN interface would need a PUT or POST first.
EXAM TIP
In the IETF model (ietf-interfaces) the same “no shutdown” is a merge of "enabled": true. If a question shows a PATCH with shutdown removed from the body and asks why the interface stays down, the answer is the merge semantics of the native model, not a device bug.
SECTION 5
VLANs and access ports (CCIE 3.2.c)
VLANs are compared as a dictionary {id: name}. A missing or renamed VLAN gets a PUT on its entry, which is idempotent; extra VLANs are deleted only inside the owned range:
cur_vlans = {
v["id"]: v.get("name")
for v in strip(dev.get(f"{NATIVE}/vlan") or {}).get("vlan", {}).get("vlan-list", [])
}
for vid, name in sorted(it.vlans.items()):
if cur_vlans.get(vid) != name:
changes.append(
Change(
"PUT",
f"{NATIVE}/vlan/Cisco-IOS-XE-vlan:vlan-list={vid}",
{"Cisco-IOS-XE-vlan:vlan-list": [{"id": vid, "name": name}]},
f"VLAN {vid} missing or renamed",
)
)
for vid in sorted(set(cur_vlans) - set(it.vlans)):
if it.prune_vlans and vid in it.prune_vlans:
changes.append(
Change(
"DELETE",
f"{NATIVE}/vlan/Cisco-IOS-XE-vlan:vlan-list={vid}",
None,
f"VLAN {vid} not in intent",
missing_ok=True,
)
)
On a switch with VLANs 1, 10 (named USR), 30 and 100, the plan renames 10, creates 20 and deletes 30. VLANs 1 and 100 stay: they are outside prune_vlans.
The access port is part of the interface PATCH in section 4 (switchport-config with access/vlan and the presence container mode/access). Two rules from the model:
- The VLAN changes come before the interface changes in the plan, so the port never points to a VLAN that does not exist yet.
switchport-config/switchportexists only with theswitching-platformfeature. The body validated against the 26.2.1 models with the feature on; without it, yanglint fails withNode "switchport" not found as a child of "switchport-config" node, the same error a Catalyst 8000V returns.
SECTION 6
ACLs (CCIE 3.2.d)
An ACL is an ordered set of entries, so the tool compares the whole ACL and, if anything differs, replaces it with one PUT. After the PUT the device holds exactly the entries in the intent:
def norm_acl(entry: dict) -> tuple[Ace, ...]:
aces = []
for r in entry.get("access-list-seq-rule", []):
rule = r.get("ace-rule", {})
aces.append(
Ace(
int(r["sequence"]),
rule.get("action"),
str(rule.get("protocol")),
norm_side(rule, "src"),
norm_side(rule, "dst"),
to_port(rule.get("dst-eq")),
"log" in rule,
)
)
return tuple(sorted(aces, key=lambda a: a.seq))
for name, aces in it.acls.items():
path = f"{NATIVE}/ip/access-list/Cisco-IOS-XE-acl:extended={quote(name, safe='')}"
cur = dev.get(path)
if cur is None or norm_acl(first(cur)) != tuple(sorted(aces, key=lambda a: a.seq)):
changes.append(Change("PUT", path, render_acl(name, aces), f"ACL {name} differs"))
Because the comparison uses Ace objects, an entry stored as "dst-eq": "telnet" equals an intent of 23, and "10" equals 10. An extra entry 40 added by someone on the CLI does make the ACL differ, and the PUT removes it. That is the right behavior for an ACL the tool owns; for an ACL several teams edit, manage single entries (access-list-seq-rule=<n>) instead.
The render function writes each entry in the shape the model expects: any / dst-any as [None] (type empty), a prefix as address plus wildcard (net.hostmask), sequence as a string and log as [None]. ACLs come first in the plan because the interface’s access-group refers to them.
SECTION 7
OSPF (AUTOCOR 1.4 and CCIE 3.2.g)
OSPF network statements are a list keyed by [ip wildcard], and their order does not matter, so the tool compares them as a set of (IPv4Network, area) pairs:
if it.ospf:
o = it.ospf
ppath = f"{NATIVE}/router/Cisco-IOS-XE-ospf:router-ospf/ospf/process-id={o['process']}"
cur = first(dev.get(ppath) or {"process-id": [{}]})
have = {
(from_wildcard(n["ip"], n["wildcard"]), to_area(n["area"]))
for n in cur.get("network", [])
}
add = o["networks"] - have
if add or cur.get("router-id") != str(o["router_id"]):
changes.append(
Change(
"PATCH",
f"{NATIVE}/router",
render_ospf(o, add),
f"OSPF {o['process']}: router-id or {len(add)} network(s)",
)
)
for net, _area in sorted(have - o["networks"], key=lambda x: int(x[0].network_address)):
key = f"{net.network_address},{net.hostmask}"
changes.append(
Change(
"DELETE",
f"{ppath}/network={key}",
None,
f"OSPF network {net} not in intent",
missing_ok=True,
)
)
With a device that already has 10.1.12.0 0.0.0.255 area 0.0.0.0 and an extra 10.9.9.0 0.0.0.255 area 0, the plan adds only 10.1.1.1/32, because to_area("0.0.0.0") == to_area(0), and deletes 10.9.9.0 with both keys in the URI (network=10.9.9.0,0.0.0.255). The new /32 goes out as wildcard 0.0.0.0, the exact case that ipaddress misreads.
Verify the neighbors in Cisco-IOS-XE-ospf-oper, converting the uint32 IDs:
def ospf_neighbors(dev: Restconf) -> dict[str, str]:
"""Return {neighbor router-id: state}; nbr-id is a uint32 in Cisco-IOS-XE-ospf-oper."""
data = strip(dev.get("Cisco-IOS-XE-ospf-oper:ospf-oper-data/ospfv2-instance") or {})
out = {}
for inst in data.get("ospfv2-instance", []):
for area in inst.get("ospfv2-area", []):
for intf in area.get("ospfv2-interface", []):
for n in intf.get("ospfv2-neighbor", []):
out[str(ipaddress.IPv4Address(int(n["nbr-id"])))] = n.get("state", "")
return out
state is an enumeration from ospf-nbr-down to ospf-nbr-full. A check that a change “worked” should wait for ospf-nbr-full on the expected neighbors, not only for a 204 on the PATCH: the PATCH proves the configuration, the neighbor state proves the network.
SECTION 8
Asset inventory
Inventory is operational data: read it, never write it. One GET with fields returns only the columns of the report, and csv.DictWriter writes them:
INV_FIELDS = [
"hw-type",
"hw-dev-index",
"hw-description",
"part-number",
"serial-number",
"version",
]
def inventory(dev: Restconf, host: str) -> list[dict]:
path = "Cisco-IOS-XE-device-hardware-oper:device-hardware-data/device-hardware/device-inventory"
reply = strip(dev.get(path, "?fields=" + ";".join(INV_FIELDS)) or {})
return [
{"host": host, **{k: e.get(k, "") for k in INV_FIELDS}}
for e in reply.get("device-inventory", [])
]
host,hw-type,hw-dev-index,hw-description,part-number,serial-number,version
192.0.2.11,hw-type-chassis,0,Cisco C8000V Chassis,C8000V,9ABCDEF0123,V00
192.0.2.11,hw-type-dimm,0,Virtual DIMM,,,
device-inventory is keyed by [hw-type hw-dev-index], so both keys go in the report: a chassis and a DIMM can both have index 0. Empty strings are normal for virtual parts. The same module has device-system-data (software version, boot time, last reboot reason) for a software inventory. The report is the device’s own truth; a source of truth such as NetBox is compared against it, which is the drift check of the SOT series.
SECTION 9
Plan and apply, then run again
main() ties it together. Without --apply the tool only reads and prints the plan:
it = load_intent(args.intent)
changes = plan(dev, it)
for c in changes:
log.info("plan %-6s %s (%s)", c.method, c.path.removeprefix(NATIVE + "/"), c.why)
if not changes:
log.info("no changes: device matches the intent")
if args.apply and changes:
for c in changes:
dev.send(c)
if plan(dev, it): # second read: the device must now match the intent
log.error("device still differs from the intent after apply")
return 2
dev.save()
log.info("applied %d change(s) and saved the configuration", len(changes))
Three runs against R1 (credentials in RESTCONF_USER and RESTCONF_PASS, CA file in RESTCONF_CA):
$ python iosxe_desired.py 192.0.2.11 intent/r1.yaml
INFO plan PUT ip/access-list/Cisco-IOS-XE-acl:extended=MGMT-IN (ACL MGMT-IN differs)
INFO plan PATCH interface/GigabitEthernet=2 (GigabitEthernet2: description, ip)
INFO plan DELETE interface/GigabitEthernet=2/shutdown (GigabitEthernet2: no shutdown)
INFO plan PATCH router (OSPF 1: router-id or 1 network(s))
INFO plan DELETE router/Cisco-IOS-XE-ospf:router-ospf/ospf/process-id=1/network=10.9.9.0,0.0.0.255 (OSPF network 10.9.9.0/24 not in intent)
INFO state GigabitEthernet2 admin=if-state-up oper=if-oper-state-ready
INFO state OSPF neighbor 2.2.2.2 ospf-nbr-full
$ echo $?
1
$ python iosxe_desired.py 192.0.2.11 intent/r1.yaml --apply --inventory inventory.csv
INFO plan ... (the same five lines)
INFO applied 5 change(s) and saved the configuration
INFO state GigabitEthernet2 admin=if-state-up oper=if-oper-state-ready
INFO state OSPF neighbor 2.2.2.2 ospf-nbr-full
INFO inventory: 2 item(s) written to inventory.csv
$ python iosxe_desired.py 192.0.2.11 intent/r1.yaml
INFO no changes: device matches the intent
INFO state GigabitEthernet2 admin=if-state-up oper=if-oper-state-ready
INFO state OSPF neighbor 2.2.2.2 ospf-nbr-full
$ echo $?
0
The interface PATCH does not list access-group because MGMT-IN was already applied; only the ACL entries were wrong. The exit codes are designed for a pipeline:
| Exit code | Meaning |
|---|---|
| 0 | Device matches the intent (nothing to do, or apply converged and was saved) |
| 1 | Plan only, and changes are pending: a pre-check can fail the merge request on drift |
| 2 | Apply ran but the second plan still found differences: stop and investigate |
| Exception | Validation, HTTP or connection error before a decision was possible |
Design choices worth copying:
- Plan first, always. The same function produces the dry run and the apply, so what you review is what runs.
- Owned fields only. PATCH merges, PUT only on objects the tool owns entirely, DELETE only inside an owned range.
- Dependency order: ACL → VLAN → interface → OSPF. Removals, if you add them, go in reverse.
- Converge, then save.
save-configruns only after the second plan is empty, so a half-applied change is never written to startup. - Operational check last. Configuration accepted is not the same as network working.
What the exam expects
- ✓ Build a Python solution that manages VLANs, OSPF, interface settings and ACLs and collects asset inventory on IOS XE (AUTOCOR 1.4).
- ✓ Read the current state, compare it with the intended state and send only the needed changes, so the script is idempotent.
- ✓ Normalize device data before comparing: union types, wildcards, named ports,
uint64strings,uint32router IDs. - ✓ Choose PUT, PATCH or DELETE per object and order changes by dependency.
- ✓ Automate interfaces, VLANs, ACLs and verify OSPF neighbors on IOS XE (CCIE 3.2.a, c, d, g).
- ✓ Verify with operational models and save the configuration only after the change converged.
EXAM CHECK · 350-901 TOPIC 1.4
Read it like the exam
1. A Python script compares the OSPF network entries it reads from the device with the intent and finds a difference on every run, although show running-config looks right. The intent says area: 0. What is the likely cause, and the fix?
The device returns the area in the other branch of the union ("0.0.0.0"), or the comparison mixes wildcards and prefixes. ospf-area-type accepts uint32 and ipv4-address, so both forms are valid. Normalize both sides (area to integer, address and wildcard to a prefix) before comparing.
2. Why does ipaddress.IPv4Network("10.1.1.1/0.0.0.0") raise ValueError when the IOS statement network 10.1.1.1 0.0.0.0 area 0 is valid?
ipaddress accepts both netmasks and hostmasks, but it tries the netmask first and treats the ambiguous all-zeros and all-ones values as netmasks. 0.0.0.0 becomes /0, and 10.1.1.1/0 has host bits set. Convert IOS wildcards explicitly: prefix length = 32 minus the number of one bits in the wildcard.
3. The tool must bring GigabitEthernet2 up and set its description. It sends one PATCH with the description and no shutdown leaf. The description changes, the interface stays down. Why, and what request is missing?
PATCH merges: leaving a leaf out of the body does not delete it. In the native model shutdown is an empty leaf, so bringing the interface up needs DELETE .../interface/GigabitEthernet=2/shutdown, treated as success if the leaf is already gone.
4. A switch has VLANs 1, 10, 30 and 100. The intent lists VLANs 10 and 20 with prune_vlans: [10, 99]. Which requests does the plan contain?
PUT on vlan-list=10 only if its name differs, PUT on vlan-list=20 to create it, and DELETE on vlan-list=30. VLANs 1 and 100 are outside the owned range and are left alone, even though they are not in the intent.
5. After --apply, the tool runs plan() again before cisco-ia:save-config. What does that second plan protect against?
Against saving a configuration that did not converge: a change the device accepted but stored differently, a change another process reverted, or a normalization bug. If the second plan is not empty, the tool exits with code 2 and leaves startup-config untouched.
References
- Cisco. Designing, Deploying and Managing Network Automation Systems v2.0 (350-901) exam topics
- Cisco. CCIE Automation Practical v1.2 exam topics
- Bierman, A., Bjorklund, M., Watsen, K. RFC 8040: RESTCONF Protocol. IETF, 2017
- YangModels. Cisco IOS XE 26.2.1 YANG models (
Cisco-IOS-XE-native,-vlan,-switch,-ospf,-acl,-types,-interfaces-oper,-ospf-oper,-device-hardware-oper,cisco-ia) - Python Software Foundation. CPython 3.13 source: Lib/ipaddress.py
- libyang / yanglint