Skip to content

Commit 609affb

Browse files
author
vprusakovs
committed
0.2.2 (2022-05-23)
------------------ * [change] Fortigate.login() - return: Fortigate (before was Session) * [new] FortigateAPI.vdom - Gets the ability to change the vdom in the same session
1 parent 2ed087c commit 609affb

File tree

20 files changed

+313
-271
lines changed

20 files changed

+313
-271
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
CHANGELOG
44
=========
55

6-
0.2.1 (2022-05-21)
6+
0.2.2 (2022-05-23)
7+
------------------
8+
* [change] Fortigate.login() - return: Fortigate (before was Session)
9+
* [new] FortigateAPI.vdom - Gets the ability to change the vdom in the same session
10+
11+
0.2.2 (2022-05-21)
712
------------------
813
* [change] README.nd changed to README.rst
914
* [change] renamed unique identifier "name" and "id" replaced to "uid"

README.rst

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -237,26 +237,27 @@ Examples - Address
237237
# Updates address data in the Fortigate
238238
data = dict(name="ADDRESS", subnet="127.0.0.255 255.255.255.255", color=6)
239239
response = fgt.address.update(uid="ADDRESS", data=data)
240-
print("address.update", response) # address.update <Response [200]>
240+
print("address.update", response, response.ok) # address.update <Response [200]> True
241241
242242
# Checks for presence of address in the Fortigate
243243
response = fgt.address.is_exist(uid="ADDRESS")
244244
print("address.is_exist", response) # address.is_exist True
245245
246246
# Deletes address from Fortigate by name
247247
response = fgt.address.delete(uid="ADDRESS")
248-
print("address.delete", response) # address.delete <Response [200]>
248+
print("address.delete", response, response.ok) # address.delete <Response [200]> True
249249
250-
# Deletes addresses from Fortigate by filter
250+
# Deletes addresses from Fortigate by filter (address was deleted before)
251251
response = fgt.address.delete(filter="name=@ADDRESS")
252-
print("address.delete", response) # address.delete <Response [200]>
252+
print("address.delete", response, response.ok) # address.delete <Response [500]> False
253253
254254
# Checks for absence of address in the Fortigate
255255
response = fgt.address.is_exist(uid="ADDRESS")
256256
print("address.is_exist", response) # address.is_exist False
257257
258258
fgt.logout()
259259
260+
260261
AddressGroup
261262
------------
262263
FortiOS v6.4 data example `./examples/address_group.yml`_
@@ -505,7 +506,7 @@ Examples - Interface
505506
- Filters interface by multiple conditions
506507
- Updates interface data in the Fortigate
507508
- Checks for presence of interface in the Fortigate
508-
- Gets all interfaces in vdom "vdom2"
509+
- Gets all interfaces in vdom "VDOM"
509510

