workload_groups¶
The following methods allow for interaction with the Workload Groups API endpoints.
Methods are accessible via zia.workload_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 WorkloadGroupsAPI¶
Bases:
APIClientA Client object for the Workload Groups API resource.
- add_group(**kwargs)¶
Creates a new ZIA Workload Group.
- Parameters:
name (str) – The name of the workload group.
**kwargs – Optional keyword args.
- Keyword Arguments:
description (str) – Additional notes or information about the workload group.
expression (str) – The expression string for the workload group.
expression_json (dict) –
JSON object containing the expression configuration with the following structure:
expression_containers (list): List of expression containers, each containing:
tag_type (str): Type of tag (e.g., “ATTR”, “ENI”, “VPC”, “VM”).
operator (str): Logical operator for the expression (e.g., “AND”, “OR”).
tag_container (dict): Container for tags with:
tags (list): List of tag objects, each containing:
key (str): The tag key identifier.
value (str): The tag value.
operator (str): Logical operator for tags within the container.
- Returns:
A tuple containing the newly added Workload Group, response, and error.
- Return type:
Examples
Add a new Workload Group with basic information:
>>> added_group, _, error = client.zia.workload_groups.add_group( ... name="Test Group", ... description="Test Group Description" ... ) >>> if error: ... print(f"Error adding group: {error}") ... return ... print(f"Group added successfully: {added_group.as_dict()}")
Add a new Workload Group with complex expression configuration:
>>> added_group, _, error = client.zia.workload_groups.add_group( ... name="Test Group", ... description="Test Group", ... expression_json={ ... "expression_containers": [ ... { ... "tag_type": "ATTR", ... "operator": "AND", ... "tag_container": { ... "tags": [ ... { ... "key": "GroupName", ... "value": "example" ... } ... ], ... "operator": "AND" ... } ... }, ... { ... "tag_type": "VPC", ... "operator": "AND", ... "tag_container": { ... "tags": [ ... { ... "key": "Vpc-id", ... "value": "vpcid12344" ... } ... ], ... "operator": "AND" ... } ... } ... ] ... } ... ) >>> if error: ... print(f"Error adding group: {error}") ... return ... print(f"Group added successfully: {added_group.as_dict()}")
- delete_group(group_id)¶
Deletes the specified Workload Group.
- Parameters:
group_id (str) – The unique identifier of the Workload Group.
- Returns:
A tuple containing the response object and error (if any).
- Return type:
Examples
Delete a Workload Group:
>>> _, _, error = client.zia.workload_groups.delete_group('73459') >>> if error: ... print(f"Error deleting Workload Group: {error}") ... return ... print(f"Workload Group with ID {'73459'} deleted successfully.")
- get_group(group_id)¶
Fetches a specific workload group by ID.
- Parameters:
group_id (int) – The unique identifier for the workload group.
- Returns:
A tuple containing (WorkloadGroup instance, Response, error).
- Return type:
Examples
Print a specific Workload Group
>>> fetched_group, _, error = client.zia.workload_groups.get_group( '1254654') >>> if error: ... print(f"Error fetching Workload Group by ID: {error}") ... return ... print(f"Fetched Workload Group by ID: {fetched_group.as_dict()}")
- list_groups(query_params=None)¶
Returns the list of workload groups configured in the ZIA Admin Portal.
- Parameters:
{dict} (query_params) –
Map of query parameters for the request.
[query_params.page]{int}: Specifies the page offset.[query_params.page_size]{int}: Specifies the page size.The default size is 250, but the maximum size is 1000.
- Returns:
A tuple containing (list of WorkloadGroups instances, Response, error)
- Return type:
Examples
List users using default settings:
>>> group_list, _, err = client.zia.workload_groups.list_groups() ... if err: ... print(f"Error listing groups: {err}") ... return ... print(f"Total groups found: {len(group_list)}") ... for group in group_list: ... print(group.as_dict())
- update_group(group_id, **kwargs)¶
Updates information for the specified ZIA Workload Group.
- Parameters:
group_id (int) – The unique ID for the Workload Group.
**kwargs – Optional keyword args.
- Keyword Arguments:
name (str) – The name of the workload group.
description (str) – Additional notes or information about the workload group.
expression (str) – The expression string for the workload group.
expression_json (dict) –
JSON object containing the expression configuration with the following structure:
expression_containers (list): List of expression containers, each containing:
tag_type (str): Type of tag (e.g., “ATTR”, “ENI”, “VPC”, “VM”).
operator (str): Logical operator for the expression (e.g., “AND”, “OR”).
tag_container (dict): Container for tags with:
tags (list): List of tag objects, each containing:
key (str): The tag key identifier.
value (str): The tag value.
operator (str): Logical operator for tags within the container.
- Returns:
A tuple containing the updated Workload Group, response, and error.
- Return type:
Examples
Update an existing Workload Group with basic information:
>>> updated_group, _, error = client.zia.workload_groups.update_group( ... group_id=1524566, ... name="Updated Test Group", ... description="Updated Test Group Description" ... ) >>> if error: ... print(f"Error updating Workload Group: {error}") ... return ... print(f"Workload Group updated successfully: {updated_group.as_dict()}")
Update an existing Workload Group with complex expression configuration:
>>> updated_group, _, error = client.zia.workload_groups.update_group( ... group_id=1524566, ... name="Updated Test Group", ... description="Updated Test Group", ... expression_json={ ... "expression_containers": [ ... { ... "tag_type": "ATTR", ... "operator": "AND", ... "tag_container": { ... "tags": [ ... { ... "key": "GroupName", ... "value": "updated_example" ... } ... ], ... "operator": "AND" ... } ... }, ... { ... "tag_type": "ENI", ... "operator": "AND", ... "tag_container": { ... "tags": [ ... { ... "key": "GroupId", ... "value": "987654321" ... } ... ], ... "operator": "AND" ... } ... } ... ] ... } ... ) >>> if error: ... print(f"Error updating Workload Group: {error}") ... return ... print(f"Workload Group updated successfully: {updated_group.as_dict()}")