zpa_gateway

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

Methods are accessible via zia.zpa_gateway

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 ZPAGatewayAPI

Bases: APIClient

A Client object for the ZPA Gateway API resource.

add_gateway(name, zpa_server_group=None, zpa_app_segments=None, **kwargs)

Creates a new ZPA Gateway.

Parameters:
  • name (str) – The name of the ZPA Gateway.

  • zpa_server_group (dict, required) – The ZPA Server Group that is configured for Source IP Anchoring.

  • zpa_app_segments (list, optional) – All the Application Segments that are associated with the selected ZPA Server Group for which Source IP Anchoring is enabled.

Keyword Arguments:
  • description (str) – Additional details about the ZPA gateway.

  • type (str) – Indicates whether the ZPA gateway is configured for Zscaler Internet Access (using option ZPA) or Zscaler Cloud Connector (using option ECZPA). Accepted values are ‘ZPA’ or ‘ECZPA’.

  • zpa_tenant_id (int) – The ID of the ZPA tenant where Source IP Anchoring is configured

Returns:

The newly added ZPA Gateway resource record.

Return type:

Tuple

Examples

Adding a new ZPA Gateway

>>> added_gateway, _, error = client.zia.zpa_gateway.add_gateway(
... name=f"NewGateway_{random.randint(1000, 10000)}",
... description=f"NewGateway_{random.randint(1000, 10000)}",
... zpa_server_group={
...     "name": "App_Segment_IP_Source_Anchoring2",
...     "external_id": "72058304855090128"
... },
... zpa_app_segments=[
... {
...      "name": "App_Segment_IP_Source_Anchoring1",
...      "external_id": "72058304855090129"
...  }
... ])
... if error:
...     print(f"Error adding gateway: {error}")
...     return
... print(f"Gateway added successfully: {added_gateway.as_dict()}")
delete_gateway(gateway_id)

Deletes the specified ZPA Gateway.

Parameters:

gateway_id (str) – The unique identifier of the ZPA Gateway that will be deleted.

Returns:

The response code for the request.

Return type:

int

Examples
>>> _, _, error = client.zia.zpa_gateway.delete_gateway(gateway_id=18423896)
... if error:
...     print(f"Error deleting zpa gateway: {error}")
...     return
... print(f"Rule with ID {updated_gateway.id} deleted successfully.")
get_gateway(gateway_id)

Returns the zpa gateway details for a given ZPA Gateway.

Parameters:

gateway_id (str) – The unique identifier for the ZPA Gateway.

Returns:

A tuple containing (ZPA Gateway instance, Response, error).

Return type:

tuple

Examples

>>> etched_gateway, _, error = client.zia.zpa_gateway.get_gateway(gateway_id=18423896)
... if error:
...     print(f"Error fetching gateway by ID: {error}")
...     return
... print(f"Fetched gateway by ID: {fetched_gateway.as_dict()}")
list_gateways(query_params=None)

Lists ZPA Gateways in your organization with pagination. A subset of ZPA Gateways can be returned that match a supported filter expression or query.

Parameters:

{dict} (query_params) – Map of query parameters for the request. [query_params.app_segment] {list}: Page size for pagination. [query_params.search] {str}: Search string for filtering results.

Returns:

A tuple containing (list of ZPA Gateways instances, Response, error)

Return type:

tuple

Examples

Get a list of all ZPA Gateways Items

>>> gw_list, _, error = client.zia.zpa_gateway.list_gateways()
    if error:
        print(f"Error listing zpa gateway: {error}")
        return
    print(f"Total gateways found: {len(rulgw_listes_list)}")
    for rule in gw_list:
        print(rule.as_dict())

Search a ZPA Gateways By Name

>>> gw_list, _, error = client.zia.zpa_gateway.list_gateways(query_params={'search': 'ZPA_GW01'})
... if error:
...     print(f"Error listing zpa gateway: {error}")
...     return
... for rule in gw_list:
...     print(rule.as_dict())
update_gateway(gateway_id, zpa_server_group=None, zpa_app_segments=None, **kwargs)

Updates information for the specified ZPA Gateway.

Parameters:

gateway_id (str) – The unique id for the ZPA Gateway to be updated.

Keyword Arguments:
  • name (str) – The name of the ZPA gateway.

  • description (str) – Additional details about the ZPA gateway.

  • type (str) – Indicates whether the ZPA gateway is configured for Zscaler Internet Access (using option ZPA) or Zscaler Cloud Connector (using option ECZPA). Accepted values are ‘ZPA’ or ‘ECZPA’.

  • zpa_server_group (dict, optional) – The ZPA Server Group configured for Source IP Anchoring.

  • zpa_app_segments (list, optional) – All the Application Segments associated with the selected ZPA Server Group for which Source IP Anchoring is enabled.

  • zpa_tenant_id (int) – The ID of the ZPA tenant where Source IP Anchoring is configured

Returns:

The updated ZPA Gateway resource record.

Return type:

Tuple

Examples

Updating a new ZPA Gateway

>>> update_gateway, _, error = client.zia.zpa_gateway.update_gateway(
... gateway_id=18423896
... name=f"NewGateway_{random.randint(1000, 10000)}",
... description=f"NewGateway_{random.randint(1000, 10000)}",
... zpa_server_group={
...     "name": "App_Segment_IP_Source_Anchoring2",
...     "external_id": "72058304855090128"
... },
... zpa_app_segments=[
... {
...      "name": "App_Segment_IP_Source_Anchoring1",
...      "external_id": "72058304855090129"
...  }
... ])
... if error:
...     print(f"Error updating gateway: {error}")
...     return
... print(f"Gateway updated successfully: {update_gateway.as_dict()}")