Skip to content

Commit

Permalink
examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirs-git committed Jan 21, 2024
1 parent 55806ba commit 49ef728
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
7 changes: 1 addition & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -160,6 +154,7 @@ or from github.com repository
fgt.logout()
----------------------------------------------------------------------------------------

.. _`Read the Docs`: https://fortigate-api.readthedocs.io/en/latest/
11 changes: 10 additions & 1 deletion docs/fortigateapi/FortiGate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion docs/fortigateapi/FortiGateAPI.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
28 changes: 24 additions & 4 deletions docs/fortigateapi/cmdb/firewall/address.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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 <Response [200]>
# 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 <Response [200]>
api.logout()

0 comments on commit 49ef728

Please sign in to comment.