pyfortiztp
Python API client library for Fortinet's FortiZTP.
The FortiZTP Cloud API provides:
- Retrieve provisioning status of FortiGates, FortiAPs, and FortiSwitch.
- Provision or un-provision devices to the cloud or on-premise targets.
Installation
To install run pip install pyfortiztp.
Alternatively, you can clone the repo and run python setup.py install.
Quick Start
To begin, import pyfortiztp and instantiate the API.
We need to provide our API credentials to our FortiCloud account.
Optionally, its possible to set the following settings:
client_idwhich defaults tofortiztp.forticloud_hostwhich defaults tohttps://customerapiauth.fortinet.comfortiztp_hostwhich defaults tohttps://fortiztp.forticloud.com
Code
fortiztp = pyfortiztp.api(
userid = "<your forticloud userid>",
password = "<your forticloud password>"
)
Examples
Retrieve a single device.
Code
device = fortiztp.devices.all(deviceSN="FGT60FTK1234ABCD")
print(device)
Output
{
"deviceSN": "FGT60FTK1234ABCD",
"deviceType": "FortiGate",
"provisionStatus": "unprovisioned",
"provisionTarget": null,
"region": "global,europe,JP,US",
"externalControllerSn": null,
"externalControllerIp": null,
"platform": null
}
Provision one or more devices to FortiManager.
deviceSN is a list of serial numbers. In this example, we only test with a single serial number.
Code
update = fortiztp.devices.update(
deviceSN = ["FGT60FTK1234ABCD"],
deviceType = "FortiGate",
provisionStatus = "provisioned",
provisionTarget = "FortiManager",
externalControllerIp = "<external IP of your fortimanager>",
externalControllerSn = "<serial number of your fortimanager>"
)
print(update)
Output
204
Note: The FortiZTP API returns the HTTP response "204 No Content" on success.
Unprovision one or more devices from FortiManager.
deviceSN is a list of serial numbers. In this example, we only test with a single serial number.
Code
update = fortiztp.devices.update(
deviceSN = ["FGT60FTK1234ABCD"],
deviceType = "FortiGate",
provisionStatus = "unprovisioned",
provisionTarget = "FortiManager",
externalControllerIp = "<external IP of your fortimanager>",
externalControllerSn = "<serial number of your fortimanager>"
)
print(update)
Output
204
Error messages.
Error messages are provided as is, from the FortiZTP API.
Code
update = fortiztp.devices.update(
deviceSN = ["FGT60FTK1234ABCD", "testSN"],
deviceType = "FortiGate",
provisionStatus = "provisioned",
provisionTarget = "FortiManager"
)
print(update)
Output
{
"error": "invalid_request",
"error_description": "Device testSN doesn't exist in this account"
}
Metadata
Release files for pyfortiztp 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyfortiztp-1.0.1.tar.gz | 8.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyfortiztp-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.5 kB
Release files / pyfortiztp-1.0.1.tar.gz
| Download URL | pyfortiztp-1.0.1.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4b8f502c92c4e5bad427a0c1cc12cd71bad71b7807af7fd82acf093bbb3e859a
|
|
BLAKE2b-256 checksum How to use checksums |
1740ca3d88a5fd29f598abb3381d366c4aa471502d4b13ed6b179df6a755ecb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Release files / pyfortiztp-1.0.1-py3-none-any.whl
| Download URL | pyfortiztp-1.0.1-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
239866c988faa4594f509fea016d72c3e8d7e349d5a1f4a4c3d3de6f50275bac
|
|
BLAKE2b-256 checksum How to use checksums |
b757f707002d37c8de17edba01614981f07fc05084064702ab577ca7f256f9e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|