Skip to main content

BGP Route Map

The BgpRouteMap class manages BGP route map objects in Palo Alto Networks' Strata Cloud Manager. It extends from BaseObject and offers methods to create, retrieve, update, list, fetch, and delete BGP route maps. Route maps provide import/export policy control for BGP, defining ordered entries with match criteria and set actions. Each entry has a sequence number, a permit/deny action, optional match conditions, and optional set modifications.

note

The API uses the spelling substract (not subtract) for the metric action type. This typo is preserved in the SDK to match the API exactly.

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 BGP Route Map service directly through the client
bgp_route_maps = client.bgp_route_map
MethodDescriptionParametersReturn Type
create()Creates a new BGP route mapdata: Dict[str, Any]BgpRouteMapResponseModel
get()Retrieves a BGP route map by its unique IDobject_id: strBgpRouteMapResponseModel
update()Updates an existing BGP route maproute_map: BgpRouteMapUpdateModelBgpRouteMapResponseModel
list()Lists BGP route maps with optional filteringfolder: Optional[str], snippet: Optional[str], device: Optional[str], exact_match: bool = False, plus additional filtersList[BgpRouteMapResponseModel]
fetch()Fetches a single BGP route map by name within a containername: str, folder: Optional[str], snippet: Optional[str], device: Optional[str]BgpRouteMapResponseModel
delete()Deletes a BGP route map by its IDobject_id: strNone

BGP Route Map Model Attributes

AttributeTypeRequiredDefaultDescription
namestrYesNoneRoute map name
idUUIDYes*NoneUnique identifier (*response/update only)
route_mapList[BgpRouteMapEntry]NoNoneList of route map entries
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

Route Map Entry Configuration

The route_map attribute holds a list of entries, each with a sequence number, action, match criteria, and set actions.

BgpRouteMapEntry

AttributeTypeRequiredDescription
nameintYesSequence number (1-65535)
descriptionstrNoEntry description
actionstrNoAction: "permit" or "deny"
matchBgpRouteMapMatchNoMatch criteria
setBgpRouteMapSetNoSet actions

BgpRouteMapMatch

AttributeTypeRequiredDescription
as_path_access_liststrNoAS path access list name
interfacestrNoInterface name to match
regular_communitystrNoRegular community to match
originstrNoOrigin to match
large_communitystrNoLarge community to match
tagintNoTag value to match
extended_communitystrNoExtended community to match
local_preferenceintNoLocal preference to match
metricintNoMetric value to match
peerstrNoPeer type: "local" or "none"
ipv4BgpRouteMapMatchIpv4NoIPv4 match criteria

BgpRouteMapMatchIpv4

AttributeTypeRequiredDescription
addressstrNoIPv4 address prefix list to match
next_hopstrNoIPv4 next-hop prefix list to match
route_sourcestrNoIPv4 route source to match

BgpRouteMapSet

AttributeTypeRequiredDescription
atomic_aggregateboolNoSet atomic aggregate
local_preferenceintNoLocal preference value to set
tagintNoTag value to set
metricBgpRouteMapSetMetricNoMetric action
weightintNoWeight value to set
originstrNoOrigin: "none", "egp", "igp", "incomplete"
remove_regular_communitystrNoRegular community to remove
remove_large_communitystrNoLarge community to remove
originator_idstrNoOriginator ID to set
aggregatorBgpRouteMapSetAggregatorNoAggregator configuration
ipv4BgpRouteMapSetIpv4NoIPv4 set configuration
aspath_excludestrNoAS path to exclude
aspath_prependstrNoAS path to prepend
regular_communityList[str]NoRegular communities to set
overwrite_regular_communityboolNoOverwrite existing communities
large_communityList[str]NoLarge communities to set
overwrite_large_communityboolNoOverwrite existing large communities

BgpRouteMapSetMetric

AttributeTypeRequiredDescription
actionstrNoMetric action: "set", "add", or "substract" (API spelling)
valueintNoMetric value

BgpRouteMapSetAggregator

AttributeTypeRequiredDescription
asintNoAggregator AS number
router_idstrNoAggregator router ID

BgpRouteMapSetIpv4

AttributeTypeRequiredDescription
source_addressstrNoSource address to set
next_hopstrNoNext-hop address to set

Exceptions

