Python SDK and command line utilities to work with the EVE-NG REST API
Project description
evengsdk
Documentation: https://ttafsir.github.io/evengsdk
Open source library and command line utilities to work with the EVE-NG REST API .
Evegnsdk allows you to quickly build network topologies in EVE-NG for testing and development. The CLI tool also enables you quickly integrate EVE-NG into your CI/CD toolset for automated testing and validation.
Requirements
- Python 3.8+
- An EVE-NG instance
:rocket:Installation
You can install evengsdk using pip
pip install eve-ng
Basic Usage
You can interact with the EVE-NG API through the client.api interface
>>> from evengsdk.client import EvengClient
>>> from pprint import pprint
>>>
>>> client = EvengClient("10.246.32.254", log_file="test.log")
>>> client.login(username="admin", password="eve")
>>>
>>> resp = client.api.list_node_templates()
>>> pprint(resp.get("data"))
{'a10': 'A10 vThunder.missing',
'acs': 'Cisco ACS.missing',
'aruba': 'Aruba WiFi Controller.missing',
'arubacx': 'Aruba OS-CX Virtual Switch.missing',
'asa': 'Cisco ASA.missing',
'asav': 'Cisco ASAv',
'bigip': 'F5 BIG-IP LTM VE',
'cumulus': 'Cumulus VX',
<OUTPUT OMMITTED FOR BREVITY>
'linux': 'Linux',
'mikrotik': 'MikroTik RouterOS.missing',
'nsx': 'VMWare NSX.missing',
'nxosv9k': 'Cisco NX-OSv 9K',
'paloalto': 'Palo Alto.missing',
'pfsense': 'pfSense Firewall.missing',
'vcenter': 'VMWare vCenter.missing',
'vios': 'Cisco vIOS Router',
'viosl2': 'Cisco vIOS Switch',
'vmx': 'Juniper vMX.missing',
'vwlc': 'Cisco vWLC.missing',
'vyos': 'VyOS',
'xrv9k': 'Cisco XRv 9000.missing'}
>>>
Example: Build a Lab
from evengsdk.client import EvengClient
client = EvengClient("10.246.32.254", log_file="test.log", ssl_verify=False, protocol="https")
client.disable_insecure_warnings() # disable warnings for self-signed certificates
client.login(username="admin", password="eve")
client.set_log_level("DEBUG")
# create a lab
lab = {"name": "test_lab", "description": "Test Lab", "path": "/"}
resp = client.api.create_lab(**lab)
if resp['status'] == "success":
print("lab created successfully.")
# we need the lab path to create objects in the lab
lab_path = f"{lab['path']}{lab['name']}.unl"
# create management network
mgmt_cloud = {"name": "eve-mgmt", "network_type": "pnet1"}
client.api.add_lab_network(lab_path, **mgmt_cloud)
# create Nodes
nodes = [
{"name": "leaf01", "template": "veos", "image": "veos-4.22.0F", "left": 50},
{"name": "leaf02", "template": "veos", "image": "veos-4.22.0F", "left": 200},
]
for node in nodes:
client.api.add_node(lab_path, **node)
# connect nodes to management network
mgmt_connections = [
{"src": "leaf01", "src_label": "Mgmt1", "dst": "eve-mgmt"},
{"src": "leaf02", "src_label": "Mgmt1", "dst": "eve-mgmt"}
]
for link in mgmt_connections:
client.api.connect_node_to_cloud(lab_path, **link)
# create p2p links
p2p_links = [
{"src": "leaf01", "src_label": "Eth1", "dst": "leaf02", "dst_label": "Eth1"},
{"src": "leaf01", "src_label": "Eth1", "dst": "leaf02", "dst_label": "Eth2"},
]
for link in p2p_links:
client.api.connect_node_to_node(lab_path, **link)
client.logout()
:tv: The eve-ng CLI Application
The CLI application makes it very simple to quick work with EVE-NG, especially in situation where you would like to automate lab builds and testing using CI/CD.
The CLI application provides an interface to manage EVE-NG objects including:
Folders- manage the directory-like structures that contains labsLabs- manage labs and objects inside labs (nodes, networks, links, etc)- nodes
- networks
Users- manage system usersSystem- View system status and resources (node templates, network types, user roles, etc..)
➜ eveng --help
Usage: eveng [OPTIONS] COMMAND [ARGS]...
CLI application to manage EVE-NG objects
Options:
--host TEXT [required]
--username TEXT [default: (current user); required]
--password TEXT [required]
--port INTEGER HTTP port to connect to. Default is 80
--debug / --no-debug Enables or disables debug mode.
-v, --verbose Enables verbosity.
--help Show this message and exit.
Commands:
folder folder sub commands
lab lab sub commands
list-network-types list EVE-NG network types
list-node-templates list EVE-NG node templates
list-user-roles list EVE-NG user roles
node node sub commands
show-status View EVE-NG server status
show-template get EVE-NG node template details
user user sub commands
version display library version
CLI sample output
:gear: Configuration
It is simple enough to pass the proper flags to eve-ng specify details for your EVE-NG host. However, you may also pass the connection details as environment variables. You can set the following evengsdk environment variables:
EVE_NG_HOST- EVE-NG host name or IP addressEVE_NG_USERNAME- EVE-NG usernameEVE_NG_PASSWORDEVE-NG API/GUI passwordEVE_NG_LAB_PATH- EVE-NG default lab path. Ex./myLab.unl
You may set the variables and export them to your shell environment. You can also define your environment variables in a .env folder that will automatically be sourced. The example. below shows the contents of a .env file that will permit you to both source the file and automatically load the variables as needed.
export EVE_NG_HOST=192.168.2.100
export EVE_NG_USERNAME=admin
export EVE_NG_PASSWORD=eve
export EVE_NG_PORT=80
export EVE_NG_PROTOCOL=http
export EVE_NG_SSL_VERIFY=False
export EVE_NG_INSECURE=True
export EVE_NG_LAB_PATH='/mylab.unl'
🏗️ Topology Builder
The CLI application allows you to build lab topologies using a declarative model in order to quickly spin a lab and configure nodes using configuration files or jinja templates. Below is a sample topology that is the examples directory of this project.
---
name: test
description: Arista VEOS leaf-spine lab
path: "/"
nodes:
- name: leaf01
template: veos
image: veos-4.22.0F
node_type: qemu
left: 50
top: 135
configuration:
file: examples/configs/test_leaf01.cfg
- name: leaf02
template: veos
image: veos-4.22.0F
node_type: qemu
left: 200
top: 135
configuration:
template: base.j2
vars:
hostname: leaf02
management_address: 10.10.10.1
- name: leaf03
template: veos
image: veos-4.22.0F
node_type: qemu
left: 350
top: 135
configuration:
template: base.j2
vars: examples/data/leaf03.yml
- name: leaf04
template: veos
image: veos-4.22.0F
node_type: qemu
left: 500
top: 135
- name: spine01
template: veos
image: veos-4.22.0F
node_type: qemu
left: 150
top: 474
- name: spine02
template: veos
image: veos-4.22.0F
node_type: qemu
left: 350
top: 474
networks:
- name: vCloud
network_type: pnet1
visibility: 1
top: 300
left: 475
links:
network:
- {"src": "leaf01", "src_label": "Mgmt1", "dst": "vCloud"}
- {"src": "leaf02", "src_label": "Mgmt1", "dst": "vCloud"}
- {"src": "leaf03", "src_label": "Mgmt1", "dst": "vCloud"}
- {"src": "leaf04", "src_label": "Mgmt1", "dst": "vCloud"}
- {"src": "spine01", "src_label": "Mgmt1", "dst": "vCloud"}
- {"src": "spine02", "src_label": "Mgmt1", "dst": "vCloud"}
node:
- {"src": "leaf01", "src_label": "Eth3", "dst": "spine01", "dst_label": "Eth1"}
- {"src": "leaf02", "src_label": "Eth3", "dst": "spine01", "dst_label": "Eth2"}
- {"src": "leaf03", "src_label": "Eth3", "dst": "spine01", "dst_label": "Eth3"}
- {"src": "leaf04", "src_label": "Eth3", "dst": "spine01", "dst_label": "Eth4"}
- {"src": "leaf01", "src_label": "Eth2", "dst": "spine02", "dst_label": "Eth1"}
- {"src": "leaf02", "src_label": "Eth2", "dst": "spine02", "dst_label": "Eth2"}
- {"src": "leaf03", "src_label": "Eth2", "dst": "spine02", "dst_label": "Eth3"}
- {"src": "leaf04", "src_label": "Eth2", "dst": "spine02", "dst_label": "Eth4"}
To create a topology from the example above simply run the following command
eve-ng lab create-from-topology -t examples/test_topology.yml --template-dir examples/templates
By default, the configuration tool searches for templates in templates directory, but you can use --template-dir as shown above to specify another location.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file eve-ng-0.2.7.tar.gz.
File metadata
- Download URL: eve-ng-0.2.7.tar.gz
- Upload date:
- Size: 41.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f778591ad7aa620d3b41302d8db742f63cc2aac015338cf7e1fd7268f8c2dc2
|
|
| MD5 |
520666c3e747676478fd9a70c209b5db
|
|
| BLAKE2b-256 |
35b0766daf75b63d3e3f72d6eaafe0c5261ff60c22aa050a168a3c10c36c5706
|
File details
Details for the file eve_ng-0.2.7-py3-none-any.whl.
File metadata
- Download URL: eve_ng-0.2.7-py3-none-any.whl
- Upload date:
- Size: 53.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6c1269581fa70d7874f9f50261a204ea19b1c9002e5d7c553dd21f490ec64f4
|
|
| MD5 |
1d17e456c948012a28d96052d6e5d3c8
|
|
| BLAKE2b-256 |
51e581010881fa26a4ac7540cc2c89fc06a0064b9abfd11b014755b1e16a6c37
|