510511
.. code:: python
511512
@@ -552,10 +553,15 @@ Examples - Interface
552553
response = fgt.interface.is_exist(uid="dmz")
553554
print("interface.is_exist", response) # interface.is_exist True
554555
555-
# Gets all interfaces in vdom "vdom2"
556-
fgt = FortigateAPI(host="host", username="username", password="password", vdom="vdom2")
556+
# Changes virtual domain to "VDOM" and gets all interfaces inside this vdom
557+
fgt.fgt.vdom = "VDOM"
558+
print(f"{fgt!r}")
559+
# Fortigate(host='host', username='username', password='********', vdom='VDOM')
557560
interfaces = fgt.interface.get()
558561
print("interfaces count", len(interfaces)) # interfaces count 0
562+
fgt.vdom = "root"
563+
print(f"{fgt!r}")
564+
# Fortigate(host='host', username='username', password='********')
559565
560566
fgt.logout()
561567
@@ -774,21 +780,20 @@ Examples - Policy
774780
for address in addresses:
775781
if address["name"] in dstaddr:
776782
policies.append(policy)
777-
pprint(policies)
778783
print("policies count", len(policies)) # policies count 2
779784
780785
# Moves policy to top
781786
neighbor = fgt.policy.get()[0]
782787
response = fgt.policy.move(uid=policyid, position="before", neighbor=neighbor["policyid"])
783-
print("policy.move", response) # policy.move <Response [200]>
788+
print("policy.move", response, response.ok) # policy.move <Response [200]> False
784789
785790
# Deletes policy from Fortigate by policyid (unique identifier)
786791
response = fgt.policy.delete(uid=policyid)
787-
print("policy.delete", response) # policy.delete <Response [200]>
792+
print("policy.delete", response, response.ok) # policy.delete <Response [200]> True
788793
789794
# Deletes policies from Fortigate by filter (by name)
790795
response = fgt.policy.delete(filter="name==POLICY")
791-
print("policy.delete", response) # policy.delete <Response [200]>
796+
print("policy.delete", response, response.ok) # policy.delete <Response [200]> True
792797
793798
# Checks for absence of policy in the Fortigate
794799
response = fgt.policy.is_exist(uid=policyid)
@@ -803,6 +808,7 @@ Examples - Policy extended filter
803808
- Gets the rules where source addresses are in subnets of 127.0.1.0/24
804809
- Gets the rules where source prefixes are supernets of address 127.0.1.1/32
805810
- Gets the rules where source prefix are equals 127.0.1.0/30 and destination prefix are equals 127.0.2.0/30
811+
- Delete policy, address-group, addresses from Fortigate (order is important)
806812

