p4net 0.2.0__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.
- p4net/__init__.py +6 -0
- p4net/__main__.py +6 -0
- p4net/cli/__init__.py +13 -0
- p4net/cli/completers.py +46 -0
- p4net/cli/dispatcher.py +940 -0
- p4net/cli/exceptions.py +17 -0
- p4net/cli/formatting.py +56 -0
- p4net/cli/main.py +163 -0
- p4net/cli/shell.py +80 -0
- p4net/compiler/__init__.py +11 -0
- p4net/compiler/exceptions.py +38 -0
- p4net/compiler/p4c.py +284 -0
- p4net/control/__init__.py +82 -0
- p4net/control/client.py +891 -0
- p4net/control/codec.py +237 -0
- p4net/control/exceptions.py +45 -0
- p4net/control/p4info_index.py +360 -0
- p4net/log/__init__.py +0 -0
- p4net/network/__init__.py +20 -0
- p4net/network/_cleanup.py +84 -0
- p4net/network/exceptions.py +21 -0
- p4net/network/nodes.py +201 -0
- p4net/network/orchestrator.py +562 -0
- p4net/runtime/__init__.py +34 -0
- p4net/runtime/bmv2.py +305 -0
- p4net/runtime/exceptions.py +33 -0
- p4net/runtime/link.py +235 -0
- p4net/runtime/netns.py +229 -0
- p4net/runtime/sysctl.py +76 -0
- p4net/runtime/tc.py +122 -0
- p4net/topo/__init__.py +16 -0
- p4net/topo/exceptions.py +9 -0
- p4net/topo/host.py +70 -0
- p4net/topo/link.py +105 -0
- p4net/topo/switch.py +62 -0
- p4net/topo/topology.py +589 -0
- p4net-0.2.0.dist-info/METADATA +149 -0
- p4net-0.2.0.dist-info/RECORD +41 -0
- p4net-0.2.0.dist-info/WHEEL +4 -0
- p4net-0.2.0.dist-info/entry_points.txt +2 -0
- p4net-0.2.0.dist-info/licenses/LICENSE +201 -0
p4net/__init__.py
ADDED
p4net/__main__.py
ADDED
p4net/cli/__init__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Interactive p4net CLI: dispatcher, shell, completer, console script."""
|
|
2
|
+
|
|
3
|
+
from p4net.cli.dispatcher import CommandDispatcher
|
|
4
|
+
from p4net.cli.exceptions import CLIError, CLIExit, CLIUsageError
|
|
5
|
+
from p4net.cli.shell import P4NetShell
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"CLIError",
|
|
9
|
+
"CLIExit",
|
|
10
|
+
"CLIUsageError",
|
|
11
|
+
"CommandDispatcher",
|
|
12
|
+
"P4NetShell",
|
|
13
|
+
]
|
p4net/cli/completers.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""prompt_toolkit completer for the p4net shell."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from prompt_toolkit.completion import NestedCompleter
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from p4net.cli.dispatcher import CommandDispatcher
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def build_network_completer(dispatcher: CommandDispatcher) -> NestedCompleter:
|
|
14
|
+
"""Build a NestedCompleter that knows about commands, hosts, and switches."""
|
|
15
|
+
nested: dict[str, dict[str, None] | None] = {}
|
|
16
|
+
for cmd in dispatcher.command_names:
|
|
17
|
+
nested[cmd] = None
|
|
18
|
+
# `topology` has one sub-verb so far: `graph`.
|
|
19
|
+
if "topology" in nested:
|
|
20
|
+
nested["topology"] = {"graph": None}
|
|
21
|
+
# Host commands: <host> [ping|ping6|cmd|ifconfig|xterm]
|
|
22
|
+
host_subs = _host_subcommands_for(dispatcher)
|
|
23
|
+
for name in dispatcher.host_names:
|
|
24
|
+
nested[name] = dict.fromkeys(host_subs, None)
|
|
25
|
+
# Switch commands.
|
|
26
|
+
for name in dispatcher.switch_names:
|
|
27
|
+
nested[name] = dict.fromkeys(_switch_subcommands_for(dispatcher), None)
|
|
28
|
+
return NestedCompleter.from_nested_dict(nested)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _switch_subcommands_for(dispatcher: CommandDispatcher) -> list[str]:
|
|
32
|
+
"""Read the dispatcher's switch handler keys at completer-build time.
|
|
33
|
+
|
|
34
|
+
Phase-2 ships an empty handler map; phase-3 fills it in. This helper
|
|
35
|
+
keeps the completer in sync without requiring two import paths.
|
|
36
|
+
"""
|
|
37
|
+
# `_switch_handlers` is private but stable; the alternative is duplicating
|
|
38
|
+
# the verb list, which would drift.
|
|
39
|
+
handlers = getattr(dispatcher, "_switch_handlers", {})
|
|
40
|
+
return sorted(handlers.keys())
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _host_subcommands_for(dispatcher: CommandDispatcher) -> list[str]:
|
|
44
|
+
"""Same idea for host verbs."""
|
|
45
|
+
handlers = getattr(dispatcher, "_host_handlers", {})
|
|
46
|
+
return sorted(handlers.keys())
|