Skip to content

Commit 55806ba

Browse files
committed
examples
1 parent f1a71ad commit 55806ba

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

examples/cmdb/firewall/address.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""api/v2/cmdb/firewall/address
22
3-
- Create address in the Fortigate
3+
- Create address in the Fortigate, in the default vdom root
44
- Get all addresses from the Fortigate vdom root
55
- Format output data to return only required key values
66
- Get address by name (unique identifier)
@@ -12,7 +12,11 @@
1212
- Delete address from the Fortigate by name (unique identifier)
1313
- Delete addresses from the Fortigate by filter
1414
- Check for absence of address in the Fortigate
15-
- Get all addresses from the vdom
15+
16+
VDOM
17+
- Create address in the Fortigate, in the custom vdom
18+
- Get all addresses from the custom vdom
19+
- Delete addresses from the custom vdom
1620
"""
1721

1822
import logging
@@ -29,7 +33,7 @@
2933
api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD, logging_error=True)
3034
api.login() # login is optional
3135

32-
# Create address in the Fortigate
36+
# Create address in the Fortigate, in the default vdom root
3337
data = {
3438
"name": "ADDRESS",
3539
"obj-type": "ip",
@@ -98,9 +102,25 @@
98102

99103
api.logout()
100104

101-
# Get all addresses from the vdom="VDOM9"
105+
# VDOM
106+
# Create address in the Fortigate, in the custom vdom
102107
api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD, vdom="VDOM9")
108+
data = {
109+
"name": "ADDRESS",
110+
"obj-type": "ip",
111+
"subnet": "127.0.0.100 255.255.255.252",
112+
"type": "ipmask",
113+
}
114+
response = api.cmdb.firewall.address.create(data)
115+
print(f"address.create {response}") # address.create <Response [200]>
116+
117+
# Get all addresses from the custom vdom
118+
103119
items = api.cmdb.firewall.address.get()
104120
print(f"addresses count={len(items)}") # addresses count=10
105121

122+
# Delete addresses from the custom vdom
123+
response = api.cmdb.firewall.address.delete("ADDRESS")
124+
print(f"address.delete {response}") # address.delete <Response [200]>
125+
106126
api.logout()

examples/fortigate.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""FortiGate examples.
22
3+
- Initialize FortiGate with optional parameters scheme=`https`, port=443
34
- FortiGate.post() - Create fortigate-object in the Fortigate
45
- FortiGate.get() - GetResponse object from the Fortigate
56
- FortiGate.get_results() - Get list of fortigate-objects from the JSON results section
@@ -23,7 +24,15 @@
2324
USERNAME = "username"
2425
PASSWORD = "password"
2526

26-
fgt = FortiGate(host=HOST, username=USERNAME, password=PASSWORD, logging_error=True)
27+
# Initialize FortiGate with optional parameters scheme=`https`, port=443
28+
fgt = FortiGate(
29+
host=HOST,
30+
username=USERNAME,
31+
password=PASSWORD,
32+
scheme="https",
33+
port=443,
34+
logging_error=True,
35+
)
2736
fgt.login() # login is optional
2837

2938
# FortiGate.post() - Create fortigate-object in the Fortigate

examples/fortigateapi.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""FortiGateAPI examples.
22
3+
- Initialize FortiGateAPI with optional parameters scheme=`https`, port=443
34
- Create address in the Fortigate
45
- Get address by name (unique identifier)
56
- Update address data in the Fortigate
@@ -18,7 +19,15 @@
1819
USERNAME = "username"
1920
PASSWORD = "password"
2021

21-
api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD, logging_error=True)
22+
# Initialize FortiGateAPI with optional parameters scheme=`https`, port=443
23+
api = FortiGateAPI(
24+
host=HOST,
25+
username=USERNAME,
26+
password=PASSWORD,
27+
scheme="https",
28+
port=443,
29+
logging_error=True,
30+
)
2231
api.login() # login is optional
2332

2433
# Create address in the Fortigate

0 commit comments

Comments
 (0)