Skip to main content

BGP Route Map Redistribution

The BgpRouteMapRedistribution class manages BGP route map redistribution 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 map redistributions. This is the most complex routing model, using 2-level oneOf discrimination:

  • Level 1 (Source Protocol): bgp, ospf, or connected_static -- mutually exclusive
  • Level 2 (Target Protocol): Within each source, the target protocol is also mutually exclusive

This produces 7 possible crossover variants, each with variant-specific match and set fields:

SourceTargetMatch TypeSet Type
bgpospfBGP matchOSPF set
bgpribBGP matchRIB set
ospfbgpSimple matchBGP set
ospfribSimple matchRIB set
connected_staticbgpSimple matchBGP set
connected_staticospfSimple matchOSPF set
connected_staticribSimple matchRIB set

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 Redistribution service directly through the client
bgp_route_map_redists = client.bgp_route_map_redistribution
MethodDescriptionParametersReturn Type
create()Creates a new BGP route map redistributiondata: Dict[str, Any]BgpRouteMapRedistributionResponseModel
get()Retrieves a BGP route map redistribution by its unique IDobject_id: strBgpRouteMapRedistributionResponseModel
update()Updates an existing BGP route map redistributionresource: BgpRouteMapRedistributionUpdateModelBgpRouteMapRedistributionResponseModel
list()Lists BGP route map redistributions with optional filteringfolder: Optional[str], snippet: Optional[str], device: Optional[str], exact_match: bool = False, plus additional filtersList[BgpRouteMapRedistributionResponseModel]
fetch()Fetches a single BGP route map redistribution by name within a containername: str, folder: Optional[str], snippet: Optional[str], device: Optional[str]BgpRouteMapRedistributionResponseModel
delete()Deletes a BGP route map redistribution by its IDobject_id: strNone

BGP Route Map Redistribution Model Attributes

AttributeTypeRequiredDefaultDescription
namestrYesNoneRedistribution name
idUUIDYes*NoneUnique identifier (*response/update only)
bgpBgpRouteMapRedistBgpSourceNoNoneBGP as source protocol (mutually exclusive)
ospfBgpRouteMapRedistOspfSourceNoNoneOSPF as source protocol (mutually exclusive)
connected_staticBgpRouteMapRedistConnectedStaticSourceNoNoneConnected/Static as source (mutually exclusive)
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

At most one source protocol (bgp, ospf, or connected_static) can be set per redistribution object.

Source Protocol Configuration

BgpRouteMapRedistBgpSource

BGP as source protocol. Targets are mutually exclusive.

AttributeTypeRequiredDescription
ospfBgpRouteMapRedistBgpToOspfNoRedistribute BGP routes to OSPF
ribBgpRouteMapRedistBgpToRibNoRedistribute BGP routes to RIB

BgpRouteMapRedistOspfSource

OSPF as source protocol. Targets are mutually exclusive.

AttributeTypeRequiredDescription
bgpBgpRouteMapRedistOspfToBgpNoRedistribute OSPF routes to BGP
ribBgpRouteMapRedistOspfToRibNoRedistribute OSPF routes to RIB

BgpRouteMapRedistConnectedStaticSource

Connected/Static as source protocol. Targets are mutually exclusive.

AttributeTypeRequiredDescription
bgpBgpRouteMapRedistConnStaticToBgpNoRedistribute connected/static routes to BGP
ospfBgpRouteMapRedistConnStaticToOspfNoRedistribute connected/static routes to OSPF
ribBgpRouteMapRedistConnStaticToRibNoRedistribute connected/static routes to RIB

Route Map Entry (all target containers)

Each target container holds a route_map list of entries. The entry structure is the same across all variants:

AttributeTypeRequiredDescription
nameintYesSequence number (1-65535)
descriptionstrNoEntry description
actionstrNoAction: "permit" or "deny"
match(variant-specific)NoMatch criteria
set(variant-specific)NoSet actions

BGP Match (for BGP source variants)

AttributeTypeRequiredDescription
as_path_access_liststrNoAS path access list name
regular_communitystrNoRegular community to match
large_communitystrNoLarge community to match
extended_communitystrNoExtended community to match
interfacestrNoInterface to match
tagintNoTag value to match
local_preferenceintNoLocal preference to match
metricintNoMetric to match
originstrNoOrigin to match
peerstrNoPeer type: "local" or "none"
ipv4BgpRouteMapRedistBgpMatchIpv4NoIPv4 match (address, next_hop, route_source)

Simple Match (for OSPF/connected_static source variants)

AttributeTypeRequiredDescription
interfacestrNoInterface to match
metricintNoMetric to match
tagintNoTag to match
ipv4BgpRouteMapRedistSimpleMatchIpv4NoIPv4 match (address, next_hop)

BGP Set (when target is BGP)

Full BGP set fields including communities, AS-path, local preference, weight, etc.

