Skip to content

Commit 720a78e

Browse files
authored
fix: Correcting profile xpaths (#333)
This fixes #266. The correct XPATH for profiles when directly configured in Panorama is /config/panorama not /config/shared. To support this, a new object ROOT was created: PANORAMA_VSYS, which allows a fallback ROOT of VSYS, but will otherwise be /config/panorama if the object is directly connected to a Panorama PanDevice object.
1 parent 2ca4b31 commit 720a78e

File tree

3 files changed

+286
-10
lines changed

3 files changed

+286
-10
lines changed

panos/base.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
logger = panos.getlogger(__name__)
4242

43-
Root = panos.enum("DEVICE", "VSYS", "MGTCONFIG")
43+
Root = panos.enum("DEVICE", "VSYS", "MGTCONFIG", "PANORAMA", "PANORAMA_VSYS")
4444
SELF = "/%s"
4545
ENTRY = "/entry[@name='%s']"
4646
MEMBER = "/member[text()='%s']"
@@ -310,6 +310,13 @@ def xpath(self, root=None):
310310
# Stop on the first pandevice encountered, unless the
311311
# panos.PanDevice object is the object whose xpath
312312
# was asked for.
313+
# If the object whose xpath we are creating is directly
314+
# attached to a Panorama and the root is PANORAMA
315+
if root == Root.PANORAMA_VSYS:
316+
if p.__class__.__name__ == "Panorama":
317+
root = Root.PANORAMA
318+
else:
319+
root = Root.VSYS
313320
path.insert(0, p.xpath_root(root, vsys, label))
314321
break
315322
elif p.__class__.__name__ == "Predefined":
@@ -339,6 +346,8 @@ def xpath(self, root=None):
339346
# Hit a template, make sure that the appropriate /config/...
340347
# xpath has been saved.
341348
if not path[0].startswith("/config/"):
349+
if root == Root.PANORAMA_VSYS:
350+
root = Root.VSYS
342351
path.insert(0, self.xpath_root(root, vsys, label))
343352
vsys = p.vsys
344353
root = p.ROOT

panos/device.py

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ class SnmpServerProfile(VersionedPanObject):
867867
868868
"""
869869

870-
ROOT = Root.VSYS
870+
ROOT = Root.PANORAMA_VSYS
871871
SUFFIX = ENTRY
872872
CHILDTYPES = (
873873
"device.SnmpV2cServer",
@@ -900,7 +900,7 @@ class SnmpV2cServer(VersionedPanObject):
900900
901901
"""
902902

903-
ROOT = Root.VSYS
903+
ROOT = Root.PANORAMA_VSYS
904904
SUFFIX = ENTRY
905905

906906
def _setup(self):
@@ -929,7 +929,7 @@ class SnmpV3Server(VersionedPanObject):
929929
930930
"""
931931

932-
ROOT = Root.VSYS
932+
ROOT = Root.PANORAMA_VSYS
933933
SUFFIX = ENTRY
934934

935935
def _setup(self):
@@ -976,7 +976,7 @@ class EmailServerProfile(VersionedPanObject):
976976
977977
"""
978978

979-
ROOT = Root.VSYS
979+
ROOT = Root.PANORAMA_VSYS
980980
SUFFIX = ENTRY
981981
CHILDTYPES = ("device.EmailServer",)
982982

@@ -1033,7 +1033,7 @@ class EmailServer(VersionedPanObject):
10331033
10341034
"""
10351035

1036-
ROOT = Root.VSYS
1036+
ROOT = Root.PANORAMA_VSYS
10371037
SUFFIX = ENTRY
10381038

10391039
def _setup(self):
@@ -1076,7 +1076,7 @@ class SyslogServerProfile(VersionedPanObject):
10761076
10771077
"""
10781078

1079-
ROOT = Root.VSYS
1079+
ROOT = Root.PANORAMA_VSYS
10801080
SUFFIX = ENTRY
10811081
CHILDTYPES = ("device.SyslogServer",)
10821082

@@ -1136,7 +1136,7 @@ class SyslogServer(VersionedPanObject):
11361136
11371137
"""
11381138

1139-
ROOT = Root.VSYS
1139+
ROOT = Root.PANORAMA_VSYS
11401140
SUFFIX = ENTRY
11411141

11421142
def _setup(self):
@@ -1227,7 +1227,7 @@ class HttpServerProfile(VersionedPanObject):
12271227
12281228
"""
12291229

1230-
ROOT = Root.VSYS
1230+
ROOT = Root.PANORAMA_VSYS
12311231
SUFFIX = ENTRY
12321232
CHILDTYPES = (
12331233
"device.HttpServer",
@@ -1387,7 +1387,7 @@ class HttpServer(VersionedPanObject):
13871387
13881388
"""
13891389

1390-
ROOT = Root.VSYS
1390+
ROOT = Root.PANORAMA_VSYS
13911391
SUFFIX = ENTRY
13921392

13931393
def _setup(self):
@@ -1435,6 +1435,7 @@ class HttpConfigHeader(ValueEntry):
14351435
"""
14361436

14371437
LOCATION = "/format/config/headers"
1438+
ROOT = Root.PANORAMA_VSYS
14381439

14391440

14401441
class HttpConfigParam(ValueEntry):
@@ -1449,6 +1450,7 @@ class HttpConfigParam(ValueEntry):
14491450
"""
14501451

14511452
LOCATION = "/format/config/params"
1453+
ROOT = Root.PANORAMA_VSYS
14521454

14531455

14541456
class HttpSystemHeader(ValueEntry):
@@ -1463,6 +1465,7 @@ class HttpSystemHeader(ValueEntry):
14631465
"""
14641466

14651467
LOCATION = "/format/system/headers"
1468+
ROOT = Root.PANORAMA_VSYS
14661469

14671470

14681471
class HttpSystemParam(ValueEntry):
@@ -1477,6 +1480,7 @@ class HttpSystemParam(ValueEntry):
14771480
"""
14781481

14791482
LOCATION = "/format/system/params"
1483+
ROOT = Root.PANORAMA_VSYS
14801484

14811485

14821486
class HttpThreatHeader(ValueEntry):
@@ -1491,6 +1495,7 @@ class HttpThreatHeader(ValueEntry):
14911495
"""
14921496

14931497
LOCATION = "/format/threat/headers"
1498+
ROOT = Root.PANORAMA_VSYS
14941499

14951500

14961501
class HttpThreatParam(ValueEntry):
@@ -1505,6 +1510,7 @@ class HttpThreatParam(ValueEntry):
15051510
"""
15061511

15071512
LOCATION = "/format/threat/params"
1513+
ROOT = Root.PANORAMA_VSYS
15081514

15091515

15101516
class HttpTrafficHeader(ValueEntry):
@@ -1519,6 +1525,7 @@ class HttpTrafficHeader(ValueEntry):
15191525
"""
15201526

15211527
LOCATION = "/format/traffic/headers"
1528+
ROOT = Root.PANORAMA_VSYS
15221529

15231530

15241531
class HttpTrafficParam(ValueEntry):
@@ -1533,6 +1540,7 @@ class HttpTrafficParam(ValueEntry):
15331540
"""
15341541

15351542
LOCATION = "/format/traffic/params"
1543+
ROOT = Root.PANORAMA_VSYS
15361544

15371545

15381546
class HttpHipMatchHeader(ValueEntry):
@@ -1547,6 +1555,7 @@ class HttpHipMatchHeader(ValueEntry):
15471555
"""
15481556

15491557
LOCATION = "/format/hip-match/headers"
1558+
ROOT = Root.PANORAMA_VSYS
15501559

15511560

15521561
class HttpHipMatchParam(ValueEntry):
@@ -1561,6 +1570,7 @@ class HttpHipMatchParam(ValueEntry):
15611570
"""
15621571

15631572
LOCATION = "/format/hip-match/params"
1573+
ROOT = Root.PANORAMA_VSYS
15641574

15651575

15661576
class HttpUrlHeader(ValueEntry):
@@ -1575,6 +1585,7 @@ class HttpUrlHeader(ValueEntry):
15751585
"""
15761586

15771587
LOCATION = "/format/url/headers"
1588+
ROOT = Root.PANORAMA_VSYS
15781589

15791590

15801591
class HttpUrlParam(ValueEntry):
@@ -1589,6 +1600,7 @@ class HttpUrlParam(ValueEntry):
15891600
"""
15901601

15911602
LOCATION = "/format/url/params"
1603+
ROOT = Root.PANORAMA_VSYS
15921604

15931605

15941606
class HttpDataHeader(ValueEntry):
@@ -1603,6 +1615,7 @@ class HttpDataHeader(ValueEntry):
16031615
"""
16041616

16051617
LOCATION = "/format/data/headers"
1618+
ROOT = Root.PANORAMA_VSYS
16061619

16071620

16081621
class HttpDataParam(ValueEntry):
@@ -1617,6 +1630,7 @@ class HttpDataParam(ValueEntry):
16171630
"""
16181631

16191632
LOCATION = "/format/data/params"
1633+
ROOT = Root.PANORAMA_VSYS
16201634

16211635

16221636
class HttpWildfireHeader(ValueEntry):
@@ -1631,6 +1645,7 @@ class HttpWildfireHeader(ValueEntry):
16311645
"""
16321646

16331647
LOCATION = "/format/wildfire/headers"
1648+
ROOT = Root.PANORAMA_VSYS
16341649

16351650

16361651
class HttpWildfireParam(ValueEntry):
@@ -1645,6 +1660,7 @@ class HttpWildfireParam(ValueEntry):
16451660
"""
16461661

16471662
LOCATION = "/format/wildfire/params"
1663+
ROOT = Root.PANORAMA_VSYS
16481664

16491665

16501666
class HttpTunnelHeader(ValueEntry):
@@ -1659,6 +1675,7 @@ class HttpTunnelHeader(ValueEntry):
16591675
"""
16601676

16611677
LOCATION = "/format/tunnel/headers"
1678+
ROOT = Root.PANORAMA_VSYS
16621679

16631680

16641681
class HttpTunnelParam(ValueEntry):
@@ -1673,6 +1690,7 @@ class HttpTunnelParam(ValueEntry):
16731690
"""
16741691

16751692
LOCATION = "/format/tunnel/params"
1693+
ROOT = Root.PANORAMA_VSYS
16761694

16771695

16781696
class HttpUserIdHeader(ValueEntry):
@@ -1687,6 +1705,7 @@ class HttpUserIdHeader(ValueEntry):
16871705
"""
16881706

16891707
LOCATION = "/format/userid/headers"
1708+
ROOT = Root.PANORAMA_VSYS
16901709

16911710

16921711
class HttpUserIdParam(ValueEntry):
@@ -1701,6 +1720,7 @@ class HttpUserIdParam(ValueEntry):
17011720
"""
17021721

17031722
LOCATION = "/format/userid/params"
1723+
ROOT = Root.PANORAMA_VSYS
17041724

17051725

17061726
class HttpGtpHeader(ValueEntry):
@@ -1715,6 +1735,7 @@ class HttpGtpHeader(ValueEntry):
17151735
"""
17161736

17171737
LOCATION = "/format/gtp/headers"
1738+
ROOT = Root.PANORAMA_VSYS
17181739

17191740

17201741
class HttpGtpParam(ValueEntry):
@@ -1729,6 +1750,7 @@ class HttpGtpParam(ValueEntry):
17291750
"""
17301751

17311752
LOCATION = "/format/gtp/params"
1753+
ROOT = Root.PANORAMA_VSYS
17321754

17331755

17341756
class HttpAuthHeader(ValueEntry):
@@ -1743,6 +1765,7 @@ class HttpAuthHeader(ValueEntry):
17431765
"""
17441766

17451767
LOCATION = "/format/auth/headers"
1768+
ROOT = Root.PANORAMA_VSYS
17461769

17471770

17481771
class HttpAuthParam(ValueEntry):
@@ -1757,6 +1780,7 @@ class HttpAuthParam(ValueEntry):
17571780
"""
17581781

17591782
LOCATION = "/format/auth/params"
1783+
ROOT = Root.PANORAMA_VSYS
17601784

17611785

17621786
class HttpSctpHeader(ValueEntry):
@@ -1771,6 +1795,7 @@ class HttpSctpHeader(ValueEntry):
17711795
"""
17721796

17731797
LOCATION = "/format/sctp/headers"
1798+
ROOT = Root.PANORAMA_VSYS
17741799

17751800

17761801
class HttpSctpParam(ValueEntry):
@@ -1785,6 +1810,7 @@ class HttpSctpParam(ValueEntry):
17851810
"""
17861811

17871812
LOCATION = "/format/sctp/params"
1813+
ROOT = Root.PANORAMA_VSYS
17881814

17891815

17901816
class HttpIpTagHeader(ValueEntry):
@@ -1799,6 +1825,7 @@ class HttpIpTagHeader(ValueEntry):
17991825
"""
18001826

18011827
LOCATION = "/format/iptag/headers"
1828+
ROOT = Root.PANORAMA_VSYS
18021829

18031830

18041831
class HttpIpTagParam(ValueEntry):
@@ -1813,3 +1840,4 @@ class HttpIpTagParam(ValueEntry):
18131840
"""
18141841

18151842
LOCATION = "/format/iptag/params"
1843+
ROOT = Root.PANORAMA_VSYS

0 commit comments

Comments
 (0)