networka 0.1.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- network_toolkit/__about__.py +4 -0
- network_toolkit/__init__.py +8 -0
- network_toolkit/__main__.py +10 -0
- network_toolkit/builtin_sequences/arista_eos/common.yml +53 -0
- network_toolkit/builtin_sequences/mikrotik_routeros/common.yml +52 -0
- network_toolkit/cli.py +265 -0
- network_toolkit/commands/__init__.py +8 -0
- network_toolkit/commands/backup.py +441 -0
- network_toolkit/commands/complete.py +172 -0
- network_toolkit/commands/config.py +1068 -0
- network_toolkit/commands/diff.py +485 -0
- network_toolkit/commands/download.py +197 -0
- network_toolkit/commands/firmware.py +780 -0
- network_toolkit/commands/info.py +377 -0
- network_toolkit/commands/list.py +345 -0
- network_toolkit/commands/routerboard_upgrade.py +204 -0
- network_toolkit/commands/run.py +839 -0
- network_toolkit/commands/schema_unified.py +91 -0
- network_toolkit/commands/sequence.py +17 -0
- network_toolkit/commands/ssh.py +540 -0
- network_toolkit/commands/ssh_engines.py +0 -0
- network_toolkit/commands/ssh_fallback.py +97 -0
- network_toolkit/commands/ssh_platform.py +120 -0
- network_toolkit/commands/upload.py +237 -0
- network_toolkit/commands/vendor_config_backup.py +378 -0
- network_toolkit/common/color_magic.py +177 -0
- network_toolkit/common/command.py +135 -0
- network_toolkit/common/command_base.py +135 -0
- network_toolkit/common/command_helpers.py +214 -0
- network_toolkit/common/credentials.py +86 -0
- network_toolkit/common/defaults.py +17 -0
- network_toolkit/common/errors.py +130 -0
- network_toolkit/common/interactive_confirmation.py +144 -0
- network_toolkit/common/logging.py +47 -0
- network_toolkit/common/output.py +594 -0
- network_toolkit/common/output_clean.py +244 -0
- network_toolkit/common/paths.py +86 -0
- network_toolkit/common/resolver.py +207 -0
- network_toolkit/common/styles.py +199 -0
- network_toolkit/common/table_generator.py +169 -0
- network_toolkit/common/table_providers.py +716 -0
- network_toolkit/config.py +1506 -0
- network_toolkit/credentials.py +288 -0
- network_toolkit/device.py +1658 -0
- network_toolkit/device_transfers.py +170 -0
- network_toolkit/exceptions.py +78 -0
- network_toolkit/ip_device.py +241 -0
- network_toolkit/platforms/__init__.py +21 -0
- network_toolkit/platforms/base.py +267 -0
- network_toolkit/platforms/cisco_ios/__init__.py +6 -0
- network_toolkit/platforms/cisco_ios/constants.py +15 -0
- network_toolkit/platforms/cisco_ios/operations.py +426 -0
- network_toolkit/platforms/cisco_iosxe/__init__.py +6 -0
- network_toolkit/platforms/cisco_iosxe/constants.py +15 -0
- network_toolkit/platforms/cisco_iosxe/operations.py +580 -0
- network_toolkit/platforms/cisco_shared/__init__.py +0 -0
- network_toolkit/platforms/cisco_shared/operations.py +0 -0
- network_toolkit/platforms/factory.py +190 -0
- network_toolkit/platforms/mikrotik_routeros/__init__.py +8 -0
- network_toolkit/platforms/mikrotik_routeros/confirmation_patterns.py +24 -0
- network_toolkit/platforms/mikrotik_routeros/constants.py +31 -0
- network_toolkit/platforms/mikrotik_routeros/operations.py +686 -0
- network_toolkit/results_enhanced.py +364 -0
- network_toolkit/schemas/__init__.py +8 -0
- network_toolkit/sequence_manager.py +239 -0
- network_toolkit/shell_completion/bash_completion_nw.sh +339 -0
- network_toolkit/shell_completion/zsh_completion_nw.zsh +136 -0
- network_toolkit/transport/__init__.py +15 -0
- network_toolkit/transport/factory.py +113 -0
- network_toolkit/transport/interfaces.py +46 -0
- network_toolkit/transport/nornir_inventory.py +173 -0
- network_toolkit/transport/nornir_netmiko.py +277 -0
- network_toolkit/transport/scrapli_sync.py +36 -0
- network_toolkit/tui/__init__.py +18 -0
- network_toolkit/tui/app.py +1275 -0
- network_toolkit/tui/clipboard.py +46 -0
- network_toolkit/tui/compat.py +111 -0
- network_toolkit/tui/constants.py +111 -0
- network_toolkit/tui/controller.py +550 -0
- network_toolkit/tui/data.py +149 -0
- network_toolkit/tui/dialogs.py +196 -0
- network_toolkit/tui/helpers.py +55 -0
- network_toolkit/tui/keymap.py +31 -0
- network_toolkit/tui/layout.py +111 -0
- network_toolkit/tui/models.py +93 -0
- network_toolkit/tui/output_manager.py +372 -0
- network_toolkit/tui/prompt.py +172 -0
- network_toolkit/tui/services.py +285 -0
- networka-0.1.9.dist-info/METADATA +316 -0
- networka-0.1.9.dist-info/RECORD +93 -0
- networka-0.1.9.dist-info/WHEEL +4 -0
- networka-0.1.9.dist-info/entry_points.txt +2 -0
- networka-0.1.9.dist-info/licenses/LICENSE +73 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"""TUI services layer.
|
|
2
|
+
|
|
3
|
+
Contains logic for resolving devices, building execution plans, and running
|
|
4
|
+
commands while streaming output via callbacks. This module is UI-framework
|
|
5
|
+
agnostic so it can be unit-tested without Textual.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import asyncio
|
|
11
|
+
import logging
|
|
12
|
+
import threading
|
|
13
|
+
from collections.abc import Iterable
|
|
14
|
+
|
|
15
|
+
from pydantic import BaseModel, ConfigDict
|
|
16
|
+
|
|
17
|
+
from network_toolkit.common.resolver import DeviceResolver
|
|
18
|
+
from network_toolkit.tui.data import TuiData
|
|
19
|
+
from network_toolkit.tui.models import (
|
|
20
|
+
CancellationToken,
|
|
21
|
+
ExecutionPlan,
|
|
22
|
+
RunCallbacks,
|
|
23
|
+
RunResult,
|
|
24
|
+
iter_commands,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class DeviceRunResult(BaseModel):
|
|
29
|
+
model_config = ConfigDict(frozen=True)
|
|
30
|
+
device: str
|
|
31
|
+
ok: bool
|
|
32
|
+
output_lines: list[str]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ExecutionService:
|
|
36
|
+
"""Build plans and execute them with concurrency and streaming output.
|
|
37
|
+
|
|
38
|
+
Cancellation semantics:
|
|
39
|
+
- Cooperative: ongoing device tasks periodically check the provided
|
|
40
|
+
``CancellationToken`` and bail between commands.
|
|
41
|
+
- Bounded scheduling: only up to ``concurrency`` devices are scheduled at
|
|
42
|
+
a time. When cancelled, we stop scheduling new devices so at most
|
|
43
|
+
``concurrency`` device tasks remain to finish.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def __init__(self, data: TuiData, *, concurrency: int = 5) -> None:
|
|
47
|
+
self._data = data
|
|
48
|
+
self._concurrency = max(1, int(concurrency))
|
|
49
|
+
self._sem = asyncio.Semaphore(self._concurrency)
|
|
50
|
+
# Track active sessions for hard-cancel support
|
|
51
|
+
self._active_sessions: set[object] = set()
|
|
52
|
+
self._active_lock = threading.Lock()
|
|
53
|
+
|
|
54
|
+
# --- Hard-cancel support
|
|
55
|
+
def _register_session(self, session: object) -> None:
|
|
56
|
+
try:
|
|
57
|
+
with self._active_lock:
|
|
58
|
+
self._active_sessions.add(session)
|
|
59
|
+
except Exception:
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
def _unregister_session(self, session: object) -> None:
|
|
63
|
+
try:
|
|
64
|
+
with self._active_lock:
|
|
65
|
+
self._active_sessions.discard(session)
|
|
66
|
+
except Exception:
|
|
67
|
+
pass
|
|
68
|
+
|
|
69
|
+
def request_hard_cancel(self, cancel: CancellationToken | None = None) -> None:
|
|
70
|
+
"""Aggressively cancel by setting the token and closing active sessions.
|
|
71
|
+
|
|
72
|
+
This will cause blocking reads/writes to error out and unwind quickly.
|
|
73
|
+
Note: it does not revert server-side operations already in progress.
|
|
74
|
+
"""
|
|
75
|
+
try:
|
|
76
|
+
if cancel is not None:
|
|
77
|
+
cancel.set()
|
|
78
|
+
except Exception:
|
|
79
|
+
pass
|
|
80
|
+
sessions: list[object]
|
|
81
|
+
try:
|
|
82
|
+
with self._active_lock:
|
|
83
|
+
sessions = list(self._active_sessions)
|
|
84
|
+
except Exception:
|
|
85
|
+
sessions = []
|
|
86
|
+
for s in sessions:
|
|
87
|
+
try:
|
|
88
|
+
disc = getattr(s, "disconnect", None)
|
|
89
|
+
if callable(disc):
|
|
90
|
+
disc()
|
|
91
|
+
except Exception as e:
|
|
92
|
+
logging.debug(f"Hard cancel disconnect failed: {e}")
|
|
93
|
+
|
|
94
|
+
def resolve_devices(
|
|
95
|
+
self, devices: Iterable[str], groups: Iterable[str]
|
|
96
|
+
) -> list[str]:
|
|
97
|
+
"""Resolve devices and expand groups using the project's resolver."""
|
|
98
|
+
resolver = DeviceResolver(self._data.config)
|
|
99
|
+
selected: set[str] = set(devices)
|
|
100
|
+
for g in groups:
|
|
101
|
+
try:
|
|
102
|
+
for m in self._data.config.get_group_members(g):
|
|
103
|
+
selected.add(m)
|
|
104
|
+
except Exception:
|
|
105
|
+
# Best-effort, groups may be invalid during development
|
|
106
|
+
logging.debug("Failed to expand group %s", g)
|
|
107
|
+
return [d for d in sorted(selected) if resolver.is_device(d)]
|
|
108
|
+
|
|
109
|
+
def build_plan(
|
|
110
|
+
self, devices: Iterable[str], sequences: Iterable[str], command_text: str
|
|
111
|
+
) -> ExecutionPlan:
|
|
112
|
+
plan: ExecutionPlan = {}
|
|
113
|
+
seqs = list(sequences)
|
|
114
|
+
if seqs:
|
|
115
|
+
for device in devices:
|
|
116
|
+
cmds: list[str] = []
|
|
117
|
+
for seq in sorted(seqs):
|
|
118
|
+
resolved = self._data.sequence_manager.resolve(seq, device) or []
|
|
119
|
+
cmds.extend(resolved)
|
|
120
|
+
if cmds:
|
|
121
|
+
plan[device] = cmds
|
|
122
|
+
else:
|
|
123
|
+
commands = list(iter_commands(command_text))
|
|
124
|
+
if commands:
|
|
125
|
+
for device in devices:
|
|
126
|
+
plan[device] = commands
|
|
127
|
+
return plan
|
|
128
|
+
|
|
129
|
+
async def run_plan(
|
|
130
|
+
self,
|
|
131
|
+
plan: ExecutionPlan,
|
|
132
|
+
cb: RunCallbacks,
|
|
133
|
+
*,
|
|
134
|
+
cancel: CancellationToken | None = None,
|
|
135
|
+
) -> RunResult:
|
|
136
|
+
total = len(plan)
|
|
137
|
+
completed = 0
|
|
138
|
+
successes = 0
|
|
139
|
+
failures = 0
|
|
140
|
+
results_by_device: dict[str, DeviceRunResult] = {}
|
|
141
|
+
|
|
142
|
+
# If cancellation was requested before any work starts, record per-device
|
|
143
|
+
# cancelled results and return immediately.
|
|
144
|
+
if cancel and cancel.is_set():
|
|
145
|
+
for dev in plan.keys():
|
|
146
|
+
try:
|
|
147
|
+
cb.on_meta(f"{dev}: cancelled before start")
|
|
148
|
+
except Exception:
|
|
149
|
+
pass
|
|
150
|
+
results_by_device[dev] = DeviceRunResult(
|
|
151
|
+
device=dev,
|
|
152
|
+
ok=False,
|
|
153
|
+
output_lines=[f"{dev}: cancelled before start"],
|
|
154
|
+
)
|
|
155
|
+
failures += 1
|
|
156
|
+
# Do not emit buffered outputs on pre-start cancel; return summary only
|
|
157
|
+
return RunResult(total=total, successes=successes, failures=failures)
|
|
158
|
+
|
|
159
|
+
async def run_device(device: str, commands: list[str]) -> DeviceRunResult:
|
|
160
|
+
async with self._sem:
|
|
161
|
+
if cancel and cancel.is_set():
|
|
162
|
+
# Inform callbacks that we cancelled this device before starting
|
|
163
|
+
try:
|
|
164
|
+
cb.on_meta(f"{device}: cancelled before start")
|
|
165
|
+
except Exception:
|
|
166
|
+
pass
|
|
167
|
+
return DeviceRunResult(
|
|
168
|
+
device=device,
|
|
169
|
+
ok=False,
|
|
170
|
+
output_lines=[f"{device}: cancelled before start"],
|
|
171
|
+
)
|
|
172
|
+
# Call into blocking runner, accommodating older test monkeypatches
|
|
173
|
+
from typing import Any, cast
|
|
174
|
+
|
|
175
|
+
def _invoke() -> Any:
|
|
176
|
+
try:
|
|
177
|
+
return self._run_device_blocking(device, commands, cb, cancel)
|
|
178
|
+
except TypeError:
|
|
179
|
+
# Back-compat for tests that monkeypatch a 3-param function
|
|
180
|
+
return self._run_device_blocking(device, commands, cb)
|
|
181
|
+
|
|
182
|
+
result = await asyncio.to_thread(_invoke)
|
|
183
|
+
# _run_device_blocking may return DeviceRunResult (new) or bool (tests)
|
|
184
|
+
if hasattr(result, "device") and hasattr(result, "output_lines"):
|
|
185
|
+
return cast(DeviceRunResult, result)
|
|
186
|
+
return DeviceRunResult(device=device, ok=bool(result), output_lines=[])
|
|
187
|
+
|
|
188
|
+
# Schedule lazily up to concurrency; stop scheduling once cancelled
|
|
189
|
+
items = list(plan.items())
|
|
190
|
+
idx = 0
|
|
191
|
+
active: set[asyncio.Task[DeviceRunResult]] = set()
|
|
192
|
+
|
|
193
|
+
def _schedule_next() -> None:
|
|
194
|
+
nonlocal idx
|
|
195
|
+
while (
|
|
196
|
+
idx < len(items)
|
|
197
|
+
and len(active) < self._concurrency
|
|
198
|
+
and not (cancel and cancel.is_set())
|
|
199
|
+
):
|
|
200
|
+
dev, cmds = items[idx]
|
|
201
|
+
idx += 1
|
|
202
|
+
active.add(asyncio.create_task(run_device(dev, cmds)))
|
|
203
|
+
|
|
204
|
+
_schedule_next()
|
|
205
|
+
while active:
|
|
206
|
+
done, pending = await asyncio.wait(
|
|
207
|
+
active, return_when=asyncio.FIRST_COMPLETED
|
|
208
|
+
)
|
|
209
|
+
for t in done:
|
|
210
|
+
try:
|
|
211
|
+
res = t.result()
|
|
212
|
+
except Exception as e:
|
|
213
|
+
# Treat unexpected task failure as a device failure
|
|
214
|
+
failures += 1
|
|
215
|
+
logging.debug("device task failed: %s", e)
|
|
216
|
+
continue
|
|
217
|
+
completed += 1
|
|
218
|
+
if res.ok:
|
|
219
|
+
successes += 1
|
|
220
|
+
else:
|
|
221
|
+
failures += 1
|
|
222
|
+
results_by_device[res.device] = res
|
|
223
|
+
cb.on_meta(f"progress: {completed}/{total}")
|
|
224
|
+
active = set(pending)
|
|
225
|
+
if cancel and cancel.is_set():
|
|
226
|
+
cb.on_meta("cancellation requested; stopping scheduling")
|
|
227
|
+
# Do not schedule any new work; allow current active tasks to finish
|
|
228
|
+
else:
|
|
229
|
+
_schedule_next()
|
|
230
|
+
# Emit any buffered outputs from tasks that didn't stream directly
|
|
231
|
+
for dev in plan.keys():
|
|
232
|
+
r = results_by_device.get(dev)
|
|
233
|
+
if not r:
|
|
234
|
+
continue
|
|
235
|
+
for line in r.output_lines:
|
|
236
|
+
cb.on_output(line)
|
|
237
|
+
return RunResult(total=total, successes=successes, failures=failures)
|
|
238
|
+
|
|
239
|
+
def _run_device_blocking(
|
|
240
|
+
self,
|
|
241
|
+
device: str,
|
|
242
|
+
commands: list[str],
|
|
243
|
+
cb: RunCallbacks,
|
|
244
|
+
cancel: CancellationToken | None = None,
|
|
245
|
+
) -> DeviceRunResult:
|
|
246
|
+
ok = True
|
|
247
|
+
# Collect output lines for return (not emitted here); we stream per-command chunks
|
|
248
|
+
buf: list[str] = []
|
|
249
|
+
try:
|
|
250
|
+
# Import here to avoid making CLI a hard dependency of module import
|
|
251
|
+
from network_toolkit.cli import DeviceSession
|
|
252
|
+
|
|
253
|
+
cb.on_meta(f"{device}: connecting...")
|
|
254
|
+
if cancel and cancel.is_set():
|
|
255
|
+
cb.on_meta(f"{device}: cancelled before connect")
|
|
256
|
+
return DeviceRunResult(device=device, ok=False, output_lines=buf)
|
|
257
|
+
with DeviceSession(device, self._data.config) as session:
|
|
258
|
+
# Make this session visible for hard-cancel
|
|
259
|
+
try:
|
|
260
|
+
self._register_session(session)
|
|
261
|
+
except Exception:
|
|
262
|
+
pass
|
|
263
|
+
cb.on_meta(f"{device}: connected")
|
|
264
|
+
for cmd in commands:
|
|
265
|
+
if cancel and cancel.is_set():
|
|
266
|
+
cb.on_meta(f"{device}: cancelled")
|
|
267
|
+
ok = False
|
|
268
|
+
break
|
|
269
|
+
# Execute command and process output
|
|
270
|
+
cb.on_meta(f"{device}$ {cmd}")
|
|
271
|
+
try:
|
|
272
|
+
text = session.execute_command(cmd)
|
|
273
|
+
out_strip = text.strip()
|
|
274
|
+
if out_strip:
|
|
275
|
+
for line in text.rstrip().splitlines():
|
|
276
|
+
cb.on_output(line)
|
|
277
|
+
except Exception as e:
|
|
278
|
+
ok = False
|
|
279
|
+
cb.on_error(f"{device}: command error: {e}")
|
|
280
|
+
cb.on_meta(f"{device}: done")
|
|
281
|
+
except Exception as e:
|
|
282
|
+
ok = False
|
|
283
|
+
cb.on_error(f"{device}: Failed: {e}")
|
|
284
|
+
# Return whatever we collected (may be empty) on failure
|
|
285
|
+
return DeviceRunResult(device=device, ok=ok, output_lines=[])
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: networka
|
|
3
|
+
Version: 0.1.9
|
|
4
|
+
Summary: Modern async Python toolkit for network device automation
|
|
5
|
+
Project-URL: Homepage, https://github.com/narrowin/networka
|
|
6
|
+
Project-URL: Documentation, https://narrowin.github.io/networka/
|
|
7
|
+
Project-URL: Repository, https://github.com/narrowin/networka.git
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/narrowin/networka/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/narrowin/networka/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Source Code, https://github.com/narrowin/networka
|
|
11
|
+
Project-URL: CI/CD, https://github.com/narrowin/networka/actions
|
|
12
|
+
Author-email: narrowin <contact@narrowin.com>
|
|
13
|
+
Maintainer-email: narrowin <contact@narrowin.com>
|
|
14
|
+
License: Apache-2.0
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Keywords: async,automation,cli,infrastructure,mikrotik,narrowin,network,networking,routeros
|
|
17
|
+
Classifier: Development Status :: 4 - Beta
|
|
18
|
+
Classifier: Environment :: Console
|
|
19
|
+
Classifier: Intended Audience :: Developers
|
|
20
|
+
Classifier: Intended Audience :: System Administrators
|
|
21
|
+
Classifier: Intended Audience :: Telecommunications Industry
|
|
22
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
23
|
+
Classifier: Operating System :: MacOS
|
|
24
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
25
|
+
Classifier: Operating System :: OS Independent
|
|
26
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
27
|
+
Classifier: Programming Language :: Python :: 3
|
|
28
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
29
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
30
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
31
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
32
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
33
|
+
Classifier: Topic :: System :: Networking
|
|
34
|
+
Classifier: Topic :: System :: Systems Administration
|
|
35
|
+
Classifier: Topic :: Utilities
|
|
36
|
+
Classifier: Typing :: Typed
|
|
37
|
+
Requires-Python: >=3.11
|
|
38
|
+
Requires-Dist: asyncssh>=2.21.0
|
|
39
|
+
Requires-Dist: libtmux>=0.46.2
|
|
40
|
+
Requires-Dist: pydantic>=2.5.0
|
|
41
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
42
|
+
Requires-Dist: pyyaml>=6.0
|
|
43
|
+
Requires-Dist: rich>=13.0.0
|
|
44
|
+
Requires-Dist: scrapli-community>=2025.1.30
|
|
45
|
+
Requires-Dist: scrapli[community]>=2023.7.30
|
|
46
|
+
Requires-Dist: scrapli[paramiko]>=2023.7.30
|
|
47
|
+
Requires-Dist: textual>=0.58.0
|
|
48
|
+
Requires-Dist: typer>=0.12.0
|
|
49
|
+
Provides-Extra: dev
|
|
50
|
+
Requires-Dist: bandit>=1.7.0; extra == 'dev'
|
|
51
|
+
Requires-Dist: build>=0.10.0; extra == 'dev'
|
|
52
|
+
Requires-Dist: cffconvert>=2.0.0; extra == 'dev'
|
|
53
|
+
Requires-Dist: detect-secrets>=1.4.0; extra == 'dev'
|
|
54
|
+
Requires-Dist: mypy>=1.7.0; extra == 'dev'
|
|
55
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
56
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
|
|
57
|
+
Requires-Dist: pytest-mock>=3.14.0; extra == 'dev'
|
|
58
|
+
Requires-Dist: pytest-xdist>=3.8.0; extra == 'dev'
|
|
59
|
+
Requires-Dist: pytest>=7.4.0; extra == 'dev'
|
|
60
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
61
|
+
Requires-Dist: twine>=4.0.0; extra == 'dev'
|
|
62
|
+
Requires-Dist: types-paramiko>=3.0.0; extra == 'dev'
|
|
63
|
+
Requires-Dist: types-pyyaml>=6.0.0; extra == 'dev'
|
|
64
|
+
Provides-Extra: docs
|
|
65
|
+
Requires-Dist: mkdocs-click>=0.9.0; extra == 'docs'
|
|
66
|
+
Requires-Dist: mkdocs-material>=9.0.0; extra == 'docs'
|
|
67
|
+
Requires-Dist: mkdocs>=1.5.0; extra == 'docs'
|
|
68
|
+
Requires-Dist: mkdocstrings[python]>=0.24.0; extra == 'docs'
|
|
69
|
+
Provides-Extra: tmux
|
|
70
|
+
Requires-Dist: libtmux>=0.21.0; extra == 'tmux'
|
|
71
|
+
Description-Content-Type: text/markdown
|
|
72
|
+
|
|
73
|
+
<div align="center"><img src="https://raw.githubusercontent.com/narrowin/networka/main/docs/assets/images/networka.png" alt="Networka Logo" width="320"/>
|
|
74
|
+
|
|
75
|
+
<p><a href="https://narrowin.github.io/networka/">Full documentation →</a></p>
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
<br/>
|
|
79
|
+
|
|
80
|
+
**Networka: `Eierlegende Wollmilchsau` of network operations — optimized for your daily workflows.**
|
|
81
|
+
|
|
82
|
+
[](https://www.python.org/downloads/)
|
|
83
|
+
[](https://github.com/narrowin/networka)
|
|
84
|
+
[](https://www.apache.org/licenses/LICENSE-2.0)
|
|
85
|
+
[](https://github.com/astral-sh/ruff)
|
|
86
|
+
[](http://mypy-lang.org/)
|
|
87
|
+
[](https://github.com/narrowin/networka/actions/workflows/ci.yml)
|
|
88
|
+
[](https://narrowin.github.io/networka/)
|
|
89
|
+
|
|
90
|
+
Networka is a modern async CLI tool for automating network devices across multiple vendors. Built with async/await patterns for high performance and reliability. Designed for network engineers who want fast, scalable automation with full cross-platform support.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## _The Networka Monologue_
|
|
95
|
+
|
|
96
|
+
_“People ask the question…_ <br>
|
|
97
|
+
**what’s a Networka?** <br>
|
|
98
|
+
|
|
99
|
+
And I tell 'em — <br>
|
|
100
|
+
it's **not** about cables, configs, and pings. <br>
|
|
101
|
+
_Oh no._ <br>
|
|
102
|
+
There’s more to it than that, my friend. <br>
|
|
103
|
+
|
|
104
|
+
We all like a bit of the good life — <br>
|
|
105
|
+
some the uptime, some the security, <br>
|
|
106
|
+
others the automation, the visibility, or the compliance. <br>
|
|
107
|
+
|
|
108
|
+
But a **Networka**, oh, they're different. <br>
|
|
109
|
+
Why? <br>
|
|
110
|
+
Because a real **Networka** wants the f\*ing lot.”<br><br>
|
|
111
|
+
(inspired by: [RockNRolla](https://www.youtube.com/watch?v=s4YLBqMJYOo))
|
|
112
|
+
|
|
113
|
+
## Getting Started
|
|
114
|
+
|
|
115
|
+
- Installation: see the docs → https://narrowin.github.io/networka/getting-started/
|
|
116
|
+
- Platform compatibility → https://narrowin.github.io/networka/platform-compatibility/
|
|
117
|
+
- Shell completion → https://narrowin.github.io/networka/shell-completion/
|
|
118
|
+
- CLI reference → https://narrowin.github.io/networka/reference/cli/
|
|
119
|
+
- API reference → https://narrowin.github.io/networka/reference/api/
|
|
120
|
+
|
|
121
|
+
## Features
|
|
122
|
+
|
|
123
|
+
### **Core Capabilities**
|
|
124
|
+
|
|
125
|
+
- **Multi-vendor network automation**: Native support for MikroTik RouterOS, Cisco IOS/IOS-XE/NX-OS, Arista EOS, Juniper JunOS, and more
|
|
126
|
+
- **Scalable device management**: Execute commands across individual devices or groups concurrently with async/await architecture
|
|
127
|
+
- **Cross-platform compatibility**: Full support for Linux, macOS, and Windows environments
|
|
128
|
+
- **Flexible configuration**: YAML and CSV configuration options with powerful device tagging and grouping
|
|
129
|
+
|
|
130
|
+
### **Operational Features**
|
|
131
|
+
|
|
132
|
+
- **Command execution**: Run single commands or predefined sequences across devices and groups
|
|
133
|
+
- **File management**: Upload/download files to/from network devices with verification and error handling
|
|
134
|
+
- **Device backup**: Automated configuration and comprehensive backups with vendor-specific implementations
|
|
135
|
+
- **Firmware management**: Upgrade, downgrade, and BIOS operations with platform validation
|
|
136
|
+
- **SSH session management**: Direct SSH access with tmux integration for interactive sessions
|
|
137
|
+
|
|
138
|
+
### **Advanced Features**
|
|
139
|
+
|
|
140
|
+
- **Intelligent completions**: Context-aware shell completions for devices, groups, and sequences
|
|
141
|
+
- **Vendor-aware sequences**: Predefined command sets optimized for different network platforms
|
|
142
|
+
- **Results management**: Organized storage with multiple output formats and automatic timestamping
|
|
143
|
+
- **Configuration validation**: Schema-based validation with detailed error reporting
|
|
144
|
+
- **Credential management**: Secure credential handling via environment variables with device-specific overrides
|
|
145
|
+
|
|
146
|
+
### **Developer & Integration Features**
|
|
147
|
+
|
|
148
|
+
- **Type safety**: Full mypy type checking for reliability and maintainability
|
|
149
|
+
- **Modern architecture**: Built with async/await patterns for high performance
|
|
150
|
+
- **Extensible design**: Plugin-friendly architecture for adding new vendors and operations
|
|
151
|
+
- **Rich output**: Professional CLI interface with color coding and structured information display
|
|
152
|
+
|
|
153
|
+
## Installation
|
|
154
|
+
|
|
155
|
+
### System Requirements
|
|
156
|
+
|
|
157
|
+
- **Operating System**: Linux, macOS, or Windows
|
|
158
|
+
- **Python**: 3.11, 3.12, or 3.13
|
|
159
|
+
- **Network Access**: SSH connectivity to target devices
|
|
160
|
+
- **Package Manager**: uv (recommended) or pip
|
|
161
|
+
|
|
162
|
+
### Quick Install (recommended)
|
|
163
|
+
|
|
164
|
+
Not on PyPI yet — install from GitHub.
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# Recommended (isolated, user-wide)
|
|
168
|
+
uv tool install git+https://github.com/narrowin/networka.git
|
|
169
|
+
|
|
170
|
+
# Alternative
|
|
171
|
+
pipx install git+https://github.com/narrowin/networka.git
|
|
172
|
+
|
|
173
|
+
# Verify installation
|
|
174
|
+
nw --help
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
#### If `nw` is not found
|
|
178
|
+
|
|
179
|
+
- Check: `command -v nw` (Linux/macOS) or `where nw` (Windows)
|
|
180
|
+
- If using pipx: ensure PATH is set, then reload shell
|
|
181
|
+
```bash
|
|
182
|
+
pipx ensurepath
|
|
183
|
+
exec $SHELL
|
|
184
|
+
```
|
|
185
|
+
- Linux/macOS: add user bin to PATH if needed
|
|
186
|
+
```bash
|
|
187
|
+
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc # or ~/.zshrc
|
|
188
|
+
exec $SHELL
|
|
189
|
+
```
|
|
190
|
+
- Windows (native, best-effort): prefer WSL2; if native, run `pipx ensurepath` and restart the terminal
|
|
191
|
+
|
|
192
|
+
More → PATH troubleshooting: https://narrowin.github.io/networka/troubleshooting/#path-nw-not-found
|
|
193
|
+
|
|
194
|
+
### Upgrade & Remove
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
# Upgrade to latest version (from GitHub)
|
|
198
|
+
uv tool install --force git+https://github.com/narrowin/networka.git
|
|
199
|
+
# or
|
|
200
|
+
pipx install --force git+https://github.com/narrowin/networka.git
|
|
201
|
+
|
|
202
|
+
# Remove installation
|
|
203
|
+
uv tool uninstall nw
|
|
204
|
+
# or
|
|
205
|
+
pipx uninstall networka
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Platform-Specific Notes
|
|
209
|
+
|
|
210
|
+
**Linux/macOS**: No additional dependencies required
|
|
211
|
+
|
|
212
|
+
**Windows**: Scrapli (the default transport) does not officially support native Windows. While it may work with Paramiko or ssh2-python drivers, the recommended approach is to run Networka on WSL2 (Ubuntu) for a fully supported POSIX environment. Native Windows usage is best-effort.
|
|
213
|
+
|
|
214
|
+
WSL2 quickstart (recommended):
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# In Ubuntu on WSL2
|
|
218
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
219
|
+
exec $SHELL
|
|
220
|
+
uv tool install git+https://github.com/narrowin/networka.git
|
|
221
|
+
nw --help
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Details → https://narrowin.github.io/networka/platform-compatibility/#wsl2-quickstart-recommended
|
|
225
|
+
|
|
226
|
+
## Quick Start
|
|
227
|
+
|
|
228
|
+
Get up and running with config init command:
|
|
229
|
+
|
|
230
|
+
````bash
|
|
231
|
+
# Initialize in default location with interactive prompts
|
|
232
|
+
nw config init
|
|
233
|
+
|
|
234
|
+
````
|
|
235
|
+
|
|
236
|
+
### One-liners (no config)
|
|
237
|
+
|
|
238
|
+
Run directly against an IP without creating files. `--platform` selects the network OS driver; `--interactive-auth` prompts for credentials.
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
# MikroTik RouterOS
|
|
242
|
+
nw run --platform mikrotik_routeros 192.0.2.10 "/system/identity/print" --interactive-auth
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
# Cisco IOS-XE
|
|
247
|
+
nw run --platform cisco_iosxe 198.51.100.20 "show version" --interactive-auth
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Terminology: device_type vs hardware platform vs transport
|
|
251
|
+
|
|
252
|
+
- device_type: Network OS driver used for connections and commands (Scrapli "platform"). Examples: mikrotik_routeros, cisco_iosxe, arista_eos, juniper_junos.
|
|
253
|
+
- platform (hardware/firmware): Hardware architecture used for firmware-related operations (x86, x86_64, arm, mipsbe, tile).
|
|
254
|
+
- transport: Connection backend. Default is scrapli.
|
|
255
|
+
|
|
256
|
+
Note: When targeting IPs directly, `--platform` refers to the network driver (device_type), not hardware architecture.
|
|
257
|
+
|
|
258
|
+
## Quick links
|
|
259
|
+
|
|
260
|
+
- Getting started → https://narrowin.github.io/networka/getting-started/
|
|
261
|
+
- Running commands → https://narrowin.github.io/networka/running-commands/
|
|
262
|
+
- Configuration → https://narrowin.github.io/networka/configuration/
|
|
263
|
+
- Environment variables → https://narrowin.github.io/networka/environment-variables/
|
|
264
|
+
- Results → https://narrowin.github.io/networka/results/
|
|
265
|
+
- Output modes → https://narrowin.github.io/networka/output-modes/
|
|
266
|
+
- Backups → https://narrowin.github.io/networka/backups/
|
|
267
|
+
- CLI reference → https://narrowin.github.io/networka/reference/cli/
|
|
268
|
+
- API reference → https://narrowin.github.io/networka/reference/api/
|
|
269
|
+
|
|
270
|
+
## CLI overview
|
|
271
|
+
|
|
272
|
+
- For current usage and commands, see the CLI reference:
|
|
273
|
+
- https://narrowin.github.io/networka/reference/cli/
|
|
274
|
+
- Quick checks: `nw --help` and `nw --version`
|
|
275
|
+
|
|
276
|
+
## Community & support
|
|
277
|
+
|
|
278
|
+
- Visit our [documentation](https://narrowin.github.io/networka/) for detailed guides and examples
|
|
279
|
+
- Create [GitHub Issues](https://github.com/narrowin/networka/issues) for bug reports and feature requests
|
|
280
|
+
- See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines
|
|
281
|
+
- Check [SECURITY.md](SECURITY.md) for security policy and reporting vulnerabilities
|
|
282
|
+
|
|
283
|
+
## Contributing
|
|
284
|
+
|
|
285
|
+
Have a look through existing [Issues](https://github.com/narrowin/networka/issues) and [Pull Requests](https://github.com/narrowin/networka/pulls) that you could help with. If you'd like to request a feature or report a bug, please create a GitHub Issue using one of the templates provided.
|
|
286
|
+
|
|
287
|
+
[See contribution guide →](CONTRIBUTING.md)
|
|
288
|
+
|
|
289
|
+
## Documentation
|
|
290
|
+
|
|
291
|
+
- Docs Home → https://narrowin.github.io/networka/
|
|
292
|
+
- Platform Compatibility → https://narrowin.github.io/networka/platform-compatibility/
|
|
293
|
+
- Development Guide → https://narrowin.github.io/networka/development/
|
|
294
|
+
- Multi-Vendor Support → https://narrowin.github.io/networka/multi-vendor-support/
|
|
295
|
+
- IP Address Support → https://narrowin.github.io/networka/ip-address-support/
|
|
296
|
+
- Transport Selection → https://narrowin.github.io/networka/transport/
|
|
297
|
+
- Environment Variables → https://narrowin.github.io/networka/environment-variables/
|
|
298
|
+
- File Upload Guide → https://narrowin.github.io/networka/file_upload/
|
|
299
|
+
- Interactive Credentials → https://narrowin.github.io/networka/interactive-credentials/
|
|
300
|
+
|
|
301
|
+
## License
|
|
302
|
+
|
|
303
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
|
|
304
|
+
|
|
305
|
+
## Acknowledgments
|
|
306
|
+
|
|
307
|
+
- [Scrapli](https://github.com/carlmontanari/scrapli) - Network device connections
|
|
308
|
+
- [Nornir](https://github.com/nornir-automation/nornir) - Network automation framework
|
|
309
|
+
- [Netmiko](https://github.com/ktbyers/netmiko) - Multi-vendor CLI connections to network devices
|
|
310
|
+
- [Typer](https://github.com/tiangolo/typer) - CLI framework
|
|
311
|
+
- [Pydantic](https://github.com/pydantic/pydantic) - Data validation
|
|
312
|
+
- [Rich](https://github.com/Textualize/rich) - Terminal formatting
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
_Built for network engineers who value clean, reliable automation_
|