807813
.. code:: python
808814
@@ -813,21 +819,21 @@ Examples - Policy extended filter
813819
fgt.login()
814820
815821
# Creates address and address_groupin the Fortigate
816-
data = {"name": f"ADDRESS1",
822+
data = {"name": "ADDRESS1",
817823
"obj-type": "ip",
818-
"subnet": f"127.0.1.0 255.255.255.252",
824+
"subnet": "127.0.1.0 255.255.255.252",
819825
"type": "ipmask"}
820826
response = fgt.address.create(data=data)
821-
print("address create", response) # post <Response [200]>
822-
data = {"name": f"ADDRESS2",
827+
print("address.create", response) # post <Response [200]>
828+
data = {"name": "ADDRESS2",
823829
"obj-type": "ip",
824-
"subnet": f"127.0.2.0 255.255.255.252",
830+
"subnet": "127.0.2.0 255.255.255.252",
825831
"type": "ipmask"}
826832
response = fgt.address.create(data=data)
827-
print("address create", response) # post <Response [200]>
833+
print("address.create", response) # post <Response [200]>
828834
data = {"name": "ADDR_GROUP", "member": [{"name": "ADDRESS2"}]}
829835
response = fgt.address_group.create(data=data)
830-
print("post", response) # post <Response [200]>
836+
print("address_group.create", response) # post <Response [200]>
831837
832838
# Creates policy in the Fortigate
833839
data = dict(
@@ -842,7 +848,7 @@ Examples - Policy extended filter
842848
schedule="always",
843849
)
844850
response = fgt.policy.create(data=data)
845-
print("post", response) # post <Response [200]>
851+
print("policy.create", response) # post <Response [200]>
846852
847853
# Gets the rules where source prefix is equals 127.0.1.0/30
848854
efilter = "srcaddr==127.0.1.0/30"
@@ -867,10 +873,24 @@ Examples - Policy extended filter
867873
# Gets the rules where source prefix are equals 127.0.1.0/30 and destination prefix are equals 127.0.2.0/30
868874
efilters = ["srcaddr==127.0.1.0/30", "dstaddr==127.0.2.0/30"]
869875
policies = fgt.policy.get(efilter=efilters)
870-
print(f"{efilters=}", len(policies)) # efilters=['srcaddr==127.0.1.0/30', 'dstaddr==127.0.2.0/30'] 1
876+
print(f"{efilters=}",
877+
len(policies)) # efilters=['srcaddr==127.0.1.0/30', 'dstaddr==127.0.2.0/30'] 1
878+
879+
# Delete policy, address-group, addresses from Fortigate (order is important)
880+
response = fgt.address.delete(uid="ADDRESS1")
881+
print("address.delete", response.ok) # address.delete <Response [200]>
882+
response = fgt.policy.delete(filter="name==POLICY")
883+
print("policy.delete", response.ok) # policy.delete <Response [200]>
884+
response = fgt.address_group.delete(uid="ADDR_GROUP")
885+
print("address_group.delete", response.ok) # address_group.delete <Response [200]>
886+
response = fgt.address.delete(uid="ADDRESS1")
887+
print("address.delete", response.ok) # address.delete <Response [200]>
888+
response = fgt.address.delete(uid="ADDRESS2")
889+
print("address.delete", response.ok) # address.delete <Response [200]>
871890
872891
fgt.logout()
873892
893+
874894
Schedule
875895
--------
876896
**Schedule** object has the same parameters and methods as `Address`_
@@ -1106,8 +1126,7 @@ Examples - Fortigate
11061126
"subnet": "127.0.0.100 255.255.255.252",
11071127
"type": "ipmask"}
11081128
response = fgt.post(url="api/v2/cmdb/firewall/address/", data=data)
1109-
print("post", response)
1110-
# post <Response [200]>
1129+
print("post", response) # post <Response [200]>
11111130
11121131
# Gets address data from Fortigate
11131132
addresses = fgt.get(url="api/v2/cmdb/firewall/address/")
@@ -1123,27 +1142,22 @@ Examples - Fortigate
11231142
# Update address data in the Fortigate
11241143
data = dict(subnet="127.0.0.255 255.255.255.255")
11251144
response = fgt.put(url="api/v2/cmdb/firewall/address/ADDRESS", data=data)
1126-
print("put", response)
1127-
# put <Response [200]>
1145+
print("put", response) # put <Response [200]>
11281146
addresses = fgt.get(url="api/v2/cmdb/firewall/address/")
11291147
addresses = [d for d in addresses if d["name"] == "ADDRESS"]
1130-
print(addresses[0]["subnet"])
1131-
# 127.0.0.255 255.255.255.255
1148+
print(addresses[0]["subnet"]) # 127.0.0.255 255.255.255.255
11321149
11331150
# Checks for presence of address in the Fortigate
11341151
response = fgt.exist(url="api/v2/cmdb/firewall/address/ADDRESS")
1135-
print("exist", response)
1136-
# <Response [200]>
1152+
print("exist", response) # <Response [200]>
11371153
11381154
# Deletes address from Fortigate
11391155
response = fgt.delete(url="api/v2/cmdb/firewall/address/ADDRESS")
1140-
print("delete", response)
1141-
# <Response [200]>
1156+
print("delete", response) # <Response [200]>
11421157
11431158
# Checks for absence of address in the Fortigate
11441159
response = fgt.exist(url="api/v2/cmdb/firewall/address/ADDRESS")
1145-
print("exist", response)
1146-
# <Response [404]>
1160+
print("exist", response) # <Response [404]>
11471161
11481162
fgt.logout()
11491163

__init__.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
11
"""fortigate-api"""
22

3-
from requests import Session
4-
53
from fortigate_api.fortigate import Fortigate
6-
from fortigate_api.address import Address
7-
from fortigate_api.address_group import AddressGroup
8-
from fortigate_api.antivirus import Antivirus
9-
from fortigate_api.application import Application
10-
from fortigate_api.interface import Interface
11-
from fortigate_api.internet_service import InternetService
12-
from fortigate_api.ip_pool import IpPool
13-
from fortigate_api.policy import Policy
14-
from fortigate_api.schedule import Schedule
15-
from fortigate_api.service import Service
16-
from fortigate_api.service_category import ServiceCategory
17-
from fortigate_api.service_group import ServiceGroup
18-
from fortigate_api.snmp_community import SnmpCommunity
19-
from fortigate_api.virtual_ip import VirtualIP
20-
from fortigate_api.zone import Zone
4+
from fortigate_api.fortigate_api import FortigateAPI

0 commit comments

Comments
 (0)