Skip to main content

QoS Rule

The QosRule class manages QoS policy rule objects in Palo Alto Networks' Strata Cloud Manager. It extends from BaseObject and offers methods to create, retrieve, update, list, fetch, delete, and move QoS policy rules. These rules define how traffic is classified and assigned to QoS classes, enabling traffic prioritization through DSCP/TOS markings and schedule-based application.

Class Overview

from scm.client import Scm

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

# Access the QoS Rule service directly through the client
qos_rules = client.qos_rule
MethodDescriptionParametersReturn Type
create()Creates a new QoS ruledata: Dict[str, Any]QosRuleResponseModel
get()Retrieves a QoS rule by its unique IDobject_id: strQosRuleResponseModel
update()Updates an existing QoS rulerule: QosRuleUpdateModelQosRuleResponseModel
list()Lists QoS rules with optional filteringfolder: Optional[str], snippet: Optional[str], device: Optional[str], exact_match: bool = False, plus additional filtersList[QosRuleResponseModel]
fetch()Fetches a single QoS rule by name within a containername: str, folder: Optional[str], snippet: Optional[str], device: Optional[str]QosRuleResponseModel
delete()Deletes a QoS rule by its IDobject_id: strNone
move()Moves a QoS rule to a new position within the rulebaserule_id: UUID, data: Dict[str, Any]None

QoS Rule Model Attributes

AttributeTypeRequiredDefaultDescription
namestrYesNoneRule name
idUUIDYes*NoneUnique identifier (*response/update only)
descriptionstrNoNoneDescription of the QoS rule
actionDict[str, Any]NoNoneQoS action configuration with 'class' field referencing a profile
schedulestrNoNoneSchedule for the QoS rule
dscp_tosDict[str, Any]NoNoneDSCP/TOS codepoint settings
folderstrNo**NoneFolder location. Max 64 chars
snippetstrNo**NoneSnippet location. Max 64 chars
devicestrNo**NoneDevice location. Max 64 chars

* Only required for update and response models ** Exactly one container (folder/snippet/device) must be provided for create operations

Exceptions

ExceptionHTTP CodeDescription
InvalidObjectError400Thrown when provided data or parameters are invalid
MissingQueryParameterError400Thrown when required query parameters (e.g., name or folder) are missing
NameNotUniqueError409Rule name already exists
ObjectNotPresentError404Rule not found
ReferenceNotZeroError409Rule still referenced by other objects
AuthenticationError401Authentication failed
ServerError500Internal server error

Methods

List QoS Rules

# List all QoS rules in a folder
rules = client.qos_rule.list(
folder="Texas"
)

# Process results
for rule in rules:
print(f"Name: {rule.name}, Description: {rule.description}")

Filtering Responses

The list() method supports additional parameters to refine your query results even further. Alongside basic filters, you can leverage the exact_match, exclude_folders, exclude_snippets, and exclude_devices parameters to control which objects are included or excluded after the initial API response is fetched.

Parameters:

  • exact_match (bool): When True, only objects defined exactly in the specified container (folder, snippet, or device) are returned. Inherited or propagated objects are filtered out.
  • exclude_folders (List[str]): Provide a list of folder names that you do not want included in the results.
  • exclude_snippets (List[str]): Provide a list of snippet values to exclude from the results.
  • exclude_devices (List[str]): Provide a list of device values to exclude from the results.

Examples:

# Only return rules defined exactly in 'Texas'
exact_rules = client.qos_rule.list(
folder='Texas',
exact_match=True
)

for rule in exact_rules:
print(f"Exact match: {rule.name} in {rule.folder}")

# Exclude all rules from the 'All' folder
no_all_rules = client.qos_rule.list(
folder='Texas',
exclude_folders=['All']
)

for rule in no_all_rules:
assert rule.folder != 'All'
print(f"Filtered out 'All': {rule.name}")

Controlling Pagination with max_limit

