From 49ef728295fc8f1be05ee8c6d664a8e81de20261 Mon Sep 17 00:00:00 2001 From: Vladimir Prusakov Date: Sun, 21 Jan 2024 10:37:27 +0200 Subject: [PATCH] examples --- README.rst | 7 +----- docs/fortigateapi/FortiGate.rst | 11 +++++++- docs/fortigateapi/FortiGateAPI.rst | 11 +++++++- docs/fortigateapi/cmdb/firewall/address.rst | 28 ++++++++++++++++++--- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/README.rst b/README.rst index 36583c2b..54613df5 100644 --- a/README.rst +++ b/README.rst @@ -50,13 +50,10 @@ or from github.com repository - Delete address from the Fortigate """ - import logging from pprint import pprint from fortigate_api import FortiGateAPI - logging.getLogger().setLevel(logging.DEBUG) - HOST = "host" USERNAME = "username" PASSWORD = "password" @@ -114,13 +111,10 @@ or from github.com repository - Delete address from the Fortigate """ - import logging from pprint import pprint from fortigate_api import FortiGate - logging.getLogger().setLevel(logging.DEBUG) - HOST = "host" USERNAME = "username" PASSWORD = "password" @@ -160,6 +154,7 @@ or from github.com repository fgt.logout() + ---------------------------------------------------------------------------------------- .. _`Read the Docs`: https://fortigate-api.readthedocs.io/en/latest/ \ No newline at end of file diff --git a/docs/fortigateapi/FortiGate.rst b/docs/fortigateapi/FortiGate.rst index ab12b34d..a4d76fc6 100644 --- a/docs/fortigateapi/FortiGate.rst +++ b/docs/fortigateapi/FortiGate.rst @@ -12,6 +12,7 @@ Usage """FortiGate examples. + - Initialize FortiGate with optional parameters scheme=`https`, port=443 - FortiGate.post() - Create fortigate-object in the Fortigate - FortiGate.get() - GetResponse object from the Fortigate - FortiGate.get_results() - Get list of fortigate-objects from the JSON results section @@ -35,7 +36,15 @@ Usage USERNAME = "username" PASSWORD = "password" - fgt = FortiGate(host=HOST, username=USERNAME, password=PASSWORD, logging_error=True) + # Initialize FortiGate with optional parameters scheme=`https`, port=443 + fgt = FortiGate( + host=HOST, + username=USERNAME, + password=PASSWORD, + scheme="https", + port=443, + logging_error=True, + ) fgt.login() # login is optional # FortiGate.post() - Create fortigate-object in the Fortigate diff --git a/docs/fortigateapi/FortiGateAPI.rst b/docs/fortigateapi/FortiGateAPI.rst index 11a3b659..8c8e2565 100644 --- a/docs/fortigateapi/FortiGateAPI.rst +++ b/docs/fortigateapi/FortiGateAPI.rst @@ -12,6 +12,7 @@ Usage """FortiGateAPI examples. + - Initialize FortiGateAPI with optional parameters scheme=`https`, port=443 - Create address in the Fortigate - Get address by name (unique identifier) - Update address data in the Fortigate @@ -30,7 +31,15 @@ Usage USERNAME = "username" PASSWORD = "password" - api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD, logging_error=True) + # Initialize FortiGateAPI with optional parameters scheme=`https`, port=443 + api = FortiGateAPI( + host=HOST, + username=USERNAME, + password=PASSWORD, + scheme="https", + port=443, + logging_error=True, + ) api.login() # login is optional # Create address in the Fortigate diff --git a/docs/fortigateapi/cmdb/firewall/address.rst b/docs/fortigateapi/cmdb/firewall/address.rst index 7bd89865..22acefb6 100644 --- a/docs/fortigateapi/cmdb/firewall/address.rst +++ b/docs/fortigateapi/cmdb/firewall/address.rst @@ -15,7 +15,7 @@ Usage """api/v2/cmdb/firewall/address - - Create address in the Fortigate + - Create address in the Fortigate, in the default vdom root - Get all addresses from the Fortigate vdom root - Format output data to return only required key values - Get address by name (unique identifier) @@ -27,7 +27,11 @@ Usage - Delete address from the Fortigate by name (unique identifier) - Delete addresses from the Fortigate by filter - Check for absence of address in the Fortigate - - Get all addresses from the vdom + + VDOM + - Create address in the Fortigate, in the custom vdom + - Get all addresses from the custom vdom + - Delete addresses from the custom vdom """ import logging @@ -44,7 +48,7 @@ Usage api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD, logging_error=True) api.login() # login is optional - # Create address in the Fortigate + # Create address in the Fortigate, in the default vdom root data = { "name": "ADDRESS", "obj-type": "ip", @@ -113,11 +117,27 @@ Usage api.logout() - # Get all addresses from the vdom="VDOM9" + # VDOM + # Create address in the Fortigate, in the custom vdom api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD, vdom="VDOM9") + 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 custom vdom + items = api.cmdb.firewall.address.get() print(f"addresses count={len(items)}") # addresses count=10 + # Delete addresses from the custom vdom + response = api.cmdb.firewall.address.delete("ADDRESS") + print(f"address.delete {response}") # address.delete + api.logout()