Skip to content

IKE Gateway

The IKEGateway class provides functionality to manage Internet Key Exchange (IKE) gateway objects in Palo Alto Networks' Strata Cloud Manager. This class inherits from BaseObject and provides methods for creating, retrieving, updating, and deleting IKE gateway configurations used for establishing VPN tunnels.

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 IKE Gateway service directly through the client
# No need to create a separate IKEGateway instance
ike_gateways = client.ike_gateway
Method Description Parameters Return Type
create() Creates a new IKE gateway data: Dict[str, Any] IKEGatewayResponseModel
get() Retrieves an IKE gateway by ID object_id: str IKEGatewayResponseModel
update() Updates an existing IKE gateway gateway: IKEGatewayUpdateModel IKEGatewayResponseModel
delete() Deletes an IKE gateway object_id: str None
list() Lists IKE gateways with filtering folder: str, **filters List[IKEGatewayResponseModel]
fetch() Gets IKE gateway by name and container name: str, folder: str IKEGatewayResponseModel

IKE Gateway Model Attributes

Attribute Type Required Default Description
name str Yes None Name of IKE gateway. Max 63 chars. Pattern: ^[0-9a-zA-Z._\-]+$
id UUID Yes* None Unique identifier (*response/update only)
authentication Authentication Yes None Authentication configuration (pre-shared key or certificate)
peer_id PeerId No None Peer identification information
local_id LocalId No None Local identification information
protocol Protocol Yes None IKE protocol configuration
protocol_common ProtocolCommon No None Common protocol settings (NAT traversal, fragmentation)
peer_address PeerAddress Yes None Peer address configuration (IP, FQDN, or dynamic)
folder str No** None Folder location. Max 64 chars
snippet str No** None Snippet location. Max 64 chars
device str No** None Device location. Max 64 chars

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

Exceptions

Exception HTTP Code Description
InvalidObjectError 400 Invalid IKE gateway data or format
MissingQueryParameterError 400 Missing required parameters
NameNotUniqueError 409 IKE gateway name already exists
ObjectNotPresentError 404 IKE gateway not found
ReferenceNotZeroError 409 IKE gateway still referenced
AuthenticationError 401 Authentication failed
ServerError 500 Internal server error

Methods

List IKE Gateways

Filtering Responses

The list() method supports additional parameters to refine your query results even further. 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 IKE gateways defined exactly in 'VPN'
exact_gateways = client.ike_gateway.list(
   folder='VPN',
   exact_match=True
)

for gateway in exact_gateways:
   print(f"Exact match: {gateway.name} in {gateway.folder}")

# Exclude all IKE gateways from the 'Shared' folder
no_shared_gateways = client.ike_gateway.list(
   folder='VPN',
   exclude_folders=['Shared']
)

for gateway in no_shared_gateways:
   assert gateway.folder != 'Shared'
   print(f"Filtered out 'Shared': {gateway.name}")

# Exclude gateways that come from 'default' snippet
no_default_snippet = client.ike_gateway.list(
   folder='VPN',
   exclude_snippets=['default']
)

for gateway in no_default_snippet:
   assert gateway.snippet != 'default'
   print(f"Filtered out 'default' snippet: {gateway.name}")

# Exclude gateways associated with 'DeviceA'
no_deviceA = client.ike_gateway.list(
   folder='VPN',
   exclude_devices=['DeviceA']
)

for gateway in no_deviceA:
   assert gateway.device != 'DeviceA'
   print(f"Filtered out 'DeviceA': {gateway.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.ike_gateway.max_limit = 4000

# List all IKE gateways - auto-paginates through results
all_gateways = client.ike_gateway.list(folder='VPN')

# The gateways are fetched in chunks according to the max_limit setting.

Fetch an IKE Gateway

Create an IKE Gateway

from scm.client import Scm

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

# Prepare IKE Gateway configuration with pre-shared key
psk_config = {
   "name": "site-a-gateway",
   "authentication": {
       "pre_shared_key": {
           "key": "your-secure-key"
       }
   },
   "peer_id": {
       "type": "ipaddr",
       "id": "203.0.113.1"
   },
   "protocol": {
       "version": "ikev2",
       "ikev2": {
           "ike_crypto_profile": "default",
           "dpd": {
               "enable": True
           }
       }
   },
   "peer_address": {
       "ip": "203.0.113.1"
   },
   "folder": "VPN"
}

# Create the IKE gateway object
psk_gateway = client.ike_gateway.create(psk_config)

# Prepare IKE Gateway with certificate authentication
cert_config = {
   "name": "site-b-gateway",
   "authentication": {
       "certificate": {
           "certificate_profile": "default-profile",
           "local_certificate": {
               "local_certificate_name": "cert-name"
           }
       }
   },
   "protocol": {
       "version": "ikev2-preferred",
       "ikev1": {
           "ike_crypto_profile": "default"
       },
       "ikev2": {
           "ike_crypto_profile": "default"
       }
   },
   "peer_address": {
       "fqdn": "vpn.example.com"
   },
   "folder": "VPN"
}

# Create the certificate-based IKE gateway
cert_gateway = client.ike_gateway.create(cert_config)

Update an IKE Gateway

Delete an IKE Gateway

Use Cases

Performing Commits

# Prepare commit parameters
commit_params = {
   "folders": ["VPN"],
   "description": "Added new IKE gateway configurations",
   "sync": True,
   "timeout": 300  # 5 minute timeout
}

# Commit the changes
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
)

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

try:
   # Create IKE gateway configuration
   gateway_config = {
      "name": "test-gateway",
      "authentication": {
          "pre_shared_key": {
              "key": "secure-key"
          }
      },
      "protocol": {
          "version": "ikev2",
          "ikev2": {
              "ike_crypto_profile": "default"
          }
      },
      "peer_address": {
          "ip": "203.0.113.1"
      },
      "folder": "VPN"
   }

   # Create the IKE gateway using the unified client interface
   new_gateway = client.ike_gateway.create(gateway_config)

   # Commit changes directly from the client
   result = client.commit(
      folders=["VPN"],
      description="Added test gateway",
      sync=True
   )

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

except InvalidObjectError as e:
   print(f"Invalid gateway data: {e.message}")
except NameNotUniqueError as e:
   print(f"Gateway name already exists: {e.message}")
except ObjectNotPresentError as e:
   print(f"Gateway not found: {e.message}")
except MissingQueryParameterError as e:
   print(f"Missing parameter: {e.message}")