Skip to main content

Address Group Models

Overview

The Address Group models provide a structured way to manage address groups in Palo Alto Networks' Strata Cloud Manager. These models support both static and dynamic address groups, which can be defined in folders, snippets, or devices. The models handle validation of inputs and outputs when interacting with the SCM API.

Models

ModelPurpose
DynamicFilterRepresents dynamic filter with tag-based criteria
AddressGroupBaseModelBase model with common fields for all operations
AddressGroupCreateModelModel for creating new address groups
AddressGroupUpdateModelModel for updating existing address groups
AddressGroupResponseModelModel for API responses

All models use extra="forbid" configuration, which rejects any fields not explicitly defined in the model.

Attributes

AttributeTypeRequiredDefaultDescription
namestrYesNoneName of the address group. Max length: 63 chars. Must match pattern: ^[a-zA-Z0-9_ .-]+$
descriptionstrNoNoneDescription of the address group. Max length: 1023 chars
tagList[str]NoNoneList of tags. Each tag max length: 127 chars
dynamicDynamicFilterNo*NoneDynamic filter for group membership
staticList[str]No*NoneList of static addresses. Min: 1, Max: 4096
folderstrNo**NoneFolder where group is defined. Max length: 64 chars
snippetstrNo**NoneSnippet where group is defined. Max length: 64 chars
devicestrNo**NoneDevice where group is defined. Max length: 64 chars
idUUIDYes***NoneUUID of the address group (response only)

* Either dynamic or static must be provided, but not both ** Exactly one container type (folder/snippet/device) must be provided *** Only required for response model

DynamicFilter Model

The DynamicFilter model represents tag-based filter criteria for dynamic address groups.

AttributeTypeRequiredDefaultDescription
filterstrYesNoneTag-based filter defining group membership. Max length: 1024 chars

Exceptions

The Address Group models can raise the following exceptions during validation:

  • ValueError: Raised in several scenarios:
    • When neither or both static and dynamic fields are provided
    • When multiple container types (folder/snippet/device) are specified
    • When no container type is specified for create operations
    • When tag values are not unique in a list
    • When tag input is neither a string nor a list

Model Validators

Address Group Type Validation

The models enforce that exactly one group type (static or dynamic) must be specified:

# This will raise a validation error
from scm.models.objects import AddressGroupCreateModel

# Error: both static and dynamic provided
try:
group = AddressGroupCreateModel(
name="invalid-group",
static=["addr1"],
dynamic={"filter": "'tag1'"},
folder="Texas"
)
except ValueError as e:
print(e) # "Exactly one of 'static' or 'dynamic' must be provided."

# Error: neither static nor dynamic provided
try:
group = AddressGroupCreateModel(
name="invalid-group",
folder="Texas"
)
except ValueError as e:
print(e) # "Exactly one of 'static' or 'dynamic' must be provided."

Container Type Validation

For create operations, exactly one container type must be specified:

# This will raise a validation error
try:
group = AddressGroupCreateModel(
name="invalid-group",
static=["addr1"],
folder="Texas",
device="fw01" # Can't specify both folder and device
)
except ValueError as e:
print(e) # "Exactly one of 'folder', 'snippet', or 'device' must be provided."

Tag Validation

Tags must be unique and properly formatted:

# This will raise a validation error for duplicate tags
try:
group = AddressGroupCreateModel(
name="invalid-group",
static=["addr1"],
folder="Texas",
tag=["web", "web"] # Duplicate tags not allowed
)
except ValueError as e:
print(e) # "List items must be unique"

# This will convert a single string tag to a list
group = AddressGroupCreateModel(
name="valid-group",
static=["addr1"],
folder="Texas",
tag="web" # Will be converted to ["web"]
)

Usage Examples

Creating a Static Address Group

from scm.client import Scm

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

# Using dictionary
static_group_dict = {
"name": "web-servers",
"description": "Web server group",
"static": ["web1", "web2", "web3"],
"folder": "Texas",
"tag": ["web", "production"]
}

response = client.address_group.create(static_group_dict)

Creating a Dynamic Address Group

# Using dictionary
dynamic_group_dict = {
"name": "aws-instances",
"description": "AWS EC2 instances",
"dynamic": {
"filter": "'aws-tag' and 'production'"
},
"folder": "Cloud",
"tag": ["aws", "dynamic"]
}

response = client.address_group.create(dynamic_group_dict)

Updating an Address Group

# Fetch existing group
existing = client.address_group.fetch(name="web-servers", folder="Texas")

# Modify attributes using dot notation
existing.description = "Updated web server group"
existing.static = ["web1", "web2", "web3", "web4"]
existing.tag = ["web", "production", "updated"]

# Pass modified object to update()
updated = client.address_group.update(existing)