-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
205 changed files
with
7,603 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
max-line-length=165 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
anta_inventory: | ||
hosts: | ||
- host: 192.168.0.10 | ||
- host: 192.168.0.11 | ||
# Optional tag to assign to this device | ||
tags: ['tag01', 'tag02'] | ||
- host: 192.168.0.12 | ||
- host: 192.168.0.13 | ||
- host: 192.168.0.14 | ||
- host: 192.168.0.15 | ||
networks: | ||
- network: '192.168.110.0/24' | ||
# Optional tag to assign to all devices in this subnet | ||
tags: ['tag01', 'tag02'] | ||
ranges: | ||
- start: 10.0.0.9 | ||
end: 10.0.0.11 | ||
# Optional tag to assign to all devices in this range | ||
tags: ['tag01', 'tag02'] | ||
- start: 10.0.0.100 | ||
end: 10.0.0.101 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
anta_inventory: | ||
hosts: | ||
- host: 127.0.0.1 | ||
port: 3431 | ||
name: s1-brdr1 | ||
- host: 127.0.0.1 | ||
port: 3432 | ||
name: s1-brdr2 | ||
- host: 127.0.0.1 | ||
port: 3433 | ||
name: s1-core1 | ||
- host: 127.0.0.1 | ||
port: 3434 | ||
name: s1-core2 | ||
- host: 127.0.0.1 | ||
port: 3435 | ||
name: s1-host1 | ||
- host: 127.0.0.1 | ||
port: 3436 | ||
name: s1-host2 | ||
- host: 127.0.0.1 | ||
port: 3437 | ||
name: s1-leaf1 | ||
- host: 127.0.0.1 | ||
port: 3438 | ||
name: s1-leaf2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export ANTA_USERNAME=arista | ||
export ANTA_PASSWORD=aristan760 | ||
export ANTA_INVENTORY=~/anta/.personal/atd-dual.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export ANTA_USERNAME=arista | ||
export ANTA_PASSWORD=@rista123 | ||
export ANTA_INVENTORY=~/anta/.personal/inv.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
anta_inventory: | ||
hosts: | ||
- host: 10.88.160.141 | ||
name: spine1 | ||
- host: 10.88.160.142 | ||
- host: 10.88.160.143 | ||
name: leaf1 | ||
- host: 10.88.160.144 | ||
name: leaf2 | ||
- host: 10.88.160.145 | ||
name: leaf3 | ||
- host: 10.88.160.146 | ||
name: leaf4 | ||
- host: 10.88.160.147 | ||
- host: 10.88.160.148 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
""" | ||
Example | ||
""" | ||
# This is needed to run the script for python < 3.10 for typing annotations | ||
from __future__ import annotations | ||
|
||
import asyncio | ||
from copy import deepcopy | ||
from pprint import pprint | ||
|
||
from anta.inventory import AntaInventory | ||
from anta.models import AntaCommand | ||
|
||
|
||
async def main_loop(inv: AntaInventory, commands: list[str]) -> dict[str, list[AntaCommand]]: | ||
""" | ||
Take an inventory and a list of commands and: | ||
1. try to connect to every device in the inventory | ||
2. print a message for every device where connection could not be established | ||
3. collect the results of the commands towards each device | ||
Returns: | ||
a dictionary where key is the device name and the value is the list of AntaCommand ran towards the device | ||
""" | ||
await inv.connect_inventory() | ||
|
||
# Print a list of devices that could not be connected to | ||
for device in inv.get_inventory(established_only=False).values(): | ||
if device.established is False: | ||
print(f"Could not connect to device {device.name}") | ||
|
||
# Make a list of coroutine to run commands towards each connected device | ||
coros = [] | ||
# dict to keep track of the commands per device | ||
result_dict = {} | ||
print("DONE") | ||
for name, device in inv.get_inventory(established_only=True).items(): | ||
anta_commands = [AntaCommand(command=command, ofmt="json") for command in commands] | ||
result_dict[name] = anta_commands | ||
coros.append(device.collect_commands(anta_commands)) | ||
|
||
# Run the coroutines | ||
await asyncio.gather(*coros) | ||
|
||
return result_dict | ||
|
||
|
||
if __name__ == "__main__": | ||
# Create the inventory | ||
inventory = AntaInventory.parse( | ||
inventory_file="inv.yml", | ||
username="arista", | ||
password="@rista123", | ||
timeout=15, | ||
) | ||
|
||
# Create a list of commands with json output | ||
commands = ["show version", "show ip bgp summary"] | ||
|
||
# Run the main asyncio entry point | ||
res = asyncio.run(main_loop(inventory, commands)) | ||
|
||
pprint(res) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# testing | ||
|
||
from anta.decorators import skip_on_platforms | ||
from anta.inventory.models import InventoryDevice | ||
from anta.result_manager.models import TestResult | ||
|
||
|
||
@skip_on_platforms(platforms=["cEOSLab"]) # pylint: disable=missing-kwoa | ||
def verify_dummy(device: InventoryDevice) -> TestResult: | ||
""" | ||
dummy test to check decorator | ||
""" | ||
result = TestResult(host=str(device.host), test="verify_dummy") | ||
result.is_success() | ||
return result | ||
|
||
|
||
if __name__ == "__main__": | ||
device1 = InventoryDevice( | ||
host="42.42.42.42", hw_model="7504R", username="a", password="a", url="a" | ||
) | ||
device2 = InventoryDevice( | ||
host="25.25.25.25", hw_model="cEOSLab", username="a", password="a", url="a" | ||
) | ||
|
||
print(verify_dummy(device1)) | ||
print(verify_dummy(device2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
anta.tests.configuration: | ||
- VerifyZeroTouch: | ||
anta.tests.logging: | ||
- VerifyLoggingHosts: | ||
hosts: | ||
- 1.1.1.1 | ||
anta.tests.multicast: | ||
- VerifyIGMPSnoopingGlobal: | ||
configuration: blah |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
anta | ||
anta-310 | ||
3.7.13 | ||
3.9.13 | ||
3.10.3 | ||
3.11.1 |
Binary file not shown.
Oops, something went wrong.