forked from networktocode/netutils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into prep1.5.0
- Loading branch information
Showing
54 changed files
with
3,890 additions
and
1,505 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
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
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,5 @@ | ||
# OS Version | ||
|
||
::: netutils.os_version | ||
options: | ||
show_submodules: True |
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
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
mkdocs==1.3.1 | ||
mkdocs==1.4.3 | ||
# Material for MkDocs theme | ||
mkdocs-material==8.3.9 | ||
mkdocs-material==8.5.8 | ||
# Render custom markdown for version added/changed/remove notes | ||
mkdocs-version-annotations==1.0.0 | ||
# Automatic documentation from sources, for MkDocs | ||
mkdocstrings==0.19 | ||
mkdocstrings-python==0.7.1 | ||
mkdocstrings==0.22.0 | ||
mkdocstrings-python==1.1.2 |
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
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
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
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
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
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 |
---|---|---|
@@ -1,9 +1,7 @@ | ||
"""Initialization file for library.""" | ||
|
||
try: | ||
from importlib import metadata # type: ignore[attr-defined] | ||
except ImportError: | ||
# Python version < 3.8 | ||
import importlib_metadata as metadata # type: ignore[no-redef] | ||
|
||
from importlib import metadata | ||
|
||
|
||
__version__ = metadata.version(__name__) |
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
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,94 @@ | ||
"""Configuration conversion methods for different network operating systems.""" | ||
|
||
import typing as t | ||
|
||
from netutils.config.utils import _open_file_config | ||
|
||
conversion_map: t.Dict[str, t.List[str]] = { | ||
"paloalto_panos": ["paloalto_panos_brace_to_set"], | ||
} | ||
|
||
|
||
def paloalto_panos_brace_to_set(cfg: str, cfg_type: str = "file") -> str: | ||
r"""Convert Palo Alto Brace format configuration to set format. | ||
Args: | ||
cfg: Configuration as a string | ||
cfg_type: A string that is effectively a choice between `file` and `string`. Defaults to `file`. | ||
Returns: | ||
str: Converted configuration as a string. | ||
Examples: | ||
>>> config = ''' | ||
... config { | ||
... mgt-config { | ||
... users { | ||
... admin { | ||
... phash *; | ||
... permissions { | ||
... role-based { | ||
... superuser yes; | ||
... } | ||
... } | ||
... public-key thisisasuperduperlongbase64encodedstring; | ||
... } | ||
... panadmin { | ||
... permissions { | ||
... role-based { | ||
... superuser yes; | ||
... } | ||
... } | ||
... phash passwordhash; | ||
... } | ||
... } | ||
... } | ||
... }''' | ||
>>> paloalto_panos_brace_to_set(cfg=config, cfg_type='string') == \ | ||
... '''set mgt-config users admin phash * | ||
... set mgt-config users admin permissions role-based superuser yes | ||
... set mgt-config users admin public-key thisisasuperduperlongbase64encodedstring | ||
... set mgt-config users panadmin permissions role-based superuser yes | ||
... set mgt-config users panadmin phash passwordhash''' | ||
True | ||
""" | ||
stack: t.List[str] = [] | ||
cfg_value: t.List[str] = [] | ||
cfg_string: str = "" | ||
|
||
if cfg_type not in ["file", "string"]: | ||
raise ValueError("The variable `cfg_type` must be either `file` or `string`.") | ||
if cfg_type == "file": | ||
cfg_list = _open_file_config(cfg).splitlines() | ||
else: | ||
cfg_list = cfg.splitlines() | ||
|
||
for i, line in enumerate(cfg_list): | ||
line = line.strip() | ||
if line.endswith(";") and not line.endswith('";'): | ||
line = line.split(";", 1)[0] | ||
line = "".join(str(s) for s in stack) + line | ||
line = line.split("config ", 1)[1] | ||
line = "set " + line | ||
cfg_value.append(line.strip()) | ||
elif line.endswith('login-banner "') or line.endswith('content "'): | ||
_first_banner_line = "".join(str(s) for s in stack) + line | ||
cfg_value.append("set " + _first_banner_line.split("config ", 1)[1]) | ||
|
||
for banner_line in cfg_list[i + 1:]: # fmt: skip | ||
if '"' in banner_line: | ||
banner_line = banner_line.split(";", 1)[0] | ||
cfg_value.append(banner_line.strip()) | ||
break | ||
cfg_value.append(banner_line.strip()) | ||
elif line.endswith("{"): | ||
stack.append(line[:-1]) | ||
elif line == "}" and len(stack) > 0: | ||
stack.pop() | ||
|
||
for _l, _line in enumerate(cfg_value): | ||
cfg_string += _line | ||
if _l < len(cfg_value) - 1: | ||
cfg_string += "\n" | ||
|
||
return cfg_string |
Oops, something went wrong.