FortiGateAPI.cmdb.firewall.ippool

class fortigate_api.cmdb.firewall.IppoolFC(fortigate: FortiGate, **kwargs)

Web UI

https://172.16.177.65/ng/firewall/ip-pool

API

https://172.16.177.65/api/v2/cmdb/firewall/ippool

Data

cmdb/firewall/ippool

uid: str = 'name'

Unique identifier of fortigate-object.

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

get(**kwargs) List[Dict[str, Any]]

Get fortigate-objects, all or filtered by some parameters.

Parameters:

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 fortigate-objects.

Return type:

List[dict]

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/firewall/ippool

- Creates ip-pool in the Fortigate
- Get all ip-pools from the Fortigate vdom root
- Get filtered ip-pools by name (unique identifier)
- Update ip-pool data in the Fortigate
- Delete ip-pool from the Fortigate by name
- Check for presence of ip-pool in the Fortigate
"""

from fortigate_api import FortiGateAPI

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

api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD)

# Creates ip-pool in the Fortigate
data = {"name": "IP_POOL1", "startip": "10.0.0.1", "endip": "10.0.0.2"}
response = api.cmdb.firewall.ippool.create(data)
print("ip-pool.create", response)  # address.create <Response [200]>

# Get all ip-pools from the Fortigate vdom root
items = api.cmdb.firewall.ippool.get()
print(f"ip-pools count={len(items)}")  # ip-pools count=2

# Get filtered ip-pools by name (unique identifier)
items = api.cmdb.firewall.ippool.get(name="IP_POOL1")
print(f"ip-pools count={len(items)}")  # ip-pools count=2

# Update ip-pool data in the Fortigate
data = dict(name="IP_POOL1", comments="description")
response = api.cmdb.firewall.ippool.update(data)
print("ip-pool.update", response)  # ip-pool.update <Response [200]>

# Delete ip-pool from the Fortigate by name
response = api.cmdb.firewall.ippool.delete("IP_POOL1")
print("ip-pool.delete", response)  # addrgrp.delete <Response [200]>

# Check for presence of ip-pool in the Fortigate
response = api.cmdb.firewall.ippool.is_exist("IP_POOL1")
print("ip_pool.is_exist", response)  # ip_pool.is_exist False

api.logout()