server_groups

The following methods allow for interaction with the ZPA Server Groups API endpoints.

Methods are accessible via zpa.server_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 ServerGroupsAPI

Bases: APIClient

A client object for the Server Groups resource.

add_group(**kwargs)

Adds a server group.

Parameters:
  • name (str) – The name for the server group.

  • app_connector_group_ids (list of str) – A list of App connector IDs that will be attached to the server group.

  • **kwargs – Optional params.

Keyword Arguments:
  • **application_ids (list of str) – A list of unique IDs of applications to associate with this server group.

  • **config_space (str) – The configuration space. Accepted values are DEFAULT or SIEM.

  • **description (str) – Additional information about the server group.

  • **enabled (bool) – Enable the server group.

  • **ip_anchored (bool) – Enable IP Anchoring.

  • **dynamic_discovery (bool) – Enable Dynamic Discovery.

  • **server_ids (list of str) – A list of unique IDs of servers to associate with this server group.

  • **microtenant_id (str) – The unique identifier of the Microtenant for the ZPA tenant.

Returns:

A tuple containing (ServerGroup, Response, error)

Return type:

Tuple

Examples

Create a server group with the minimum params:

>>> added_group, _, err = client.zpa.server_groups.add_group(
...    name='new_server_group',
...    app_connector_group_ids=['99999'],
... )
... if err:
...     print(f"Error adding server group: {err}")
...     return
... print(f"Server Group added successfully: {added_group.as_dict()}")

Create a server group and define a new application server on the fly:

>>> added_group, _, err = client.zpa.server_groups.add_group(
...    name='new_server_group',
...    description='new_server_group',
...    enabled=True,
...    dynamic_discovery=False,
...    app_connector_group_ids=['99999'],
...    server_ids=['99999'],
... if err:
...     print(f"Error adding server group: {err}")
...     return
... print(f"Server Group added successfully: {added_group.as_dict()}")
delete_group(group_id, microtenant_id=None)

Deletes the specified server group.

Parameters:
  • group_id (str) – The unique id for the server group to be deleted.

  • microtenant_id (str) – The unique identifier of the Microtenant for the ZPA tenant.

Returns:

A tuple containing (None, Response, error)

Return type:

tuple

Examples

>>> _, _, err = client.zpa.server_groups.delete_group(
...     group_id='999999'
... )
... if err:
...     print(f"Error deleting server groups: {err}")
...     return
... print(f"server groups with ID {'999999'} deleted successfully.")
get_group(group_id, query_params=None)

Provides information on the specified server group.

Parameters:
  • group_id (str) – The unique id for the server group.

  • query_params (dict, optional) – Map of query parameters for the request. [query_params.microtenant_id] {str}: The microtenant ID, if applicable.

Returns:

A tuple containing (ServerGroup, Response, error)

Return type:

Tuple

Examples

>>> fetched_group, _, err = client.zpa.server_groups.get_group('999999')
... if err:
...     print(f"Error fetching server group by ID: {err}")
...     return
... print(f"Fetched server group by ID: {fetched_group.as_dict()}")
list_groups(query_params=None)

Enumerates server groups in your organization with pagination. A subset of server groups can be returned that match a supported filter expression or query.

Parameters:

{dict} (query_params) –

Map of query parameters for the request.

[query_params.page] {str}: Specifies the page number.

[query_params.page_size] {int}: Specifies the page size.

If not provided, the default page size is 20. The max page size is 500.

[query_params.search] {str}: The search string used to support search by features and fields for the API. [query_params.microtenant_id] {str}: ID of the microtenant, if applicable.

Returns:

A tuple containing (list of ServerGroups instances, Response, error)

Return type:

Tuple

Examples

>>> groups_list, _, err = client.zpa.server_groups.list_groups(
... query_params={'search': 'Group01', 'page': '1', 'page_size': '100'})
... if err:
...     print(f"Error listing server groups: {err}")
...     return
... print(f"Total server groups found: {len(groups_list)}")
... for group in groups_list:
...     print(group.as_dict())
reformat_params = [('server_ids', 'servers'), ('app_connector_group_ids', 'appConnectorGroups')]
update_group(group_id, **kwargs)

Updates a server group.

Parameters:
  • group_id (str) – The unique identifier for the server group.

  • microtenant_id (str) – The unique identifier of the Microtenant for the ZPA tenant.

Returns:

A tuple containing (ServerGroup, Response, error)

Return type:

Tuple

Examples

>>> update_group, _, err = client.zpa.server_groups.update_group(
...    group_id="999999",
...    name='update_server_group',
...    description='update_server_group',
...    enabled=True,
...    dynamic_discovery=True,
...    app_connector_group_ids=['99999'],
... if err:
...     print(f"Error adding server group: {err}")
...     return
... print(f"Server Group added successfully: {added_group.as_dict()}")