FortiGateAPI.cmdb.system.interface

class fortigate_api.cmdb.system.InterfaceSC(fortigate: FortiGate, **kwargs)

Web UI

https://172.16.177.65/ng/interface

API

https://172.16.177.65/api/v2/cmdb/system/interface

Data

cmdb/system/interface

uid: str = 'name'

Unique identifier of fortigate-object.

get(all_vdoms: bool = False, **kwargs) List[Dict[str, Any]]

Get interface-objects in specified vdom, all or filtered by some of params.

Parameters:
  • all_vdoms (bool) – True - get interface-objects of all VDOMs, False - get interface-objects assigned to an initialized VDOM. Default is False.

  • kwargs – Fortigate REST API parameters. filter - Filter fortigate-objects by one or multiple Filtering conditions. More details can be found at https://fndn.fortinet.net for related GET method.

Returns:

List of the interface-objects.

Return type:

List[dict]

create(data: Dict[str, Any]) Response

Create the fortigate-object in the Fortigate.

Parameters:

data (dict) – Data of the fortigate-object. More details can be found at https://fndn.fortinet.net for related POST method.

Returns:

Session response.

  • <Response [200]> Object successfully created,

  • <Response [500]> Object already exists.

Return type:

Response

delete(uid: str | int = '', filter: str | Sequence[str] = '', **kwargs) Response

Delete the fortigate-object from the Fortigate.

Parameters:
  • uid (str or int) – Identifier of the fortigate-object. Used to delete a single object.

  • filter (str or List[str]) – Filter fortigate-objects by one or multiple Filtering conditions. Used to delete multiple objects.

  • kwargs – Fortigate REST API parameters. More details can be found at https://fndn.fortinet.net for related DELETE method.

Returns:

Session response.

  • <Response [200]> Object successfully deleted,

  • <Response [404]> Object not found in the Fortigate.

Return type:

Response

is_exist(uid: str | int) bool

Check if a fortigate-object exists in the Fortigate.

Parameters:

uid (str or int) – Identifier of the fortigate-object.

Returns:

True - object exists, False - object does not exist.

Return type:

bool

update(data: Dict[str, Any]) Response

Update fortigate-object on the Fortigate.

Parameters:

data (dict) – Data of the fortigate-object to update. More details can be found at https://fndn.fortinet.net for related PUT method.

Returns:

Session response.

  • <Response [200]> Object successfully updated,

  • <Response [404]> Object has not been updated.

Return type:

Response

property url: str

URL to the fortigate-object.

Usage

"""api/v2/cmdb/system/interface

- Get all interfaces from the vdom="VDOM9"
- Get all interfaces from the vdom="root"
- Get all interfaces from the all vdoms
- Get filtered interface by name (unique identifier)
- Update interface data in the Fortigate
- Check for presence of interface in the Fortigate
"""

from pprint import pprint

from fortigate_api import FortiGateAPI

HOST = "host"
USERNAME = "username"
PASSWORD = "password"

# Get all interfaces from the vdom="VDOM9"
api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD, vdom="VDOM9")
items = api.cmdb.system.interface.get()
print(f"interfaces count={len(items)}")  # interfaces count=2

# Get all interfaces from the vdom="root"
api.vdom = "root"
items = api.cmdb.system.interface.get()
print(f"interfaces count={len(items)}")  # interfaces count=38

# Get all interfaces from the all vdoms
items = api.cmdb.system.interface.get(all_vdoms=True)
print(f"interfaces count={len(items)}")  # interfaces count=40

# Get filtered interface by name (unique identifier)
items = api.cmdb.system.interface.get(name="dmz")
print(f"interfaces count={len(items)}")  # interfaces count=1
pprint(items)
#  [{"name": "dmz",
#    "ip": "0.0.0.0 0.0.0.0",
#    ...
#    }]

# Filter interface by operator equals `==`
items = api.cmdb.system.interface.get(filter="name==dmz")
print(f"interfaces count={len(items)}")  # interfaces count=1

# Filter interface by operator contains `=@`
items = api.cmdb.system.interface.get(filter="name=@wan")
print(f"interfaces count={len(items)}")  # interfaces count=2

# Filter interface by multiple conditions
items = api.cmdb.system.interface.get(filter=["allowaccess=@ping", "detectprotocol==ping"])
print(f"interfaces count={len(items)}")  # interfaces count=12

# Update interface data in the Fortigate
data = dict(name="dmz", description="dmz")
response = api.cmdb.system.interface.update(data)
print("interface.update", response)  # interface.update <Response [200]>

# Check for presence of interface in the Fortigate
response = api.cmdb.system.interface.is_exist("dmz")
print("interface.is_exist", response)  # interface.is_exist True

api.logout()