Skip to content

Commit 9e8663b

Browse files
committed
Merge branch 'release/0.5.1'
2 parents a48e808 + 6e70bc2 commit 9e8663b

File tree

11 files changed

+164
-49
lines changed

11 files changed

+164
-49
lines changed

HISTORY.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@
33
History
44
=======
55

6+
0.5.1
7+
-----
8+
9+
Released: 2017-09-12
10+
11+
Status: Alpha
12+
13+
- Fix: Security and NAT policy XPATH problems
14+
- Fix: `base.PanDevice.create_from_device()`'s check for certain Panorama devices
15+
- Fix: `firewall.Firewall.organize_into_vsys()`'s behavior with importables that aren't imported
16+
- Fix: `refreshall()`'s behavior when it has a `device.Vsys` parent
17+
18+
619
0.5.0
720
-----
821

9-
Released 2017-07-14
22+
Released: 2017-07-14
1023

1124
Status: Alpha
1225

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
Palo Alto Networks Device Framework
33
===================================
44

5-
The Palo Alto Networks Device Framework is a way to interact with Palo Alto
6-
Networks devices (including Next-generation Firewalls and Panorama) using the
7-
device API that is object oriented and conceptually similar to interaction
8-
with the device via the GUI or CLI.
5+
The Device Framework is a mechanism for interacting with Palo Alto Networks
6+
devices (including physical and virtualized Next-generation Firewalls and
7+
Panorama). The Device Framework is object oriented and mimics the traditional
8+
interaction with the device via the GUI or CLI/API.
99

1010
* Documentation: http://pandevice.readthedocs.io
1111
* Overview: http://paloaltonetworks.github.io/pandevice

pandevice/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
__author__ = 'Palo Alto Networks'
2525
__email__ = '[email protected]'
26-
__version__ = '0.5.0'
26+
__version__ = '0.5.1'
2727

2828

2929
import logging

pandevice/base.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,13 @@ def _parent_xpath(self):
314314
if self.parent is None:
315315
return ""
316316
else:
317-
return self.parent._build_xpath(self.ROOT)
317+
return self.parent._build_xpath(self.ROOT, None)
318318

319-
def _build_xpath(self, root):
319+
def _build_xpath(self, root, vsys):
320320
if self.parent is None:
321321
# self with no parent
322322
return ""
323-
parent_xpath = self.parent._build_xpath(root) + self.XPATH
323+
parent_xpath = self.parent._build_xpath(root, vsys) + self.XPATH
324324
if self.SUFFIX is not None:
325325
parent_xpath += self.SUFFIX % (self.uid, )
326326
return parent_xpath
@@ -334,9 +334,12 @@ def xpath_panorama(self):
334334
return self.parent.xpath_panorama()
335335

336336
def _root_xpath_vsys(self, vsys):
337-
root_xpath = "/config/devices/entry[@name='localhost.localdomain']/vsys"
338-
specific_vsys = "/entry[@name='{0}']".format(vsys) if vsys else ""
339-
return root_xpath + specific_vsys
337+
if vsys == 'shared':
338+
return '/config/shared'
339+
340+
xpath = "/config/devices/entry[@name='localhost.localdomain']"
341+
xpath += "/vsys/entry[@name='{0}']".format(vsys or 'vsys1')
342+
return xpath
340343

