|
8 | 8 | - Filter interface by multiple conditions |
9 | 9 | - Update interface data in the Fortigate |
10 | 10 | - Check for presence of interface in the Fortigate |
11 | | -- Get all interfaces in vdom "VDOM" |
| 11 | +- Change virtual domain to VDOM and get all interfaces of this virtual domain |
| 12 | +- Change virtual domain to root and get all interfaces of this virtual domain |
| 13 | +- Get all interfaces in all virtual domains (root and VDOM) |
12 | 14 | """ |
13 | 15 |
|
14 | 16 | import logging |
|
25 | 27 | fgt = FortigateAPI(host=HOST, username=USERNAME, password=PASSWORD) |
26 | 28 | fgt.login() |
27 | 29 |
|
28 | | -print("\nGets all interfaces in vdom \"root\" from the Fortigate") |
| 30 | +print("\nGet all interfaces in vdom \"root\" from the Fortigate") |
29 | 31 | interfaces = fgt.interface.get() |
30 | 32 | print(f"interfaces count={len(interfaces)}") # interfaces count=21 |
31 | 33 |
|
32 | | -print("\nGets filtered interface by name (unique identifier)") |
| 34 | +print("\nGet filtered interface by name (unique identifier)") |
33 | 35 | interfaces = fgt.interface.get(uid="dmz") |
34 | 36 | pprint(interfaces) |
35 | 37 | # [{"name": "dmz", |
36 | 38 | # "ip": "0.0.0.0 0.0.0.0", |
37 | 39 | # ... |
38 | 40 | # }] |
39 | 41 |
|
40 | | -print("\nFilters interface by operator equals \"==\"") |
| 42 | +print("\nFilter interface by operator equals \"==\"") |
41 | 43 | interfaces = fgt.interface.get(filter="name==dmz") |
42 | 44 | print(f"interfaces count={len(interfaces)}") # interfaces count=1 |
43 | 45 |
|
44 | | -print("\nFilters interface by operator contains \"=@\"") |
| 46 | +print("\nFilter interface by operator contains \"=@\"") |
45 | 47 | interfaces = fgt.interface.get(filter="name=@wan") |
46 | 48 | print(f"interfaces count={len(interfaces)}") # interfaces count=2 |
47 | 49 |
|
48 | | -print("\nFilters interface by operator not equals \"!=\"") |
| 50 | +print("\nFilter interface by operator not equals \"!=\"") |
49 | 51 | interfaces = fgt.interface.get(filter="name!=dmz") |
50 | 52 | print(f"interfaces count={len(interfaces)}") # interfaces count=20 |
51 | 53 |
|
52 | | -print("\nFilters interface by multiple conditions") |
| 54 | +print("\nFilter interface by multiple conditions") |
53 | 55 | interfaces = fgt.interface.get(filter=["allowaccess=@ping", "detectprotocol==ping"]) |
54 | 56 | print(f"interfaces count={len(interfaces)}") # interfaces count=8 |
55 | 57 |
|
56 | | -print("\nUpdates interface data in the Fortigate") |
| 58 | +print("\nUpdate interface data in the Fortigate") |
57 | 59 | data = dict(name="dmz", description="dmz") |
58 | 60 | response = fgt.interface.update(uid="dmz", data=data) |
59 | 61 | print("interface.update", response) # interface.update <Response [200]> |
60 | 62 |
|
61 | | -print("\nChecks for presence of interface in the Fortigate") |
| 63 | +print("\nCheck for presence of interface in the Fortigate") |
62 | 64 | response = fgt.interface.is_exist(uid="dmz") |
63 | 65 | print("interface.is_exist", response) # interface.is_exist True |
64 | 66 |
|
65 | | -print("\nChanges virtual domain to \"VDOM\" and gets all interfaces inside this vdom") |
| 67 | +# Interfaces in virtual domains |
| 68 | + |
| 69 | +print("\nChange virtual domain to VDOM and get all interfaces of this virtual domain") |
66 | 70 | fgt.rest.vdom = "VDOM" |
67 | | -print(f"{fgt!r}") # Fortigate(host='host', username='username', password='********', vdom='VDOM') |
| 71 | +print(f"{fgt!r}") # Fortigate(host='host', username='username', vdom='VDOM') |
68 | 72 | print(fgt.vdom) # VDOM |
69 | 73 | interfaces = fgt.interface.get() |
70 | | -print(f"interfaces count={len(interfaces)}") # interfaces count=0 |
| 74 | +print(f"interfaces count={len(interfaces)}") # interfaces count=12 |
71 | 75 |
|
72 | | -print("\nChanges virtual domain to \"root\"") |
| 76 | +print("\nChange virtual domain to root and get all interfaces of this virtual domain") |
73 | 77 | fgt.vdom = "root" |
74 | | -print(f"{fgt!r}") # Fortigate(host='host', username='username', password='********') |
| 78 | +print(f"{fgt!r}") # Fortigate(host='host', username='username') |
75 | 79 | print(fgt.vdom) # root |
| 80 | +interfaces = fgt.interface.get() |
| 81 | +print(f"interfaces count={len(interfaces)}") # interfaces count=31 |
| 82 | + |
| 83 | +print("\nGet all interfaces in all virtual domains (root and VDOM)") |
| 84 | +interfaces = fgt.interface.get(all=True) |
| 85 | +print(f"interfaces count={len(interfaces)}") # interfaces count=43 |
76 | 86 |
|
77 | 87 | fgt.logout() |
0 commit comments