-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (29 loc) · 1.35 KB
/
Copy pathmain.py
File metadata and controls
43 lines (29 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# These imports are required to parse through the xml file.
import xml.etree.ElementTree as ET
import sys
baseTag = "{http://schemas.microsoft.com/office/infopath/2003/myXSD/2019-03-01T06:37:18}"
# The location of the file from which the IP address should be parsed.
root = ET.parse('./IP_Subnet_VLAN_aanvraag_landelijk_datacenter_Aanvragen-2020-07-23T16_47_22.xml').getroot()
#Searching for the subnets
subNetVLAN = root.find(f"{baseTag}SubnetVlan")
if subNetVLAN is None:
print("Tag my:SubnetVlan doesn't exists, killing script")
sys.exit()
sVipHelpersGR = subNetVLAN.find(f"{baseTag}SVIPHelpersGr")
if sVipHelpersGR is None:
print("Tag my:my:SVIPHelpersGr doesn't exists, killing script")
sys.exit()
# A list of all the items with the following xml tag: my:SVIPHelper
sVipIps = {}
sVipBaseKey = "IP helper addr"
# A list of all the items with the following xml tag: my:SVIPHelper
# this is the section where the IP helper addresses are located.
for elem in sVipHelpersGR.findall(f"{baseTag}SVIPHelpers"):
for subElem in elem.findall(f"{baseTag}SVIPHelper"):
sVipIps[f"{sVipBaseKey} {len(sVipIps) + 1}"] = subElem.text
sVipSubnets = {}
sVipSubnetBaseKey = "Subnet"
# A variable with the value of my:SVIPSubnet this i
sVipSubnets[f"{sVipSubnetBaseKey}"] = subNetVLAN.find(f"{baseTag}SVIPSubnet").text
print(sVipIps)
print(sVipSubnets)