Skip to main content

Variable Configuration Object

Manages variable resources with flexible typing and container associations in Palo Alto Networks Strata Cloud Manager.

Class Overview​

The Variable class provides CRUD operations for variable resources used to define reusable values that can be referenced across configurations.

Methods​

MethodDescriptionParametersReturn Type
create()Creates a new variabledata: Dict[str, Any]VariableResponseModel
get()Retrieves a variable by IDvariable_id: Union[str, UUID]VariableResponseModel
update()Updates an existing variablevariable: VariableUpdateModelVariableResponseModel
delete()Deletes a variablevariable_id: Union[str, UUID]None
list()Lists variables with filtering**filtersList[VariableResponseModel]
fetch()Gets a variable by its namename: str, folder: strVariableResponseModel

Model Attributes​

AttributeTypeRequiredDefaultDescription
namestrYesNoneName of the variable. Max length: 63 chars
typestrYesNoneVariable type (see Variable Types below)
valuestrYesNoneValue of the variable
idUUIDYes*NoneUnique identifier (*response/update only)
descriptionstrNoNoneOptional description
folderstrNo**NoneFolder in which the variable is defined. Max: 64 chars
snippetstrNo**NoneSnippet in which the variable is defined. Max: 64 chars
devicestrNo**NoneDevice in which the variable is defined. Max: 64 chars
overriddenboolNoNoneWhether the variable is overridden (response only)
labelsList[str]NoNoneOptional list of labels (response only)

* Only required for response and update models ** Exactly one of folder, snippet, or device must be provided

Variable Types​

TypeDescription
percentPercentage value
countCount/number value
ip-netmaskIP address with subnet mask
zoneSecurity zone
ip-rangeIP address range
ip-wildcardIP wildcard mask
device-priorityDevice priority value
device-idDevice identifier
egress-maxMaximum egress value
as-numberAS number
fqdnFully qualified domain name
portPort number
link-tagLink tag
group-idGroup identifier
rateRate value
router-idRouter identifier
qos-profileQoS profile
timerTimer value

Exceptions​

ExceptionHTTP CodeDescription
InvalidObjectError400Invalid variable data or format
ObjectNotPresentError404Requested variable not found
APIErrorVariousGeneral API communication error
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"
)

variables = client.variable

Methods​

List Variables​

all_variables = client.variable.list()

for var in all_variables:
print(f"Variable: {var.name}, Type: {var.type}, Value: {var.value}")

Filtering responses:

# Filter by type (client-side)
ip_variables = client.variable.list(type="ip-netmask")

# Filter by labels (client-side)
labeled_variables = client.variable.list(labels=["network"])

# Filter by parent folder (client-side)
folder_variables = client.variable.list(parent="department-a")

# Filter by snippet (client-side)
snippet_variables = client.variable.list(snippets=["security-snippet"])

Controlling pagination with max_limit:

client.variable.max_limit = 100

all_variables = client.variable.list()

Fetch a Variable​

variable = client.variable.fetch(name="subnet-variable", folder="department-a")
if variable:
print(f"Found variable: {variable.name}, Value: {variable.value}")

Create a Variable​

# Variable associated with a folder
variable_data = {
"name": "subnet-variable",
"type": "ip-netmask",
"value": "192.168.1.0/24",
"description": "Network subnet for department A",
"folder": "department-a"
}
created = client.variable.create(variable_data)

# Variable associated with a snippet
snippet_variable = {
"name": "snippet-var",
"type": "port",
"value": "8080",
"snippet": "web-servers"
}
client.variable.create(snippet_variable)

# Variable associated with a device
device_variable = {
"name": "device-var",
"type": "ip-netmask",
"value": "10.0.0.1/32",
"device": "001122334455"
}
client.variable.create(device_variable)

Update a Variable​

existing = client.variable.fetch(name="subnet-variable", folder="department-a")

existing.value = "10.0.0.0/16"
existing.description = "Updated network subnet"

updated = client.variable.update(existing)

Delete a Variable​

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

Get a Variable by ID​

variable = client.variable.get("12345678-1234-1234-1234-123456789012")
print(f"Variable: {variable.name}, Type: {variable.type}, Value: {variable.value}")

Error Handling​

from scm.exceptions import ObjectNotPresentError, InvalidObjectError

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

try:
# Missing required container (folder, snippet, or device)
client.variable.create({
"name": "invalid-var",
"type": "ip-netmask",
"value": "192.168.1.0/24"
})
except InvalidObjectError as e:
print(f"Validation error: {e}")