Skip to main content

Snippet Configuration Object

Manages reusable configuration snippet objects in Palo Alto Networks Strata Cloud Manager.

Class Overview​

The Snippet class inherits from BaseObject and provides CRUD operations for snippet objects, which are reusable configuration elements. It also supports folder association and disassociation.

Methods​

MethodDescriptionParametersReturn Type
create()Creates a new snippetdata: Dict[str, Any]SnippetResponseModel
get()Retrieves a snippet by IDobject_id: Union[str, UUID]SnippetResponseModel
update()Updates an existing snippetsnippet: SnippetUpdateModelSnippetResponseModel
delete()Deletes a snippetobject_id: Union[str, UUID]None
list()Lists snippets with filtering**filtersList[SnippetResponseModel]
fetch()Gets a snippet by its namename: strSnippetResponseModel
associate_folder()Associates a snippet with a foldersnippet_id, folder_idSnippetResponseModel
disassociate_folder()Disassociates a snippet from a foldersnippet_id, folder_idSnippetResponseModel

Model Attributes​

AttributeTypeRequiredDefaultDescription
namestrYesNoneName of the snippet
idUUIDYes*NoneUnique identifier (*response/update only)
descriptionstrNoNoneOptional description
labelsList[str]NoNoneOptional list of labels
enable_prefixboolNoNoneWhether to enable prefix for this snippet
typestrNoNoneSnippet type: 'predefined', 'custom', 'readonly'
display_namestrNoNoneDisplay name for the snippet
last_updatestrNoNoneTimestamp of last update
created_instrNoNoneTimestamp of creation
foldersList[FolderReference]NoNoneFolders the snippet is applied to
shared_instrNoNoneSharing scope (e.g., 'local')

* Only required for response and update models

Exceptions​

ExceptionHTTP CodeDescription
InvalidObjectError400Invalid snippet data or format
ObjectNotPresentError404Requested snippet not found
APIErrorVariousGeneral API communication error
NotImplementedError501Feature not yet implemented
AuthenticationError401Authentication failed
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"
)

snippets = client.snippet

Methods​

List Snippets​

all_snippets = client.snippet.list()
security_snippets = client.snippet.list(labels=["security"])
custom_snippets = client.snippet.list(types=["custom"])

Controlling pagination with max_limit:

client.snippet.max_limit = 100

all_snippets = client.snippet.list()

Fetch a Snippet​

snippet = client.snippet.fetch("Security Policy Snippet")
if snippet:
print(f"Found snippet: {snippet.name}, ID: {snippet.id}")

Create a Snippet​

snippet_data = {
"name": "Security Policy Snippet",
"description": "Common security policy configurations",
"labels": ["security", "policy"],
"enable_prefix": True
}
created = client.snippet.create(snippet_data)
print(f"Created snippet: {created.id}")

Update a Snippet​

existing = client.snippet.fetch(name="Security Policy Snippet")

existing.description = "Updated security policy configs"
existing.labels = ["security", "updated"]

updated = client.snippet.update(existing)

Delete a Snippet​

client.snippet.delete("12345678-1234-1234-1234-123456789012")

Get a Snippet by ID​

snippet = client.snippet.get("12345678-1234-1234-1234-123456789012")
print(f"Snippet: {snippet.name}, Type: {snippet.type}")

Use Cases​

Folder Associations​

try:
updated_snippet = client.snippet.associate_folder(snippet_id, folder_id)
print("Associated snippet with folder")
result = client.snippet.disassociate_folder(snippet_id, folder_id)
print("Disassociated snippet from folder")
except NotImplementedError as e:
print(f"Folder association not yet implemented: {e}")

Error Handling​

from scm.exceptions import ObjectNotPresentError, InvalidObjectError

try:
snippet = client.snippet.get("nonexistent-id")
except ObjectNotPresentError:
print("Snippet not found!")

try:
client.snippet.create({"name": "", "description": "Invalid"})
except InvalidObjectError as e:
print(f"Validation error: {e}")