Skip to main content

Label Configuration Object

Manages label objects for resource classification and organization in Palo Alto Networks Strata Cloud Manager.

Class Overview​

The Label class inherits from BaseObject and provides CRUD operations for label objects used for resource classification.

Methods​

MethodDescriptionParametersReturn Type
create()Creates a new label objectdata: Dict[str, Any]LabelResponseModel
get()Retrieves a label by IDlabel_id: Union[str, UUID]LabelResponseModel
update()Updates an existing labellabel: Union[LabelUpdateModel, LabelResponseModel]LabelResponseModel
delete()Deletes a labellabel_id: Union[str, UUID]None
list()Lists labels with filtering**filtersList[LabelResponseModel]
fetch()Gets label by namename: strLabelResponseModel

Model Attributes​

AttributeTypeRequiredDefaultDescription
namestrYesNoneName of label object. Max length: 63 chars
idUUIDYes*NoneUnique identifier (*response/update only)
descriptionstrNoNoneObject description

* Only required for response and update models

Exceptions​

ExceptionHTTP CodeDescription
InvalidObjectError400Invalid label data or format
ObjectNotPresentError404Label not found
APIErrorVariousGeneral API errors

Basic Configuration​

from scm.client import Scm

client = Scm(
client_id="your_client_id",
client_secret="your_client_secret",
tsg_id="your_tsg_id"
)

labels = client.label

Methods​

List Labels​

all_labels = client.label.list()

for label in all_labels:
print(f"Label: {label.name}, Description: {label.description}")

Controlling pagination with max_limit:

client.label.max_limit = 100

all_labels = client.label.list()

Fetch a Label​

label = client.label.fetch(name="environment")
if label:
print(f"Found label: {label.name}, ID: {label.id}")

Create a Label​

label_config = {
"name": "environment",
"description": "Environment classification label"
}
new_label = client.label.create(label_config)
print(f"Created label with ID: {new_label.id}")

Update a Label​

existing_label = client.label.fetch(name="environment")

existing_label.description = "Updated environment classification label"

updated_label = client.label.update(existing_label)

Delete a Label​

client.label.delete("123e4567-e89b-12d3-a456-426655440000")

Get a Label by ID​

label = client.label.get("123e4567-e89b-12d3-a456-426655440000")
print(f"Retrieved label: {label.name}")

Use Cases​

Committing Changes​

result = client.commit(
folders=["Texas"],
description="Added new labels",
sync=True,
timeout=300
)
print(f"Commit job ID: {result.job_id}")

Monitoring Jobs​

job_status = client.get_job_status(result.job_id)
print(f"Job status: {job_status.data[0].status_str}")

recent_jobs = client.list_jobs(limit=10)
for job in recent_jobs.data:
print(f"Job {job.id}: {job.type_str} - {job.status_str}")

Error Handling​

from scm.exceptions import (
InvalidObjectError,
ObjectNotPresentError,
APIError
)

try:
label_config = {
"name": "test_label",
"description": "Test label"
}
new_label = client.label.create(label_config)
result = client.commit(
folders=["Texas"],
description="Added test label",
sync=True
)
status = client.get_job_status(result.job_id)

except InvalidObjectError as e:
print(f"Invalid label data: {e.message}")
except ObjectNotPresentError as e:
print(f"Label not found: {e.message}")
except APIError as e:
print(f"API error: {e.message}")