ip_groups

The following methods allow for interaction with the ZTW IP Groups API endpoints.

Methods are accessible via ztw.ip_groups

Copyright (c) 2023, Zscaler Inc.

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

class IPGroupsAPI

Bases: APIClient

add_ip_group(**kwargs)

Adds a new IP Group.

Parameters:
  • name (str) – The name of the IP Group.

  • ip_addresses (str) – The list of IP addresses for the IP Group.

  • description (str) – Additional information for the IP Group.

Returns:

The new IP Group resource record.

Return type:

tuple

Examples

Add a new IP Group:

>>> ztw.ip_groups.add_ip_group(name='My IP Group',
...    ip_addresses=['198.51.100.0/24'],
...    description='Contains the IP addresses for the local network.')
delete_ip_group(group_id)

Deletes an IP Group.

Parameters:

group_id (str) – The unique ID of the IP Group to be deleted.

Returns:

The status code for the operation.

Return type:

int

Examples

>>> _, response, error = client.ztw.ip_groups.delete_ip_group('545845')
... if error:
...     print(f"Error deleting group: {error}")
... return
list_ip_groups(query_params=None)

List IP Groups in your organization.

Parameters:

{dict} (query_params) –

Map of query parameters for the request.

[query_params.search] {str}: Search string for filtering results by rule name.

Returns:

A tuple containing (list of IP Groups instances, Response, error)

Return type:

tuple

Examples

List all IP Groups:

>>> group_list, response, error = ztw.ip_groups.list_ip_groups():
... if error:
...     print(f"Error listing IP Groups: {error}")
...     return
... print(f"Total groups found: {len(group_list)}")
... for group in group_list:
...     print(group.as_dict())

Gets a list of all IP Groups.

>>> group_list, response, error = ztw.ip_groups.list_ip_groups(query_params={"search": 'Group01'}):
... if error:
...     print(f"Error listing IP Groups: {error}")
...     return
... print(f"Total groups found: {len(group_list)}")
... for group in group_list:
...     print(group.as_dict())
list_ip_groups_lite(query_params=None)

Lists IP Groups name and ID all IP Groups. This endpoint retrieves only IPv4 source address groups. If the search parameter is provided, the function filters the rules client-side.

Parameters:

{dict} (query_params) –

Map of query parameters for the request.

[query_params.search] {str}: The search string used to match against

a group’s name or description attributes.

Returns:

List of IP Groups resource records.

Return type:

tuple

Examples

Gets a list of all IP Groups.

>>> group_list, response, error = ztw.ip_groups.list_ip_groups_lite():
... if error:
...     print(f"Error listing IP Groups: {error}")
...     return
... print(f"Total groups found: {len(group_list)}")
... for group in group_list:
...     print(group.as_dict())

Gets a list of all IP Groups name and ID.

>>> group_list, response, error = ztw.ip_groups.list_ip_groups_lite(query_params={"search": 'Group01'}):
... if error:
...     print(f"Error listing IP Groups: {error}")
...     return
... print(f"Total groups found: {len(group_list)}")
... for group in group_list:
...     print(group.as_dict())