File: run.py

package info (click to toggle)
python-scrapli 2023.7.30-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,536 kB
  • sloc: python: 14,459; makefile: 72
file content (41 lines) | stat: -rw-r--r-- 898 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import asyncio
from pathlib import Path
from typing import Optional

from scrapli_replay.server.server import start

import scrapli

TEST_DATA_DIR = f"{Path(scrapli.__file__).parents[1]}/tests/test_data"

SERVERS = [
    ("cisco_iosxe", 2221),
    ("cisco_nxos", 2222),
    ("cisco_iosxr", 2223),
    ("arista_eos", 2224),
    ("juniper_junos", 2225),
]


async def run_servers() -> None:
    await asyncio.gather(
        *[
            start(
                port=server[1],
                collect_data=f"{TEST_DATA_DIR}/mock_server_sessions/{server[0]}.yaml",
            )
            for server in SERVERS
        ]
    )


def sync_run_servers(loop: Optional[asyncio.base_events.BaseEventLoop] = None) -> None:
    if loop is None:
        loop = asyncio.get_event_loop()

    loop.run_until_complete(run_servers())
    loop.run_forever()


if __name__ == "__main__":
    sync_run_servers()