The SDK supports pagination through the max_limit parameter, which defines how many objects are retrieved per API call. By default, max_limit is set to 2500. The API itself imposes a maximum allowed value of 5000. If you set max_limit higher than 5000, it will be capped to the API's maximum. The list() method will continue to iterate through all objects until all results have been retrieved. Adjusting max_limit can help manage retrieval performance and memory usage when working with large datasets.

Example:

from scm.client import Scm

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

# Configure max_limit using the property setter
client.qos_rule.max_limit = 4000

# List all rules - auto-paginates through results
all_rules = client.qos_rule.list(folder='Texas')

Fetch a QoS Rule

# Fetch by name and folder
rule = client.qos_rule.fetch(
name="voip-priority",
folder="Texas"
)
print(f"Found rule: {rule.name}")

# Get by ID
rule_by_id = client.qos_rule.get(rule.id)
print(f"Retrieved rule: {rule_by_id.name}")

Create a QoS Rule

from scm.client import Scm

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

# Create a QoS rule with action and DSCP settings
rule_data = {
"name": "voip-priority",
"description": "Prioritize VoIP traffic",
"action": {
"class": "class1"
},
"dscp_tos": {
"codepoints": [
{"name": "ef", "type": {"af": {"codepoint": "ef"}}}
]
},
"folder": "Texas"
}

new_rule = client.qos_rule.create(rule_data)
print(f"Created QoS rule with ID: {new_rule.id}")

# Create a scheduled QoS rule
scheduled_rule = {
"name": "business-hours-qos",
"description": "Business hours bandwidth management",
"action": {
"class": "class2"
},
"schedule": "business-hours",
"folder": "Texas"
}

sched_rule = client.qos_rule.create(scheduled_rule)
print(f"Created scheduled QoS rule with ID: {sched_rule.id}")

Update a QoS Rule

# Fetch existing rule
existing_rule = client.qos_rule.fetch(
name="voip-priority",
folder="Texas"
)

# Modify the description and action
existing_rule.description = "Updated VoIP priority rule"
existing_rule.action = {
"class": "class1"
}

# Perform update
updated_rule = client.qos_rule.update(existing_rule)

Delete a QoS Rule

# Delete by ID
rule_id = "123e4567-e89b-12d3-a456-426655440000"
client.qos_rule.delete(rule_id)

Use Cases

Performing Commits

# Prepare commit parameters
commit_params = {
"folders": ["Texas"],
"description": "Updated QoS rule configurations",
"sync": True,
"timeout": 300 # 5 minute timeout
}

# Commit the changes directly on the client
result = client.commit(**commit_params)

print(f"Commit job ID: {result.job_id}")

Monitoring Jobs

# Get status of specific job directly from the client
job_status = client.get_job_status(result.job_id)
print(f"Job status: {job_status.data[0].status_str}")

# List recent jobs directly from the client
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.client import Scm
from scm.exceptions import (
InvalidObjectError,
MissingQueryParameterError,
NameNotUniqueError,
ObjectNotPresentError,
ReferenceNotZeroError
)

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

try:
# Create QoS rule
rule_config = {
"name": "test-qos-rule",
"description": "Test QoS rule",
"action": {
"class": "class1"
},
"folder": "Texas"
}

new_rule = client.qos_rule.create(rule_config)

# Commit changes
result = client.commit(
folders=["Texas"],
description="Added QoS rule",
sync=True
)

# Check job status
status = client.get_job_status(result.job_id)

except InvalidObjectError as e:
print(f"Invalid rule data: {e.message}")
except NameNotUniqueError as e:
print(f"Rule name already exists: {e.message}")
except ObjectNotPresentError as e:
print(f"Rule not found: {e.message}")
except ReferenceNotZeroError as e:
print(f"Rule still in use: {e.message}")
except MissingQueryParameterError as e:
print(f"Missing parameter: {e.message}")