{"id":16139438,"url":"https://github.com/networkop/cue-networking-ii","last_synced_at":"2025-06-26T20:03:53.114Z","repository":{"id":63342400,"uuid":"566051431","full_name":"networkop/cue-networking-II","owner":"networkop","description":"github.com/networkop/cue-networking Part II","archived":false,"fork":false,"pushed_at":"2022-11-23T16:35:16.000Z","size":49,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-12T23:45:17.494Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jinja","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/networkop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-14T21:42:12.000Z","updated_at":"2024-12-17T03:57:11.000Z","dependencies_parsed_at":"2023-01-22T09:30:13.099Z","dependency_job_id":null,"html_url":"https://github.com/networkop/cue-networking-II","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networkop%2Fcue-networking-II","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networkop%2Fcue-networking-II/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networkop%2Fcue-networking-II/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networkop%2Fcue-networking-II/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/networkop","download_url":"https://codeload.github.com/networkop/cue-networking-II/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247526675,"owners_count":20953141,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-09T23:49:04.504Z","updated_at":"2025-04-06T17:43:24.145Z","avatar_url":"https://github.com/networkop.png","language":"Jinja","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CUE for Network Automation (Part II)\n\n\n## Walkthrough\n\n1. Pre-seed `demo.nautobot.com` with test data\n\n```\ncue apply ./...\n```\n\n2. Retrieve device data from Nautobot and save it as a set of host variables\n\n```\ncue fetch ./...\n```\n\n3. Print per-device structured configurations\n\n```\ncue try ./...\n```\n\n4. Print final device configurations\n\n```\ncue show ./...\n```\n\n4. Apply network configurations\n\n\n```\ncue push ./...\n```\n\n6. Cleanup `demo.nautobot.com`\n\n```\ncue cleanup ./...\n```\n\n## Creating CUE schemas\n\n### Option 1 - from Jinja templates\n\n1. Download the required Jinja templates and put them in the `./schemas/\u003cvendor\u003e` directory.\n\n```\ncat schemas/arista/eos.conf_original.j2\n```\n\n2. Remove all custom filters from a copy of each template.\n\n```\ncp arista/eos.conf_original.j2 arista/eos.conf.j2\nsed -E -i 's/\\|\\s+arista\\.avd\\.\\S+//' arista/eos.conf.j2\nsed -E -i 's/arista.avd.defined/defined/g' arista/eos.conf.j2\nsed -i -E 's/defined\\(true\\)/defined/' schemas/arista/eos.conf.j2\nsed -i -E 's/defined\\(false\\)/defined/' schemas/arista/eos.conf.j2\nsed -i -E 's/defined\\(\\'all\\'\\)/defined/' schemas/arista/eos.conf.j2\n```\n\n3. Convert Jinja templates to a JSON schema\n\n```\n$ pip install jinja2schema\n$ ./jinja-to-json-schema.py arista/eos.conf.j2\n```\n\n4. Convert JSON schema into CUE\n\n```\ncue import -f -p schema schema.json -o arista/schema.cue\n```\n\n5. (Optional) Make all fields optional\n\n```\nsed -i -E 's/(\\s+\\w+):/\\1\\?\\:/' schemas/arista/schema.cue\n```\n\n### Option 2 - from YAML files\n\n1. Get a copy of target device configuration in YAML format\n\n```\ncat schemas/nvidia/config.yml\n```\n\n2. Generate a JSON schema from the YAML file\n\n```\ncat schemas/nvidia/schema.json\n```\n\n3. Import as CUE \n\n```\ncue import -f -p schema nvidia/schema.json\n```\n\n4. Cleanup the schema (remove concrete values and add constraints)\n\n```diff\n\u003c import \"net\"\n\u003c\n---\n\u003e @jsonschema(schema=\"http://json-schema.org/draft-06/schema#\")\n\u003e _\n12c12,15\n\u003c #Interface: [string]: #InterfaceClass\n---\n\u003e #Interface: {\n\u003e       lo:   #Lo\n\u003e       swp1: #InterfaceSwp1\n\u003e }\n14,15c17,18\n\u003c #InterfaceClass: {\n\u003c       ip?:   #IP\n---\n\u003e #Lo: {\n\u003e       ip:   #IP\n19c22,30\n\u003c #IP: address: [string \u0026 net.IPCIDR]: {}\n---\n\u003e #IP: address: #Address\n\u003e\n\u003e #Address: \"198.51.100.1/32\": #[\"198.51.100.132\"]\n\u003e\n\u003e #: \"198.51.100.132\": {\n\u003e       ...\n\u003e }\n\u003e\n\u003e #InterfaceSwp1: type: string\n48c59\n\u003c #Neighbor: [string]: #NeighborClass\n---\n\u003e #Neighbor: swp1: #NeighborSwp1\n50c61\n\u003c #NeighborClass: {\n---\n\u003e #NeighborSwp1: {\n```\n\n## Working with Jinja (j2cli)\n\n1. Install `j2cli`\n\n```\npip install j2cli\n```\n\n1. Download any custom Jinja filters and test into the `./jinja` directory. \n\n```tree\ntree jinja\njinja\n├── filters\n│   └── combined.py\n└── tests\n    └── defined.py\n```\n\n2. Rename custom filters to get rid of namespacing\n\n```\nsed -E -i 's/arista.avd./arista_avd_/g' arista/eos.conf_original.j2\n```\n\n3. Update Python functions inside `./jinja` directory to match the new naming scheme\n\n4. Pass updated python files as arguments to `j2cli`\n\n```\nj2 --tests jinja/tests/defined.py --filters jinja/filters/combined.py -f json schemas/arista/eos.conf_original.j2 -\n```\n\n## Working with the lab\n\nBuild the lab topology using containerlab:\n\n```\ncue lab-up ./...\n```\n\nDestroy the lab\n\n```\ncue lab-down ./...\n```\n\nIf running on WSL2, adjust the default iptables rules\n\n```\ndocker exec lon-sw-02 ip6tables -P INPUT ACCEPT\ndocker exec lon-sw-02 ip6tables -P FORWARD ACCEPT\ndocker exec lon-sw-02 iptables -P FORWARD ACCEPT\ndocker exec lon-sw-02 iptables -P INPUT ACCEPT\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetworkop%2Fcue-networking-ii","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetworkop%2Fcue-networking-ii","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetworkop%2Fcue-networking-ii/lists"}