-
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.
- Loading branch information
Showing
35 changed files
with
1,733 additions
and
1 deletion.
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,145 @@ | ||
# Some nornir Ignores | ||
nornir.log | ||
nornir_pyez.egg-info/ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# VSCode Settings | ||
.vscode/ |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Geury Torres | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 +1,160 @@ | ||
# nornir_fgt | ||
# Fortigate Plugin for Nornir | ||
|
||
## Plugins | ||
|
||
Connections - Pyfgt | ||
|
||
## Description | ||
|
||
"This plugin integrates the fortigate-api library with the Nornir framework to simplify and automate configuration tasks on Fortigate devices. Using this plugin, you can easily create, delete, get, and update objects in the Fortigate using REST API and SSH. With commonly used objects already implemented." | ||
|
||
Fortigate-API library - https://github.com/vladimirs-git/fortigate-api | ||
|
||
## Installation | ||
|
||
``` | ||
pip install nornir-pyfgt | ||
``` | ||
|
||
## Read the Documentation | ||
|
||
link goes here | ||
|
||
## Usages | ||
|
||
pyfgt get firewall addresses | ||
|
||
```python | ||
from nornir import InitNornir | ||
from nornir_pyfgt.plugins.tasks import pyfgt_address | ||
from nornir_utils.plugins.functions import print_result | ||
|
||
nr = InitNornir( | ||
config_file="your/config/path" | ||
) | ||
|
||
|
||
results = nr.run(task=pyfgt_address) | ||
|
||
print_result(results) | ||
|
||
``` | ||
|
||
results | ||
|
||
``` | ||
vvvv pyfgt_address ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO | ||
[ { 'allow-routing': 'disable', | ||
'associated-interface': '', | ||
'cache-ttl': 0, | ||
'clearpass-spt': 'unknown', | ||
'color': 0, | ||
'comment': '', | ||
'country': '', | ||
'dirty': 'dirty', | ||
'fabric-object': 'disable', | ||
'filter': '', | ||
'fsso-group': [], | ||
'interface': '', | ||
'list': [], | ||
'macaddr': [], | ||
'name': 'DEMO', | ||
'node-ip-only': 'disable', | ||
'obj-id': '', | ||
'obj-type': 'ip', | ||
'q_origin_key': 'ADDRESS', | ||
'sdn': '', | ||
'sdn-addr-type': 'private', | ||
'sub-type': 'sdn', | ||
'subnet': '10.10.10.10 255.255.255.0', | ||
'tag-detection-level': '', | ||
'tag-type': '', | ||
'tagging': [], | ||
'type': 'ipmask', | ||
'uuid': '0cdb9216-a648-51ed-b43f-238c3b127bc2'}, | ||
... | ||
^^^^ END pyfgt_address ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
``` | ||
|
||
pyfgt get custom URL - Check Fortigate API Documentation for API endpoints | ||
|
||
```python | ||
from nornir import InitNornir | ||
from nornir_utils.plugins.functions import print_result | ||
from nornir_pyfgt.plugins.tasks import pyfgt_get_url | ||
|
||
|
||
nr = InitNornir( | ||
config_file="your/config/path" | ||
) | ||
|
||
|
||
results = nr.run(task=pyfgt_get_url, url="/api/v2/cmdb/user/local") | ||
|
||
print_result(results) | ||
|
||
``` | ||
|
||
results | ||
|
||
``` | ||
vvvv pyfgt_get_url ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO | ||
[ { 'auth-concurrent-override': 'disable', | ||
'auth-concurrent-value': 0, | ||
'authtimeout': 0, | ||
'email-to': '', | ||
'fortitoken': '', | ||
'id': 16777217, | ||
'ldap-server': '', | ||
'name': 'guest', | ||
'passwd': 'ENC XXXX', | ||
'passwd-policy': '', | ||
'passwd-time': '0000-00-00 00:00:00', | ||
'ppk-identity': '', | ||
'ppk-secret': '', | ||
'q_origin_key': 'guest', | ||
'radius-server': '', | ||
'sms-custom-server': '', | ||
'sms-phone': '', | ||
'sms-server': 'fortiguard', | ||
'status': 'enable', | ||
'tacacs+-server': '', | ||
'two-factor': 'disable', | ||
'two-factor-authentication': '', | ||
'two-factor-notification': '', | ||
'type': 'password', | ||
'username-sensitivity': 'enable', | ||
'workstation': ''}] | ||
^^^^ END pyfgt_get_url^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
``` | ||
|
||
pyfgt send SSH command | ||
|
||
```python | ||
from nornir import InitNornir | ||
from nornir_utils.plugins.functions import print_result | ||
from nornir_pyfgt.plugins.tasks import pyfgt_send_command | ||
|
||
|
||
nr = InitNornir( | ||
config_file="your/config/path" | ||
) | ||
|
||
|
||
results = nr.run(task=pyfgt_send_command, command="get system interface") | ||
|
||
print_result(results) | ||
|
||
``` | ||
|
||
results | ||
|
||
``` | ||
vvvv pyfgt_send_command ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO | ||
== [ port1 ] | ||
name: port1 mode: dhcp ip: 192.168.0.158 255.255.255.0 status: up netbios-forward: disable type: physical ring-rx: 0 ring-tx: 0 netflow-sampler: disable sflow-sampler: disable src-check: enable explicit-web-proxy: disable explicit-ftp-proxy: disable proxy-captive-portal: disable mtu-override: disable wccp: disable drop-overlapped-fragment: disable drop-fragment: disable | ||
== [ port2 ] | ||
name: port2 mode: static ip: 0.0.0.0 0.0.0.0 status: up netbios-forward: disable type: physical ring-rx: 0 ring-tx: 0 netflow-sampler: disable sflow-sampler: disable src-check: enable explicit-web-proxy: disable explicit-ftp-proxy: disable proxy-captive-portal: disable mtu-override: disable wccp: disable drop-overlapped-fragment: disable drop-fragment: disable | ||
... | ||
^^^^ END pyfgt_send_command ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
``` |
Empty file.
Empty file.
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,43 @@ | ||
from typing import Any, Dict, Optional | ||
|
||
from fortigate_api import FortigateAPI | ||
|
||
from nornir.core.configuration import Config | ||
|
||
CONNECTION_NAME = "pyfgt" | ||
|
||
|
||
class Pyfgt: | ||
def open( | ||
self, | ||
hostname: Optional[str], | ||
username: Optional[str], | ||
password: Optional[str], | ||
platform: Optional[str], | ||
port: Optional[str] = 22, | ||
scheme: Optional[str] = 'http', | ||
timeout: Optional[int] = 15, | ||
verify: Optional[bool] = False, | ||
vdom: Optional[str] = 'root', | ||
ssh: Optional[Dict[str, Any]] = None, | ||
configuration: Optional[Config] = None, | ||
extras: Optional[Dict[str, Any]] = None, | ||
) -> None: | ||
parameters: Dict[str, Any] = { | ||
"host": hostname, | ||
"username": username, | ||
"password": password, | ||
"port": port, | ||
"ssh": ssh, | ||
"scheme:": scheme, | ||
"timeout": timeout, | ||
"verify": verify, | ||
"vdom": vdom, | ||
} | ||
|
||
connection = FortigateAPI(**parameters) | ||
|
||
self.connection = connection | ||
|
||
def close(self) -> None: | ||
self.connection.logout() |
Oops, something went wrong.