{"id":21636126,"url":"https://github.com/bigevilbeard/automated_bgp_iox","last_synced_at":"2026-03-08T01:31:57.144Z","repository":{"id":128721512,"uuid":"180130057","full_name":"bigevilbeard/automated_bgp_iox","owner":"bigevilbeard","description":"How to Leverage BGP Automation to Execute Python Code Directly on an End Device","archived":false,"fork":false,"pushed_at":"2023-05-22T21:37:16.000Z","size":21,"stargazers_count":5,"open_issues_count":1,"forks_count":4,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-11T15:59:17.689Z","etag":null,"topics":[],"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,"zenodo":null}},"created_at":"2019-04-08T10:57:39.000Z","updated_at":"2023-04-29T00:04:46.000Z","dependencies_parsed_at":"2025-04-11T15:50:42.100Z","dependency_job_id":"52273c2e-76d9-4906-80fa-627e9ffbbabb","html_url":"https://github.com/bigevilbeard/automated_bgp_iox","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bigevilbeard/automated_bgp_iox","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigevilbeard%2Fautomated_bgp_iox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigevilbeard%2Fautomated_bgp_iox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigevilbeard%2Fautomated_bgp_iox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigevilbeard%2Fautomated_bgp_iox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bigevilbeard","download_url":"https://codeload.github.com/bigevilbeard/automated_bgp_iox/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigevilbeard%2Fautomated_bgp_iox/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30240896,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T00:58:18.660Z","status":"ssl_error","status_checked_at":"2026-03-08T00:55:48.608Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-11-25T03:30:11.047Z","updated_at":"2026-03-08T01:31:57.109Z","avatar_url":"https://github.com/bigevilbeard.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# How to Leverage BGP Automation to Execute Python Code Directly on an End Device\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/automated_bgp_iox.git\ncd automated_bgp_iox\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## Check the version of virlutils (this should be 0.8.8 )\n```\npip3 freeze | grep virlutils\nvirlutils==0.8.8\n```\nIf required\n```\npip3 install --upgrade virlutils\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 `automated_bgp_iox` 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# Increase the ram for the CSR1000v\nvirl flavors delete CSR1000v\nvirl flavors add CSR1000v --memory 8192 --vcpus 2\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 automated_bgp_iox]$virl ls\nRunning Simulations\n╒═══════════════════════════════════════════════════╤══════════╤════════════════════════════╤═══════════╕\n│ Simulation                                        │ Status   │ Launched                   │ Expires   │\n╞═══════════════════════════════════════════════════╪══════════╪════════════════════════════╪═══════════╡\n│ automated_bgp_iox_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 automated_bgp_iox]$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):automated_bgp_iox 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:automated_bgp_iox 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## Guest Shell on CE-1\n\n```\nhost-CE-1(config)#iox\nhost-CE-1(config)#\n*Mar 21 10:56:58.177: %UICFGEXP-6-SERVER_NOTIFIED_START: R0/0: psd: Server iox has been notified to start\nhost-CE-1(config)#end\n```\nConfirm IOX is Running\n\n```\nhost-CE-1#sh iox\nVirtual Service Global State and Virtualization Limits:\n\nInfrastructure version : 1.7\nTotal virtual services installed : 0\nTotal virtual services activated : 0\n\nMachine types supported   : KVM, LXC\nMachine types disabled    : none\n\nMaximum VCPUs per virtual service : 0\nResource virtualization limits:\nName                         Quota     Committed     Available\n--------------------------------------------------------------\nsystem CPU (%)                   7             0             7\nmemory (MB)                   1024             0           882\nbootflash (MB)               20000             0          6719\n\n\nIOx Infrastructure Summary:\n---------------------------\nIOx service (CAF)    : Running\nIOx service (HA)     : Not Running\nIOx service (IOxman) : Running\nLibvirtd             : Running\n```\nEnable Guest Shell\n```\nhost-CE-1#guestshell enable\nInterface will be selected if configured in app-hosting\nPlease wait for completion\n....\n\n```\n\n## Add the python script via bash\n\n```\nhost-CE-1#guestshell run bash\n[guestshell@guestshell ~]$touch bgp_down.py\n[guestshell@guestshell ~]$ vi bgp_down.py\n\u003cesc\u003e, i\nimport sys\nimport cli\n\n\nprint \"\\n\\n *** Shutting Down BGP Session  *** \\n\\n\"\ncli.configurep([\"router bgp 100\",\"neighbor 10.1.2.2 shutdown\", \"end\"])\n\u003cesc\u003e, wq\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%2Fautomated_bgp_iox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbigevilbeard%2Fautomated_bgp_iox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigevilbeard%2Fautomated_bgp_iox/lists"}