Skip to main content

Service Connections Configuration Object

Manages service connection objects for establishing connectivity to cloud service providers in Palo Alto Networks Strata Cloud Manager.

Class Overview

The ServiceConnection class inherits from BaseObject and provides CRUD operations for service connection objects.

Methods

MethodDescriptionParametersReturn Type
create()Creates a new service connectiondata: Dict[str, Any]ServiceConnectionResponseModel
get()Retrieves a service connection by IDobject_id: strServiceConnectionResponseModel
update()Updates an existing service connectionservice_connection: ServiceConnectionUpdateModelServiceConnectionResponseModel
delete()Deletes a service connectionobject_id: strNone
list()Lists service connections with filteringname: Optional[str], **filtersList[ServiceConnectionResponseModel]
fetch()Gets service connection by namename: strServiceConnectionResponseModel

Model Attributes

AttributeTypeRequiredDefaultDescription
namestrYesNoneName of service connection (max 63 chars)
idUUIDYes*NoneUnique identifier (*response only)
folderstrNoService ConnectionsFolder containing the service connection
ipsec_tunnelstrYesNoneIPsec tunnel for the service connection
onboarding_typeOnboardingTypeNoclassicOnboarding type
regionstrYesNoneRegion for the service connection
backup_SCstrNoNoneBackup service connection
bgp_peerBgpPeerModelNoNoneBGP peer configuration
nat_poolstrNoNoneNAT pool
no_export_communityNoExportCommunityNoNoneNo export community configuration
protocolProtocolModelNoNoneProtocol configuration
qosQosModelNoNoneQoS configuration
secondary_ipsec_tunnelstrNoNoneSecondary IPsec tunnel
source_natboolNoNoneEnable source NAT
subnetsList[str]NoNoneSubnets for the service connection

* Only required for response models

Exceptions

ExceptionHTTP CodeDescription
InvalidObjectError400Invalid service connection data or format
MissingQueryParameterError400Missing required parameters
ObjectNotPresentError404Service connection not found
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"
)

service_connections = client.service_connection

Methods

List Service Connections

all_connections = client.service_connection.list()

for conn in all_connections:
print(f"Service Connection: {conn.name}, Region: {conn.region}")

Filtering responses:

# Filter by name
filtered_connections = client.service_connection.list(name="aws")

# Filter by region
us_east_connections = client.service_connection.list(region="us-east-1")

Controlling pagination with max_limit:

client.service_connection.max_limit = 500

all_connections = client.service_connection.list()

Fetch a Service Connection

service_connection = client.service_connection.fetch(name="aws-service-connection")
print(f"Found service connection: {service_connection.name}")

Create a Service Connection

service_connection_config = {
"name": "aws-service-connection",
"ipsec_tunnel": "aws-ipsec-tunnel",
"region": "us-east-1",
"onboarding_type": "classic",
"subnets": ["10.0.0.0/24", "192.168.1.0/24"],
"bgp_peer": {
"local_ip_address": "192.168.1.1",
"peer_ip_address": "192.168.1.2",
},
"protocol": {
"bgp": {
"enable": True,
"peer_as": "65000",
}
},
"source_nat": True,
}
service_connection = client.service_connection.create(service_connection_config)

Update a Service Connection

existing_connection = client.service_connection.fetch(name="aws-service-connection")

existing_connection.subnets = ["10.0.0.0/24", "192.168.1.0/24", "172.16.0.0/24"]
existing_connection.source_nat = False

updated_connection = client.service_connection.update(existing_connection)

Delete a Service Connection

client.service_connection.delete("123e4567-e89b-12d3-a456-426655440000")

Get a Service Connection by ID

service_connection_by_id = client.service_connection.get(service_connection.id)
print(f"Retrieved service connection: {service_connection_by_id.name}")

Use Cases

Committing Changes

result = client.commit(
folders=["Service Connections"],
description="Added new service connection",
sync=True,
timeout=300
)
print(f"Commit job ID: {result.job_id}")

Monitoring Jobs

job_status = client.get_job_status(result.job_id)
print(f"Job status: {job_status.data[0].status_str}")

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.exceptions import (
InvalidObjectError,
MissingQueryParameterError,
ObjectNotPresentError
)

try:
service_connection_config = {
"name": "test-connection",
"ipsec_tunnel": "test-tunnel",
"region": "us-east-1",
"onboarding_type": "classic",
"subnets": ["10.0.0.0/24"]
}
new_connection = client.service_connection.create(service_connection_config)
result = client.commit(
folders=["Service Connections"],
description="Added test service connection",
sync=True
)
status = client.get_job_status(result.job_id)

except InvalidObjectError as e:
print(f"Invalid service connection data: {e.message}")
except ObjectNotPresentError as e:
print(f"Service connection not found: {e.message}")
except MissingQueryParameterError as e:
print(f"Missing parameter: {e.message}")