ExceptionHTTP CodeDescription
InvalidObjectError400Thrown when provided data or parameters are invalid
MissingQueryParameterError400Thrown when required query parameters (e.g., name or folder) are missing
NameNotUniqueError409Route map name already exists
ObjectNotPresentError404Route map not found
ReferenceNotZeroError409Route map still referenced
AuthenticationError401Authentication failed
ServerError500Internal server error

Methods

List BGP Route Maps

# List all route maps in a folder
route_maps = client.bgp_route_map.list(
folder="Texas"
)

# Process results
for rm in route_maps:
entry_count = len(rm.route_map) if rm.route_map else 0
print(f"Name: {rm.name} ({entry_count} entries)")

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 route maps defined exactly in 'Texas'
exact_maps = client.bgp_route_map.list(
folder='Texas',
exact_match=True
)

for rm in exact_maps:
print(f"Exact match: {rm.name} in {rm.folder}")

# Exclude all route maps from the 'All' folder
no_all_maps = client.bgp_route_map.list(
folder='Texas',
exclude_folders=['All']
)

for rm in no_all_maps:
assert rm.folder != 'All'
print(f"Filtered out 'All': {rm.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.bgp_route_map.max_limit = 4000

# List all route maps - auto-paginates through results
all_maps = client.bgp_route_map.list(folder='Texas')

Fetch a BGP Route Map

# Fetch by name and folder
route_map = client.bgp_route_map.fetch(
name="inbound-policy",
folder="Texas"
)
print(f"Found route map: {route_map.name}")
if route_map.route_map:
for entry in route_map.route_map:
print(f" Seq {entry.name}: {entry.action}")
if entry.description:
print(f" Description: {entry.description}")

# Get by ID
route_map_by_id = client.bgp_route_map.get(route_map.id)
print(f"Retrieved route map: {route_map_by_id.name}")

Create a BGP Route Map

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 route map for inbound policy
inbound_map_data = {
"name": "inbound-policy",
"route_map": [
{
"name": 10,
"description": "Accept internal prefixes with higher local-pref",
"action": "permit",
"match": {
"ipv4": {
"address": "internal-prefixes"
}
},
"set": {
"local_preference": 200,
"weight": 100
}
},
{
"name": 20,
"description": "Accept all other routes with default local-pref",
"action": "permit",
"set": {
"local_preference": 100
}
}
],
"folder": "Texas"
}

new_map = client.bgp_route_map.create(inbound_map_data)
print(f"Created route map with ID: {new_map.id}")

# Create a route map with community manipulation
community_map_data = {
"name": "set-communities",
"route_map": [
{
"name": 10,
"action": "permit",
"match": {
"as_path_access_list": "customer-as-paths"
},
"set": {
"regular_community": ["65000:100", "65000:200"],
"overwrite_regular_community": True
}
}
],
"folder": "Texas"
}

community_map = client.bgp_route_map.create(community_map_data)
print(f"Created community route map with ID: {community_map.id}")

# Create a route map with AS path prepending
prepend_map_data = {
"name": "as-prepend-outbound",
"route_map": [
{
"name": 10,
"description": "Prepend AS path to de-prefer this path",
"action": "permit",
"match": {
"ipv4": {
"address": "backup-prefixes"
}
},
"set": {
"aspath_prepend": "65000 65000 65000",
"metric": {
"action": "set",
"value": 200
}
}
},
{
"name": 100,
"action": "permit"
}
],
"folder": "Texas"
}

prepend_map = client.bgp_route_map.create(prepend_map_data)
print(f"Created AS-prepend route map with ID: {prepend_map.id}")

Update a BGP Route Map

# Fetch existing route map
existing_map = client.bgp_route_map.fetch(
name="inbound-policy",
folder="Texas"
)

# Add a deny entry for bogon prefixes at the beginning
existing_map.route_map.insert(0, {
"name": 5,
"description": "Deny bogon prefixes",
"action": "deny",
"match": {
"ipv4": {
"address": "bogon-prefixes"
}
}
})

# Perform update
updated_map = client.bgp_route_map.update(existing_map)

Delete a BGP Route Map

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

Use Cases

Performing Commits

# Prepare commit parameters
commit_params = {
"folders": ["Texas"],
"description": "Updated BGP route map 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 BGP route map
map_config = {
"name": "test-route-map",
"route_map": [
{
"name": 10,
"action": "permit",
"set": {
"local_preference": 150
}
}
],
"folder": "Texas"
}

new_map = client.bgp_route_map.create(map_config)

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

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

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