341344
def element(self, with_children=True, comparable=False):
342345
"""Construct an ElementTree for this PanObject and all its children
@@ -1441,8 +1444,7 @@ def _about_parameter(self, parameter):
14411444
return ans
14421445

14431446
def _requires_import_consideration(self):
1444-
if self.vsys in (None, 'shared') or not hasattr(self,
1445-
'xpath_import_base'):
1447+
if self.vsys == 'shared' or not hasattr(self, 'XPATH_IMPORT'):
14461448
return False
14471449
return True
14481450

@@ -1489,9 +1491,12 @@ def _gather_bulk_info(self, func=None):
14891491
for node in itertools.chain(all_objects):
14901492
all_objects.extend(node.children)
14911493
if node._requires_import_consideration():
1492-
vsys_dict.setdefault(node.vsys, {})
1493-
vsys_dict[node.vsys].setdefault(node.xpath_import_base(), [])
1494-
vsys_dict[node.vsys][node.xpath_import_base()].append(node)
1494+
vsys = node.vsys
1495+
if vsys is None and node.ALWAYS_IMPORT:
1496+
vsys = 'vsys1'
1497+
vsys_dict.setdefault(vsys, {})
1498+
vsys_dict[vsys].setdefault(node.xpath_import_base(), [])
1499+
vsys_dict[vsys][node.xpath_import_base()].append(node)
14951500

14961501
return dev, instances, vsys_dict
14971502

@@ -2965,7 +2970,7 @@ def create_from_device(cls,
29652970
system_info = device.refresh_system_info()
29662971
version = system_info[0]
29672972
model = system_info[1]
2968-
if model == "Panorama":
2973+
if model == "Panorama" or model.startswith('M-'):
29692974
instance = panorama.Panorama(hostname,
29702975
api_username,
29712976
api_password,
@@ -3271,14 +3276,14 @@ def set_config_changed(self, scope=None):
32713276
if scope not in self.config_changed:
32723277
self.config_changed.append(scope)
32733278

3274-
def _build_xpath(self, root):
3275-
return self.xpath_root(root)
3279+
def _build_xpath(self, root, vsys):
3280+
return self.xpath_root(root, vsys or self.vsys)
32763281

3277-
def xpath_root(self, root_type):
3282+
def xpath_root(self, root_type, vsys):
32783283
if root_type == Root.DEVICE:
32793284
xpath = self.xpath_device()
32803285
elif root_type == Root.VSYS:
3281-
xpath = self.xpath_vsys()
3286+
xpath = self._root_xpath_vsys(vsys)
32823287
elif root_type == Root.MGTCONFIG:
32833288
xpath = self.xpath_mgtconfig()
32843289
elif root_type == Root.PANORAMA:

pandevice/device.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,12 @@ def _setup(self):
131131
self._params = tuple(params)
132132

133133
def xpath_vsys(self):
134-
if self.name == "shared":
135-
return "/config/shared"
136-
elif self.name is None:
137-
return self._root_xpath_vsys('vsys1')
138-
else:
139-
return self._root_xpath_vsys(self.name)
140-
141-
def _build_xpath(self, root):
142-
if root == Root.VSYS:
143-
return super(Vsys, self)._build_xpath(root)
144-
else:
145-
# If original object is not a VSYS Root, then bypass the vsys part of the xpath
146-
if self.parent is None:
147-
return ""
148-
else:
149-
return self.parent._build_xpath(root)
134+
return self._root_xpath_vsys(self.name)
135+
136+
def _build_xpath(self, root, vsys):
137+
if self.parent is None:
138+
return ''
139+
return self.parent._build_xpath(root, self.name)
150140

151141
@property
152142
def vsys(self):

pandevice/firewall.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,7 @@ def vsys(self, value):
150150
self.ha_peer._vsys = value
151151

152152
def xpath_vsys(self):
153-
if self.vsys == "shared":
154-
return "/config/shared"
155-
elif self.vsys is None:
156-
return self._root_xpath_vsys('vsys1')
157-
else:
158-
return self._root_xpath_vsys(self.vsys)
153+
return self._root_xpath_vsys(self.vsys)
159154

160155
def xpath_panorama(self):
161156
raise err.PanDeviceError("Attempt to modify Panorama configuration on non-Panorama device")
@@ -416,6 +411,13 @@ def organize_into_vsys(self, create_vsys_objects=True, refresh_vsys=True):
416411
x.parent.remove(x)
417412
vsys.add(x)
418413
break
414+
else:
415+
# Checked every vsys, this importable isn't in any of
416+
# them (vsys is None), so move this node to be a child
417+
# of the firewall.
418+
if x.parent != self:
419+
x.parent.remove(x)
420+
self.add(x)
419421
break
420422

421423

pandevice/network.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ def _setup(self):
505505
self._params = tuple(params)
506506

507507

508-
class VirtualWire(VersionedPanObject):
508+
class VirtualWire(VsysOperations):
509509
"""Virtual wires (vwire)
510510
511511
Args:
@@ -524,6 +524,9 @@ def _setup(self):
524524
# xpaths
525525
self._xpaths.add_profile(value='/network/virtual-wire')
526526

527+
# xpath imports
528+
self._xpath_imports.add_profile(value='/network/virtual-wire')
529+
527530
# params
528531
params = []
529532

pandevice/panorama.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,14 @@ def xpath_vsys(self):
8787
else:
8888
return "/config/devices/entry[@name='localhost.localdomain']/device-group/entry[@name='%s']" % self.name
8989

90-
def _build_xpath(self, root):
90+
def _build_xpath(self, root, vsys):
9191
if (self.name == "shared" or self.name is None) and root == Root.VSYS:
9292
# This is a Vsys object in shared Panorama scope, so proceed normally
93-
return super(DeviceGroup, self)._build_xpath(root)
93+
return super(DeviceGroup, self)._build_xpath(root,
94+
self.name or 'shared')
9495
else:
9596
# This is a member of the device-group, so override to use DeviceGroup root
96-
return super(DeviceGroup, self)._build_xpath(self.ROOT)
97+
return super(DeviceGroup, self)._build_xpath(self.ROOT, self.name)
9798

9899

99100
class Panorama(base.PanDevice):

pandevice/policies.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class SecurityRule(VersionedPanObject):
116116
"""
117117
# TODO: Add QoS variables
118118
SUFFIX = ENTRY
119+
ROOT = Root.VSYS
119120

120121
def _setup(self):
121122
# xpaths
@@ -242,8 +243,10 @@ class NatRule(VersionedPanObject):
242243
target (list): Apply this policy to the listed firewalls only
243244
(applies to panorama/device groups only)
244245
tag (list): Administrative tags
246+
245247
"""
246248
SUFFIX = ENTRY
249+
ROOT = Root.VSYS
247250

248251
def _setup(self):
249252
# xpaths

tests/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def test_parent_xpath_for_xpath_parent(self):
372372
ret_val = self.obj._parent_xpath()
373373

374374
self.assertEqual(Path, ret_val)
375-
self.obj.parent._build_xpath.assert_called_once_with(0)
375+
self.obj.parent._build_xpath.assert_called_once_with(0, None)
376376

377377
def test_xpath_vsys_without_parent(self):
378378
ret_val = self.obj.xpath_vsys()

0 commit comments

Comments
 (0)