Skip to content

Commit 49ef728

Browse files
committed
examples
1 parent 55806ba commit 49ef728

File tree

4 files changed

+45
-12
lines changed

4 files changed

+45
-12
lines changed

README.rst

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,10 @@ or from github.com repository
5050
- Delete address from the Fortigate
5151
"""
5252
53-
import logging
5453
from pprint import pprint
5554
5655
from fortigate_api import FortiGateAPI
5756
58-
logging.getLogger().setLevel(logging.DEBUG)
59-
6057
HOST = "host"
6158
USERNAME = "username"
6259
PASSWORD = "password"
@@ -114,13 +111,10 @@ or from github.com repository
114111
- Delete address from the Fortigate
115112
"""
116113
117-
import logging
118114
from pprint import pprint
119115
120116
from fortigate_api import FortiGate
121117
122-
logging.getLogger().setLevel(logging.DEBUG)
123-
124118
HOST = "host"
125119
USERNAME = "username"
126120
PASSWORD = "password"
@@ -160,6 +154,7 @@ or from github.com repository
160154
fgt.logout()
161155
162156
157+
163158
----------------------------------------------------------------------------------------
164159

165160
.. _`Read the Docs`: https://fortigate-api.readthedocs.io/en/latest/

docs/fortigateapi/FortiGate.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Usage
1212
1313
"""FortiGate examples.
1414
15+
- Initialize FortiGate with optional parameters scheme=`https`, port=443
1516
- FortiGate.post() - Create fortigate-object in the Fortigate
1617
- FortiGate.get() - GetResponse object from the Fortigate
1718
- FortiGate.get_results() - Get list of fortigate-objects from the JSON results section
@@ -35,7 +36,15 @@ Usage
3536
USERNAME = "username"
3637
PASSWORD = "password"
3738
38-
fgt = FortiGate(host=HOST, username=USERNAME, password=PASSWORD, logging_error=True)
39+
# Initialize FortiGate with optional parameters scheme=`https`, port=443
40+
fgt = FortiGate(
41+
host=HOST,
42+
username=USERNAME,
43+
password=PASSWORD,
44+
scheme="https",
45+
port=443,
46+
logging_error=True,
47+
)
3948
fgt.login() # login is optional
4049
4150
# FortiGate.post() - Create fortigate-object in the Fortigate

docs/fortigateapi/FortiGateAPI.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Usage
1212
1313
"""FortiGateAPI examples.
1414
15+
- Initialize FortiGateAPI with optional parameters scheme=`https`, port=443
1516
- Create address in the Fortigate
1617
- Get address by name (unique identifier)
1718
- Update address data in the Fortigate
@@ -30,7 +31,15 @@ Usage
3031
USERNAME = "username"
3132
PASSWORD = "password"
3233
33-
api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD, logging_error=True)
34+
# Initialize FortiGateAPI with optional parameters scheme=`https`, port=443
35+
api = FortiGateAPI(
36+
host=HOST,
37+
username=USERNAME,
38+
password=PASSWORD,
39+
scheme="https",
40+
port=443,
41+
logging_error=True,
42+
)
3443
api.login() # login is optional
3544
3645
# Create address in the Fortigate

docs/fortigateapi/cmdb/firewall/address.rst

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Usage
1515
1616
"""api/v2/cmdb/firewall/address
1717
18-
- Create address in the Fortigate
18+
- Create address in the Fortigate, in the default vdom root
1919
- Get all addresses from the Fortigate vdom root
2020
- Format output data to return only required key values
2121
- Get address by name (unique identifier)
@@ -27,7 +27,11 @@ Usage
2727
- Delete address from the Fortigate by name (unique identifier)
2828
- Delete addresses from the Fortigate by filter
2929
- Check for absence of address in the Fortigate
30-
- Get all addresses from the vdom
30+
31+
VDOM
32+
- Create address in the Fortigate, in the custom vdom
33+
- Get all addresses from the custom vdom
34+
- Delete addresses from the custom vdom
3135
"""
3236
3337
import logging
@@ -44,7 +48,7 @@ Usage
4448
api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD, logging_error=True)
4549
api.login() # login is optional
4650
47-
# Create address in the Fortigate
51+
# Create address in the Fortigate, in the default vdom root
4852
data = {
4953
"name": "ADDRESS",
5054
"obj-type": "ip",
@@ -113,11 +117,27 @@ Usage
113117
114118
api.logout()
115119
116-
# Get all addresses from the vdom="VDOM9"
120+
# VDOM
121+
# Create address in the Fortigate, in the custom vdom
117122
api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD, vdom="VDOM9")
123+
data = {
124+
"name": "ADDRESS",
125+
"obj-type": "ip",
126+
"subnet": "127.0.0.100 255.255.255.252",
127+
"type": "ipmask",
128+
}
129+
response = api.cmdb.firewall.address.create(data)
130+
print(f"address.create {response}") # address.create <Response [200]>
131+
132+
# Get all addresses from the custom vdom
133+
118134
items = api.cmdb.firewall.address.get()
119135
print(f"addresses count={len(items)}") # addresses count=10
120136
137+
# Delete addresses from the custom vdom
138+
response = api.cmdb.firewall.address.delete("ADDRESS")
139+
print(f"address.delete {response}") # address.delete <Response [200]>
140+
121141
api.logout()
122142
123143

0 commit comments

Comments
 (0)