Getting Started with pan-scm-sdk
Welcome to the pan-scm-sdk
! This guide will walk you through the initial setup and basic usage of the SDK to interact
with Palo Alto Networks Strata Cloud Manager.
Installation
Requirements:
- Python 3.10 or higher
Install the package via pip:
pip install pan-scm-sdk
Authentication
Before using the SDK, you need to authenticate with Strata Cloud Manager using your client credentials.
Example:
from scm.client import Scm
# Initialize the SCM client with your credentialsapi_client = Scm(
client_id="your_client_id",
client_secret="your_client_secret",
tsg_id="your_tsg_id",
)
# The SCM client is now ready to use
# Initialize the SCM client with your credentialsapi_client = Scm(
client_id="your_client_id",
client_secret="your_client_secret",
tsg_id="your_tsg_id",
)
# The SCM client is now ready to use
client_id
: Your OAuth2 client ID.client_secret
: Your OAuth2 client secret.tsg_id
: Your Tenant Service Group ID.
Basic Usage
The SDK provides classes to manage various configuration objects. Below are examples of how to use the SDK to manage addresses, address groups, and applications.
Managing Addresses
from scm.config.objects import Address
# Create an Address instanceaddress = Address(api_client)
# Create a new addressaddress_data = {
"name": "test-address",
"fqdn": "test.example.com",
"description": "Created via pan-scm-sdk",
"folder": "Prisma Access",
}
new_address = address.create(address_data)
print(f"Created address with ID: {new_address.id}")
# List addressesaddresses = address.list(folder='Prisma Access')
for addr in addresses:
print(f"Address Name: {addr.name}, IP: {addr.ip_netmask or addr.fqdn}")
# Create an Address instanceaddress = Address(api_client)
# Create a new addressaddress_data = {
"name": "test-address",
"fqdn": "test.example.com",
"description": "Created via pan-scm-sdk",
"folder": "Prisma Access",
}
new_address = address.create(address_data)
print(f"Created address with ID: {new_address.id}")
# List addressesaddresses = address.list(folder='Prisma Access')
for addr in addresses:
print(f"Address Name: {addr.name}, IP: {addr.ip_netmask or addr.fqdn}")
Managing Address Groups
from scm.config.objects import AddressGroup
# Create an AddressGroup instanceaddress_group = AddressGroup(api_client)
# Create a new address groupaddress_group_data = {
"name": "example-group",
"description": "Test address group",
"static": ["test-address"],
"folder": "Prisma Access",
}
new_group = address_group.create(address_group_data)
print(f"Created address group with ID: {new_group.id}")
# List address groupsgroups = address_group.list(folder='Prisma Access')
for group in groups:
print(f"Address Group Name: {group.name}")
# Create an AddressGroup instanceaddress_group = AddressGroup(api_client)
# Create a new address groupaddress_group_data = {
"name": "example-group",
"description": "Test address group",
"static": ["test-address"],
"folder": "Prisma Access",
}
new_group = address_group.create(address_group_data)
print(f"Created address group with ID: {new_group.id}")
# List address groupsgroups = address_group.list(folder='Prisma Access')
for group in groups:
print(f"Address Group Name: {group.name}")
Managing Applications
from scm.config.objects import Application
# Create an Application instanceapplication = Application(api_client)
# Create a new applicationapplication_data = {
"name": "test-app",
"category": "collaboration",
"subcategory": "internet-conferencing",
"technology": "client-server",
"risk": 1,
"description": "Created via pan-scm-sdk",
"ports": ["tcp/80,443"],
"folder": "Prisma Access",
}
new_application = application.create(application_data)
print(f"Created application with ID: {new_application.id}")
# List applicationsapplications = application.list(folder='Prisma Access')
for app in applications:
print(f"Application Name: {app.name}, Category: {app.category}")
# Create an Application instanceapplication = Application(api_client)
# Create a new applicationapplication_data = {
"name": "test-app",
"category": "collaboration",
"subcategory": "internet-conferencing",
"technology": "client-server",
"risk": 1,
"description": "Created via pan-scm-sdk",
"ports": ["tcp/80,443"],
"folder": "Prisma Access",
}
new_application = application.create(application_data)
print(f"Created application with ID: {new_application.id}")
# List applicationsapplications = application.list(folder='Prisma Access')
for app in applications:
print(f"Application Name: {app.name}, Category: {app.category}")
Next Steps
- Explore the SDK Developer Documentation for detailed information on classes and methods.
- Refer to the Usage Examples for more practical examples.