Skip to main content

Base Configuration Object

Serves as the foundation for all configuration objects in Palo Alto Networks Strata Cloud Manager.

Class Overview

The BaseObject class provides standardized CRUD operations (Create, Read, Update, Delete) and job management functionality that is inherited by all configuration object types.

Methods

MethodDescriptionParametersReturn Type
create()Creates new objectdata: Dict[str, Any]Dict[str, Any]
get()Retrieves object by IDobject_id: strDict[str, Any]
update()Updates existing objectdata: Dict[str, Any]Dict[str, Any]
delete()Deletes objectobject_id: strNone
list()Lists objects with filtering**filtersList[Dict[str, Any]]
list_jobs()Lists jobs with paginationlimit: int, offset: int, parent_id: strJobListResponse
get_job_status()Gets job statusjob_id: strJobStatusResponse
commit()Commits configuration changesfolders: List[str], description: str, **kwargsCandidatePushResponse

Model Attributes

AttributeTypeRequiredDescription
ENDPOINTstrYesAPI endpoint path for object operations
api_clientScmYesInstance of SCM API client

Exceptions

ExceptionHTTP CodeDescription
InvalidObjectError400Invalid object data or format
MissingQueryParameterError400Missing required parameters
NotFoundError404Object not found
AuthenticationError401Authentication failed
AuthorizationError403Permission denied
ConflictError409Object conflict
ServerError500Internal server error

Basic Configuration

from scm.client import Scm

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

# Most objects can be accessed directly through the client
# Example: client.address, client.service_group, client.security_rule, etc.

For custom or extended objects:

from scm.client import Scm
from scm.config.objects import BaseObject

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

class CustomObject(BaseObject):
ENDPOINT = "/config/objects/v1/custom"

custom_obj = CustomObject(client)

Methods

List Objects

list_params = {
"folder": "Texas",
"limit": 100,
"offset": 0
}
objects = custom_obj.list(**list_params)
for obj in objects:
print(f"Name: {obj['name']}")

Filtering responses:

# Only return objects defined exactly in 'Texas'
exact_objects = custom_obj.list(
folder='Texas',
exact_match=True
)

# Exclude all objects from the 'All' folder
no_all_objects = custom_obj.list(
folder='Texas',
exclude_folders=['All']
)

Controlling pagination with max_limit:

custom_obj = CustomObject(client, max_limit=4321)

all_objects = custom_obj.list(folder='Texas')

Create an Object

object_data = {
"name": "test-object",
"description": "Test object creation",
"folder": "Texas"
}
new_object = custom_obj.create(object_data)
print(f"Created object with ID: {new_object['id']}")

Update an Object

update_data = {
"id": "123e4567-e89b-12d3-a456-426655440000",
"name": "updated-object",
"description": "Updated description",
"folder": "Texas"
}
updated_object = custom_obj.update(update_data)

Delete an Object

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

Get an Object by ID

retrieved_object = custom_obj.get("123e4567-e89b-12d3-a456-426655440000")
print(f"Retrieved object: {retrieved_object['name']}")

Use Cases

Committing Changes

result = client.commit(
folders=["Texas"],
description="Configuration update",
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,
NotFoundError,
AuthenticationError,
ServerError
)

try:
result = custom_obj.create({
"name": "test-object",
"folder": "Texas"
})
commit_result = client.commit(
folders=["Texas"],
description="Added test object",
sync=True
)
status = client.get_job_status(commit_result.job_id)

except InvalidObjectError as e:
print(f"Invalid object data: {e.message}")
except NotFoundError as e:
print(f"Object not found: {e.message}")
except AuthenticationError as e:
print(f"Authentication failed: {e.message}")
except ServerError as e:
print(f"Server error: {e.message}")