AttributeTypeRequiredDescription
atomic_aggregateboolNoSet atomic aggregate
local_preferenceintNoLocal preference to set
tagintNoTag to set
metricBgpRouteMapRedistSetMetricNoMetric action (set/add/substract)
weightintNoWeight to set
originstrNoOrigin to set
aggregatorBgpRouteMapRedistSetAggregatorNoAggregator config
ipv4BgpRouteMapRedistSetIpv4NoIPv4 set config
aspath_excludestrNoAS path to exclude
aspath_prependstrNoAS path to prepend
regular_communityList[str]NoCommunities to set
overwrite_regular_communityboolNoOverwrite communities
large_communityList[str]NoLarge communities to set
overwrite_large_communityboolNoOverwrite large communities

OSPF Set (when target is OSPF)

AttributeTypeRequiredDescription
metricBgpRouteMapRedistSetMetricNoMetric action (set/add/substract)
metric_typestrNoOSPF metric type
tagintNoTag to set

RIB Set (when target is RIB)

AttributeTypeRequiredDescription
ipv4BgpRouteMapRedistSetIpv4NoIPv4 set (source_address)

Exceptions

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

Methods

List BGP Route Map Redistributions

# List all route map redistributions in a folder
redists = client.bgp_route_map_redistribution.list(
folder="Texas"
)

# Process results
for redist in redists:
source = "unknown"
if redist.bgp:
source = "bgp"
elif redist.ospf:
source = "ospf"
elif redist.connected_static:
source = "connected_static"
print(f"Name: {redist.name} (source: {source})")

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 redistributions defined exactly in 'Texas'
exact_redists = client.bgp_route_map_redistribution.list(
folder='Texas',
exact_match=True
)

for redist in exact_redists:
print(f"Exact match: {redist.name} in {redist.folder}")

# Exclude all redistributions from the 'All' folder
no_all_redists = client.bgp_route_map_redistribution.list(
folder='Texas',
exclude_folders=['All']
)

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

# List all redistributions - auto-paginates through results
all_redists = client.bgp_route_map_redistribution.list(folder='Texas')

Fetch a BGP Route Map Redistribution

# Fetch by name and folder
redist = client.bgp_route_map_redistribution.fetch(
name="ospf-to-bgp-redist",
folder="Texas"
)
print(f"Found redistribution: {redist.name}")

# Determine the source protocol
if redist.bgp:
print(" Source: BGP")
elif redist.ospf:
print(" Source: OSPF")
elif redist.connected_static:
print(" Source: Connected/Static")

# Get by ID
redist_by_id = client.bgp_route_map_redistribution.get(redist.id)
print(f"Retrieved redistribution: {redist_by_id.name}")

Create a BGP Route Map Redistribution

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 OSPF-to-BGP redistribution
ospf_to_bgp_data = {
"name": "ospf-to-bgp-redist",
"ospf": {
"bgp": {
"route_map": [
{
"name": 10,
"description": "Redistribute OSPF internal routes to BGP",
"action": "permit",
"match": {
"tag": 100
},
"set": {
"local_preference": 200,
"regular_community": ["65000:100"],
"origin": "igp"
}
},
{
"name": 20,
"action": "permit",
"set": {
"local_preference": 100
}
}
]
}
},
"folder": "Texas"
}

new_redist = client.bgp_route_map_redistribution.create(ospf_to_bgp_data)
print(f"Created OSPF-to-BGP redistribution with ID: {new_redist.id}")

# Create BGP-to-OSPF redistribution
bgp_to_ospf_data = {
"name": "bgp-to-ospf-redist",
"bgp": {
"ospf": {
"route_map": [
{
"name": 10,
"description": "Redistribute specific BGP routes to OSPF",
"action": "permit",
"match": {
"as_path_access_list": "internal-as-paths",
"ipv4": {
"address": "bgp-prefixes-for-ospf"
}
},
"set": {
"metric": {
"action": "set",
"value": 500
},
"metric_type": "type-2",
"tag": 200
}
}
]
}
},
"folder": "Texas"
}

bgp_ospf_redist = client.bgp_route_map_redistribution.create(bgp_to_ospf_data)
print(f"Created BGP-to-OSPF redistribution with ID: {bgp_ospf_redist.id}")

# Create connected/static-to-BGP redistribution
conn_to_bgp_data = {
"name": "connected-to-bgp-redist",
"connected_static": {
"bgp": {
"route_map": [
{
"name": 10,
"description": "Redistribute connected interfaces to BGP",
"action": "permit",
"match": {
"interface": "ethernet1/1"
},
"set": {
"local_preference": 300,
"weight": 200,
"origin": "igp"
}
}
]
}
},
"folder": "Texas"
}

conn_bgp_redist = client.bgp_route_map_redistribution.create(conn_to_bgp_data)
print(f"Created connected-to-BGP redistribution with ID: {conn_bgp_redist.id}")

Update a BGP Route Map Redistribution

# Fetch existing redistribution
existing_redist = client.bgp_route_map_redistribution.fetch(
name="ospf-to-bgp-redist",
folder="Texas"
)

# Add a deny entry for specific tags
existing_redist.ospf.bgp.route_map.insert(0, {
"name": 5,
"description": "Deny routes with tag 999",
"action": "deny",
"match": {
"tag": 999
}
})

# Perform update
updated_redist = client.bgp_route_map_redistribution.update(existing_redist)

Delete a BGP Route Map Redistribution

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

Use Cases

Performing Commits

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

new_redist = client.bgp_route_map_redistribution.create(redist_config)

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

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

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