template_router

The following methods allow for interaction with the ZTB Template Router API endpoints.

Methods are accessible via ztb.template_router

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 TemplateRouterAPI

Bases: APIClient

Client for the ZTB Groups Router resource.

Provides CRUD operations for groups router in the Zero Trust Branch API.

create_template(**kwargs)

Creates a new ZTB Template.

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

  • **kwargs – Optional keyword args.

Keyword Arguments:
  • display_name (str) – The display name for the group.

  • type (str) – The group type (e.g. device).

  • autonomous (bool) – Whether the group is autonomous.

  • owner (str) – The owner of the group.

  • member_attributes (dict) – Member attribute filters.

Returns:

A tuple containing the newly created Group, response, and error.

Return type:

tuple

Examples

Create a new Group:

>>> created_group, _, error = client.ztb.groups_router.create_group(
...     name="Group01",
...     display_name="Group01",
...     type="device",
...     autonomous=True,
...     owner="user",
... )
>>> if error:
...     print(f"Error creating group: {error}")
...     return
... print(f"Group created successfully: {created_group.as_dict()}")
delete_template(template_id)

Deletes the specified Template.

Parameters:

template_id (int) – The unique identifier of the Template.

Returns:

A tuple containing the response object and error (if any).

Return type:

tuple

Examples

Delete a Template:

>>> _, _, error = client.ztb.template_router.delete_template('73459')
>>> if error:
...     print(f"Error deleting template: {error}")
...     return
... print(f"Template with ID 73459 deleted successfully.")
get_template(template_id)

Fetches a specific template by ID.

Parameters:

template_id (int) – The unique identifier for the template.

Returns:

A tuple containing (TemplateRouter instance, Response, error).

Return type:

tuple

Examples

Print a specific Template:

>>> fetched_template, _, error = client.ztb.template_router.get_template('73459')
>>> if error:
...     print(f"Error fetching template by ID: {error}")
...     return
... print(f"Fetched template by ID: {fetched_template.as_dict()}")
list_template_interfaces(platform, query_params=None)

Get Gateway Template Interfaces.

Parameters:
  • platform (str) – The platform type (e.g. vm, hardware).

  • query_params (dict) – Map of query parameters for the request.

Returns:

A tuple containing (list of Common instances, Response, error).

Return type:

tuple

Examples

List all template interfaces for a platform:

>>> template_list, _, error = client.ztb.template_router.list_template_interfaces(
...     platform="vm"
... )
>>> if error:
...     print(f"Error listing interfaces: {error}")
...     return
... print(f"Total interfaces found: {len(template_list)}")
... for iface in template_list:
...     print(iface.as_dict())

Client-side filtering with JMESPath:

The response object supports client-side filtering and projection via resp.search(expression). See the JMESPath documentation for expression syntax.

list_template_names()

Get Gateway Template Names.

Returns:

A tuple containing (list of Common instances, Response, error).

Return type:

tuple

Examples

List all template interfaces for a platform:

>>> template_list, _, error = client.ztb.template_router.list_template_interfaces(
...     platform="vm"
... )
>>> if error:
...     print(f"Error listing template names: {error}")
...     return
... print(f"Total template names found: {len(template_names)}")
... for name in template_names:
...     print(name.as_dict())

Client-side filtering with JMESPath:

The response object supports client-side filtering and projection via resp.search(expression). See the JMESPath documentation for expression syntax.

list_templates(query_params=None)

Get Gateway Template

Parameters:

query_params (dict) –

Map of query parameters for the request.

[query_params.search] (str):

[query_params.page] (int):

[query_params.size] (int):

[query_params.sort] (str): Available values : name, private_dns, dhcp_service, deployment_type, platform_type, sites, is_default, created_at

[query_params.sortdir] (str): Available values : asc, desc

Returns:

A tuple containing (list of TemplateRouter instances, Response, error).

Return type:

tuple

Examples

List all templates:

>>> template_list, _, error = client.ztb.template_router.list_templates()
>>> if error:
...     print(f"Error listing templates: {error}")
...     return
... print(f"Total templates found: {len(template_list)}")
... for template in template_list:
...     print(template.as_dict())

Client-side filtering with JMESPath:

The response object supports client-side filtering and projection via resp.search(expression). See the JMESPath documentation for expression syntax.

update_template_put(template_id, **kwargs)

Updates information for the specified ZTB Template (PUT).

Parameters:
  • template_id (int) – The unique ID for the Template.

  • **kwargs – Full template replacement fields.

Returns:

A tuple containing the updated Template, response, and error.

Return type:

tuple

Examples

Update an existing Template:

>>> updated_group, _, error = client.ztb.groups_router.update_group_put(
...     group_id='73459',
...     name="Group01",
...     display_name="Group01",
...     type="device",
...     autonomous=True,
...     owner="user",
... )
>>> if error:
...     print(f"Error updating group: {error}")
...     return
... print(f"Group updated successfully (PUT): {updated_group.as_dict()}")