Using the XGS-API to delete a VLAN via python #97
Replies: 1 comment
-
|
Hi, this one is a little bit tricky because the key for VLANs is the hardware name of the VLAN rather than the name. To remove, you need to specify the interface name as the `name` argument and add the `key` argument with value of `Hardware`. For example:
fw.remove(xml_tag="VLAN", name="PortA.10", key="Hardware")
The hardware name is generated automatically when you create the VLAN and can be seen in the UI under the Misc column. It also appears if you do a fw.get_tag_with_filter:
fw.get_tag_with_filter(xml_tag="VLAN", key="Name", value="test")['Response']['VLAN']['Hardware']
Out[18]: 'PortA.10'
The fact that it says “Configuration applied successfully” when it fails to remove the VLAN is a bug that we’ll need to address.
From: jonrei97 ***@***.***>
Date: Tuesday, October 14, 2025 at 7:25 AM
To: sophos/sophos-firewall-sdk ***@***.***>
Cc: Subscribed ***@***.***>
Subject: [sophos/sophos-firewall-sdk] Using the XGS-API to delete a VLAN via python (Discussion #97)
Hello,
iam currently in the process of migrating my vlans from one old switch to a new switch stack. For that purpose i need to read and delete all existing vlans of a specific interface and then create them on a different interface. The read and create part worked perfectly fine for me however iam struggeling with deleting a vlan using the API with python and the sophosfirewall_python Package.
The returned output i get for the delete command says the VLAN was successfully deleted, however when i check via gui or via API the VLAN is still existing.
What am i doing wrong? When i try to delete in the WebUI it works as usual, are there any dependencys i need to remove via API prior to the delete which are handled automatically in the WebUI:
from sophosfirewall_python.firewallapi import SophosFirewall
FIREWALL_USERNAME = "apiuser"
FIREWALL_PASSWORD = "apipassword"
FIREWALL_HOST_OR_IP = "myfirewall"
FIREWALL_PORT = "4444"
fw = SophosFirewall(
username=FIREWALL_USERNAME,
password=FIREWALL_PASSWORD,
hostname=FIREWALL_HOST_OR_IP,
port=FIREWALL_PORT,
verify=False
)
delete_test_vlan = fw.remove(xml_tag="VLAN", name="Test-VLAN")
print(delete_test_vlan)
this is the response i get:
{'Response': ***@***.***<https://eu-west-1.protection.sophos.com?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL2FwaXZlcnNpb24=&i=NjI2MGY4MzEzOTcwM2UxMTEyNWRlYjFl&t=bDV6Q3Zua3BnM2xwdEtlWUEyazJWZkNRVjAxWFc0dXBHMnNEbnZlSUNIWT0=&h=611bc96d3ddd48f49f765d8fbe08410d&s=AVNPUEhUT0NFTkNSWVBUSVa7Z56Wl0HUa2InR2X4iZf_VhFb887oT0fj-Wj-_R9rEA>': '2105.1', ***@***.***_CAT_VER': '1', ***@***.***_WIFI6': '0', 'Login': {'status': 'Authentication Successful'},
—
Reply to this email directly, view it on GitHub<https://eu-west-1.protection.sophos.com?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL3NvcGhvcy9zb3Bob3MtZmlyZXdhbGwtc2RrL2Rpc2N1c3Npb25zLzk3&i=NjI2MGY4MzEzOTcwM2UxMTEyNWRlYjFl&t=ZUsvZ3ZHaUFZbFdzUThLanJEcXlqN0ZKRlpqZ3dTb0FzcEZhQlpsTG41OD0=&h=611bc96d3ddd48f49f765d8fbe08410d&s=AVNPUEhUT0NFTkNSWVBUSVa7Z56Wl0HUa2InR2X4iZf_VhFb887oT0fj-Wj-_R9rEA>, or unsubscribe<https://eu-west-1.protection.sophos.com?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL25vdGlmaWNhdGlvbnMvdW5zdWJzY3JpYmUtYXV0aC9BQlU3VFRMQU1BQU5YVDZNN1JEMkhOMzNYVE1TSEFWQ05GU002QUFBQUFDSkVKV0FBT1ZISTJEU01WUVdJWDNMTVY0M0VSREpPTlJYSzQzVE5GWFc0T1paR0FaREtOUllHSQ==&i=NjI2MGY4MzEzOTcwM2UxMTEyNWRlYjFl&t=M2YraXI5cTBJbzgvb2VhQ3JhQUlacE9sSmtMeU10eEd0bzJTMk82Nmx2dz0=&h=611bc96d3ddd48f49f765d8fbe08410d&s=AVNPUEhUT0NFTkNSWVBUSVa7Z56Wl0HUa2InR2X4iZf_VhFb887oT0fj-Wj-_R9rEA>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jonrei97
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
iam currently in the process of migrating my vlans from one old switch to a new switch stack. For that purpose i need to read and delete all existing vlans of a specific interface and then create them on a different interface. The read and create part worked perfectly fine for me however iam struggeling with deleting a vlan using the API with python and the sophosfirewall_python Package.
The returned output i get for the delete command says the VLAN was successfully deleted, however when i check via gui or via API the VLAN is still existing.
What am i doing wrong? When i try to delete in the WebUI it works as usual, are there any dependencys i need to remove via API prior to the delete which are handled automatically in the WebUI:
this is the response i get:
{'Response': {'@apiversion': '2105.1', '@IPS_CAT_VER': '1', '@IS_WIFI6': '0', 'Login': {'status': 'Authentication Successful'},
Beta Was this translation helpful? Give feedback.
All reactions