{"id":21636124,"url":"https://github.com/bigevilbeard/challenges_with-network_automation","last_synced_at":"2025-04-11T15:50:58.326Z","repository":{"id":128721633,"uuid":"173749940","full_name":"bigevilbeard/challenges_with-network_automation","owner":"bigevilbeard","description":"Network automation with Cisco IOS XE devices using RESTCONF","archived":false,"fork":false,"pushed_at":"2019-05-07T18:45:35.000Z","size":44,"stargazers_count":24,"open_issues_count":1,"forks_count":9,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-25T11:52:28.089Z","etag":null,"topics":["api","ios-xe","iox","python","restconf"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bigevilbeard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-04T13:27:41.000Z","updated_at":"2024-03-04T10:34:45.000Z","dependencies_parsed_at":"2023-03-13T11:28:42.484Z","dependency_job_id":null,"html_url":"https://github.com/bigevilbeard/challenges_with-network_automation","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/bigevilbeard%2Fchallenges_with-network_automation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigevilbeard%2Fchallenges_with-network_automation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigevilbeard%2Fchallenges_with-network_automation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigevilbeard%2Fchallenges_with-network_automation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bigevilbeard","download_url":"https://codeload.github.com/bigevilbeard/challenges_with-network_automation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248434628,"owners_count":21102879,"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":["api","ios-xe","iox","python","restconf"],"created_at":"2024-11-25T03:30:06.034Z","updated_at":"2025-04-11T15:50:58.319Z","avatar_url":"https://github.com/bigevilbeard.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Challenges With Network Automation\n\n## DevNet Sandbox\nAll code has been tested on the Cisco DevNet Multi-IOS Cisco Test Network Sandbox [HERE](https://devnetsandbox.cisco.com/RM/Diagram/Index/6b023525-4e7f-4755-81ae-05ac500d464a?diagramType=Topology).\n\nPlease see the sandbox pages for credentials and reservations, virl default passwords are used on all routers (cisco/cisco). This demo example is based on Python 3.6 and was tested successfully under that version.\n\n\n## Code\n\nAll of the code and examples for this are located in this directory. Clone and access it with the following commands:\n\n```\ngit clone https://github.com/bigevilbeard/challenges_with-network_automation.git\ncd challenges_with-network_automation\n```\n\n## Python Environment Setup\nIt is recommended that this demo be completed using Python 3.6.\n\nIt is highly recommended to leverage Python Virtual Environments for completing exercises in this course.\n\nFollow these steps to create and activate a venv.\n```\n# OS X or Linux\nvirtualenv venv --python=python3.6\nsource venv/bin/activate\n```\n## Install the code requirements\n```\npip install -r requirements.txt\n```\n\n## Reservation Setup\nThis lesson leverages a specific [VIRL](https://github.com/bigevilbeard/automated_bgp_iox/blob/master/topology.virl) topology, as such virl default passwords are used on all routers (cisco/cisco). Before beginning this lesson run the following command to reconfigure the Sandbox with the proper topology.\n\nFrom the `challenges_with-network_automation` directory\n```\n# Get a list of currently running simulations\nvirl ls --all\n\n# Stop any running simulations.\nvirl down --sim-name \u003cSimulation name\u003e\n\n# Start the VIRL Simulation for demo\nvirl up\n\n# Monitor status of simulation\nvirl nodes   # Node startup\n```\nOnce the VIRL simulation is built, the following will be seen.\n```\n(venv) [developer@devbox challenges_with-network_automation]$virl ls\nRunning Simulations\n╒═══════════════════════════════════════════════════╤══════════╤════════════════════════════╤═══════════╕\n│ Simulation                                        │ Status   │ Launched                   │ Expires   │\n╞═══════════════════════════════════════════════════╪══════════╪════════════════════════════╪═══════════╡\n│ challenges_with-network_automation_default_yNccAp │ ACTIVE   │ 2019-03-04T16:19:46.778031 │           │\n╘═══════════════════════════════════════════════════╧══════════╧════════════════════════════╧═══════════╛\n```\n\nNOTE: IP addresses will differ in your own simulation\n\n```\n(venv) [developer@devbox challenges_with-network_automation]$virl nodes\nHere is a list of all the running nodes\n╒═══════════╤══════════╤═════════╤═════════════╤════════════╤══════════════════════╤════════════════════╕\n│ Node      │ Type     │ State   │ Reachable   │ Protocol   │ Management Address   │ External Address   │\n╞═══════════╪══════════╪═════════╪═════════════╪════════════╪══════════════════════╪════════════════════╡\n│ PE-2      │ CSR1000v │ ACTIVE  │ REACHABLE   │ telnet     │ 172.16.30.91         │ N/A                │\n├───────────┼──────────┼─────────┼─────────────┼────────────┼──────────────────────┼────────────────────┤\n│ PE-1      │ CSR1000v │ ACTIVE  │ REACHABLE   │ telnet     │ 172.16.30.90         │ N/A                │\n├───────────┼──────────┼─────────┼─────────────┼────────────┼──────────────────────┼────────────────────┤\n│ CE-1      │ CSR1000v │ ACTIVE  │ REACHABLE   │ telnet     │ 172.16.30.89         │ N/A                │\n├───────────┼──────────┼─────────┼─────────────┼────────────┼──────────────────────┼────────────────────┤\n│ ~mgmt-lxc │ mgmt-lxc │ ACTIVE  │ REACHABLE   │ ssh        │ 172.16.30.87         │ 172.16.30.88       │\n╘═══════════╧══════════╧═════════╧═════════════╧════════════╧══════════════════════╧════════════════════╛\n```\n\n## Running the code examples\n\nConfiguration is done using the Representational State Transfer Configuration Protocol (RESTCONF). RESTCONF is an HTTP based protocol. It provides a programmatic interface based on standard mechanisms for accessing configuration data, state data, data-model-specific Remote Procedure Call (RPC) operations and events defined in a YANG model. This code is using native YANG models for IOS-XE - models that are specific to IOS-XE platforms.\n\n- `get_bgp.py` - Passes static configuration IP Address/Port/User/Password and will get all device BGP information. Results are printed using [Tabulate](https://pypi.org/project/tabulate/)\n- `get_interfaces.py` - Passes static configuration IP Address/Port/User/Password and will get all device interface information. Results are printed using [Tabulate](https://pypi.org/project/tabulate/)\n- `get_device.py` - Passes static configuration IP Address/Port/User/Password and will get device hostname and version information. Results are printed using [Tabulate](https://pypi.org/project/tabulate/)\n\n- `router_info.py` - This code uses Object-Oriented Programming (OOP). This is a programming paradigm where different components of a computer program are modeled after real-world objects. An object is anything that has some characteristics and can perform a function. All args used in the running of the code are handled using [CLICK](https://click.palletsprojects.com/en/7.x/). Click is a Python package for creating beautiful command line interfaces in a composable way with as little code as necessary.\n\nIn this code, we can show the router BGP and interface information (shown in `json` format). We can also add an access list to an interface with the `patch` and `delete`. As with REST, with RESTCONF we can use Methods. Methods are `HTTPS` operations _`(GET/PATCH/POST/DELETE/OPTIONS/PUT)`_ performed on a target resource. Use either a single IP or update the `JSON` file with devices IP addresses.\n\nUse the `--help` to see the Options and Commands\n\n```\n(venv) STUACLAR-M-R6EU:challenges_with-network_automation stuaclar$ python router_info.py --help\nUsage: router_info.py [OPTIONS] COMMAND [ARGS]...\n\n  Gather and Add IOS XE device information using restconf\n\nOptions:\n  --ip TEXT        ip or dns address of device\n  --file TEXT      file ip addresses of devices\n  --port INTEGER   device port, default = 443\n  --username TEXT  device username (default lab username = cisco)\n  --password TEXT  device password (default lab password = cisco)\n  --help           Show this message and exit.\n\nCommands:\n  add_drop        Add ACL to Interface\n  delete_drop     Remove ACL from Interface\n  get_bgp         Gather BGP information\n  get_device      Gather Device information\n  get_interfaces  Gather Interface information\n```\n\n## Example Use Commands\n\n- `python router_info.py --ip 172.16.30.62 get_interfaces`\n`python router_info.py --file routers.json get_device`\n\n```\n(venv) STUACLAR-M-R6EU:challenges_with-network_automation stuaclar$ python router_info.py --ip  172.16.30.89 get_device\nUsername: cisco\nPassword:\nWorking....\n{\n    \"Cisco-IOS-XE-native:native\": {\n        \"device\": {\n            \"hostname\": \"csr1000v\",\n            \"version\": \"16.8\"\n        }\n    }\n}\nTask completed\n```\n\n## About me\n\nNetwork Automation Developer Advocate for Cisco DevNet.\nI'm like Hugh Hefner... minus the mansion, the exotic cars, the girls, the magazine and the money. So basically, I have a robe.\n\nFind me here: [LinkedIn](https://www.linkedin.com/in/stuarteclark/) / [Twitter](https://twitter.com/bigevilbeard)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigevilbeard%2Fchallenges_with-network_automation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbigevilbeard%2Fchallenges_with-network_automation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigevilbeard%2Fchallenges_with-network_automation/lists"}