Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vladimirs-git/fortigate-api
Python package for configuring Fortigate (Fortios) devices using REST API
https://github.com/vladimirs-git/fortigate-api
api firewall fortigate fortigate-api fortigate-automation fortigate-firewall fortinet fortios python
Last synced: 2 days ago
JSON representation
Python package for configuring Fortigate (Fortios) devices using REST API
- Host: GitHub
- URL: https://github.com/vladimirs-git/fortigate-api
- Owner: vladimirs-git
- License: apache-2.0
- Created: 2021-11-05T10:37:19.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-12-30T16:18:34.000Z (10 days ago)
- Last Synced: 2024-12-30T16:18:45.123Z (10 days ago)
- Topics: api, firewall, fortigate, fortigate-api, fortigate-automation, fortigate-firewall, fortinet, fortios, python
- Language: Python
- Homepage:
- Size: 3.56 MB
- Stars: 67
- Watchers: 7
- Forks: 20
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- License: LICENSE.txt
Awesome Lists containing this project
README
.. image:: https://img.shields.io/pypi/v/fortigate-api.svg
:target: https://pypi.python.org/pypi/fortigate-api
.. image:: https://img.shields.io/badge/Python-3.8%20%7C%203.9%20%7C%203.10%20%7C%203.11-blue.svg
:target: https://pypi.python.org/pypi/logger-color
.. image:: https://img.shields.io/github/last-commit/vladimirs-git/fortigate-api
:target: https://pypi.python.org/pypi/fortigate-apifortigate-api
=============Python package to configure Fortigate (Fortios) devices using REST API.
- FortiGateAPI - Python connector to Fortigate API endpoints.
- FortiGate - Python wrapper for the FortiOS REST API.Checked with FortiOS = v6.4.14.
Fully documented on `Read the Docs`_.----------------------------------------------------------------------------------------
Requirements
============Python >=3.8,<=3.13
Quickstart
==========Install the package from pypi.org
.. code:: bash
pip install fortigate-api
or from github.com repository
.. code:: bash
pip install git+https://github.com/vladimirs-git/fortigate-api
----------------------------------------------------------------------------------------
.. code:: python
"""Quickstart FortiGateAPI.
- Create address in the Fortigate
- Get all addresses from the Fortigate vdom root
- Get address by name (unique identifier)
- Filter address by operator contains `=@`
- Update address data in the Fortigate
- Delete address from the Fortigate
"""from pprint import pprint
from fortigate_api import FortiGateAPI
HOST = "host"
USERNAME = "username"
PASSWORD = "password"api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD)
# Create address in the Fortigate
data = {
"name": "ADDRESS",
"obj-type": "ip",
"subnet": "127.0.0.100 255.255.255.252",
"type": "ipmask",
}
response = api.cmdb.firewall.address.create(data)
print(f"address.create {response}") # address.create# Get all addresses from the Fortigate vdom root
items = api.cmdb.firewall.address.get()
print(f"All addresses count={len(items)}") # All addresses count=14# Get address by name (unique identifier)
items = api.cmdb.firewall.address.get(name="ADDRESS")
print(f"addresses count={len(items)}") # addresses count=1
pprint(items)
# [{"comment": "",
# "name": "ADDRESS",
# "subnet": "127.0.0.100 255.255.255.252",
# "uuid": "a386e4b0-d6cb-51ec-1e28-01e0bc0de43c",
# ...
# }]# Filter address by operator contains `=@`
items = api.cmdb.firewall.address.get(filter="[email protected]")
print(f"Filtered by `=@`, count={len(items)}") # Filtered by `=@`, count=2# Update address data in the Fortigate
data = {"name": "ADDRESS", "subnet": "127.0.0.255 255.255.255.255"}
response = api.cmdb.firewall.address.update(data)
print(f"address.update {response}") # address.update# Delete address from the Fortigate
response = api.cmdb.firewall.address.delete("ADDRESS")
print(f"address.delete {response}") # address.deleteapi.logout()
.. code:: python
"""Quickstart FortiGate.
- Creates address in the Fortigate
- Get address by name (unique identifier)
- Updates address data in the Fortigate
- Delete address from the Fortigate
"""from pprint import pprint
from fortigate_api import FortiGate
HOST = "host"
USERNAME = "username"
PASSWORD = "password"fgt = FortiGate(host=HOST, username=USERNAME, password=PASSWORD)
# Creates address in the Fortigate
data = {
"name": "ADDRESS",
"obj-type": "ip",
"subnet": "127.0.0.100 255.255.255.252",
"type": "ipmask",
}
response = fgt.post(url="api/v2/cmdb/firewall/address/", data=data)
print(f"POST {response}", ) # POST# Get address by name (unique identifier)
response = fgt.get(url="api/v2/cmdb/firewall/address/ADDRESS")
print(f"GET {response}", ) # POST
result = response.json()["results"]
pprint(result)
# [{"name": "ADDRESS",
# "subnet": "127.0.0.100 255.255.255.252",
# "uuid": "a386e4b0-d6cb-51ec-1e28-01e0bc0de43c",
# ...
# }]# Updates address data in the Fortigate
data = {"name": "ADDRESS", "subnet": "127.0.0.255 255.255.255.255"}
response = fgt.put(url="api/v2/cmdb/firewall/address/ADDRESS", data=data)
print(f"PUT {response}") # PUT# Delete address from the Fortigate
response = fgt.delete(url="api/v2/cmdb/firewall/address/ADDRESS")
print(f"DELETE {response}", ) # DELETEfgt.logout()
----------------------------------------------------------------------------------------
.. _`Read the Docs`: https://fortigate-api.readthedocs.io/en/latest/