Skip to main content

Layer2 Subinterface

The Layer2Subinterface class manages Layer 2 subinterface objects in Palo Alto Networks' Strata Cloud Manager. Layer 2 subinterfaces operate at the data link layer and are used for VLAN-tagged traffic on physical interfaces, enabling VLAN trunking.

Class Overview​

from scm.client import Scm

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

layer2_subinterfaces = client.layer2_subinterface
MethodDescriptionParametersReturn Type
create()Creates a new Layer 2 subinterfacedata: Dict[str, Any]Layer2SubinterfaceResponseModel
get()Retrieves a Layer 2 subinterface by IDobject_id: strLayer2SubinterfaceResponseModel
update()Updates an existing Layer 2 subinterfacesubinterface: Layer2SubinterfaceUpdateModelLayer2SubinterfaceResponseModel
list()Lists Layer 2 subinterfaces with optional filteringfolder, snippet, device, plus filtersList[Layer2SubinterfaceResponseModel]
fetch()Fetches a single Layer 2 subinterface by name within a containername: str, folder, snippet, deviceLayer2SubinterfaceResponseModel
delete()Deletes a Layer 2 subinterface by IDobject_id: strNone

Layer2 Subinterface Model Attributes​

AttributeTypeRequiredDefaultDescription
namestrYesNoneInterface name (e.g., "ethernet1/1.100")
idUUIDYes*NoneUnique identifier (*response/update only)
commentstrNoNoneDescription. Max 1023 chars
vlan_tagstrYesNoneVLAN tag (1-4096)
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 must be provided for create operations

Exceptions​

ExceptionHTTP CodeDescription
InvalidObjectError400Invalid data or parameters
MissingQueryParameterError400Missing required parameters
ObjectNotPresentError404Interface not found
AuthenticationError401Authentication failed
ServerError500Internal server error

Methods​

List Layer2 Subinterfaces​

# List all Layer 2 subinterfaces
subinterfaces = client.layer2_subinterface.list(folder="Interfaces")

for sub in subinterfaces:
print(f"Name: {sub.name}, VLAN: {sub.vlan_tag}")

# Filter by VLAN tag
vlan100 = client.layer2_subinterface.list(folder="Interfaces", vlan_tag="100")

Fetch a Layer2 Subinterface​

# Fetch by name
subinterface = client.layer2_subinterface.fetch(
name="ethernet1/1.100",
folder="Interfaces"
)
print(f"Found: {subinterface.name}, VLAN: {subinterface.vlan_tag}")

# Get by ID
subinterface_by_id = client.layer2_subinterface.get(subinterface.id)

Create a Layer2 Subinterface​

# Create Layer 2 subinterface with VLAN tag
subinterface_data = {
"name": "ethernet1/1.100",
"comment": "VLAN 100 - Guest Network",
"vlan_tag": "100",
"folder": "Interfaces"
}

result = client.layer2_subinterface.create(subinterface_data)
print(f"Created subinterface: {result.id}")

# Create multiple subinterfaces for different VLANs
vlans = [
{"name": "ethernet1/1.200", "vlan_tag": "200", "comment": "VLAN 200 - IoT"},
{"name": "ethernet1/1.300", "vlan_tag": "300", "comment": "VLAN 300 - Voice"},
]

for vlan in vlans:
vlan["folder"] = "Interfaces"
result = client.layer2_subinterface.create(vlan)
print(f"Created: {result.name}")

Update a Layer2 Subinterface​

existing = client.layer2_subinterface.fetch(
name="ethernet1/1.100",
folder="Interfaces"
)

existing.comment = "Updated Guest Network VLAN"

updated = client.layer2_subinterface.update(existing)

Delete a Layer2 Subinterface​

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

Use Cases​

Managing Configuration Changes​

result = client.commit(
folders=["Interfaces"],
description="Updated Layer 2 subinterfaces",
sync=True
)

Error Handling​

from scm.exceptions import InvalidObjectError

try:
subinterface = client.layer2_subinterface.create({
"name": "ethernet1/1.100",
"vlan_tag": "5000", # Error: VLAN out of range
"folder": "Interfaces"
})
except InvalidObjectError as e:
print(f"Invalid configuration: {e.message}")