Skip to content

Commit 4676eea

Browse files
committed
Merge branch 'release/0.9.0'
2 parents 97c72ca + df5945a commit 4676eea

File tree

5 files changed

+83
-36
lines changed

5 files changed

+83
-36
lines changed

HISTORY.rst

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

6-
0.8.1
6+
0.9.1
77
-----
88

99
Released: Pending
1010

1111
Status: Alpha
1212

13+
0.9.0
14+
-----
15+
16+
Released: 2019-04-22
17+
18+
Status: Alpha
19+
20+
- Added `VlanInterface.set_vlan_interface()`
21+
- Minor bug fix
22+
1323
0.8.0
1424
-----
1525

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.8.0'
26+
__version__ = '0.9.0'
2727

2828

2929
import logging

pandevice/base.py

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ def _convert_var(cls, value, vartype):
13681368
return yesno(value)
13691369

13701370
def _set_reference(self, reference_name, reference_type, reference_var,
1371-
exclusive, refresh, update, running_config,
1371+
var_type, exclusive, refresh, update, running_config,
13721372
return_type, name_only, **kwargs):
13731373
"""Used by helper methods to set references between objects
13741374
@@ -1468,46 +1468,52 @@ def _set_reference(self, reference_name, reference_type, reference_var,
14681468
if exclusive:
14691469
for obj in allobjects:
14701470
references = getattr(obj, reference_var)
1471-
if references is None:
1471+
if not references:
14721472
continue
1473-
elif hasattr(references, "__iter__") and self in references:
1474-
if reference_name is not None and str(getattr(obj, reference_type.NAME)) == reference_name:
1475-
continue
1473+
elif reference_name is not None and obj.uid == reference_name:
1474+
continue
1475+
elif isinstance(references, list) and self in references:
14761476
update_needed = True
14771477
references.remove(self)
1478-
if update: obj.update(reference_var)
1479-
elif hasattr(references, "__iter__") and str(self) in references:
1480-
if reference_name is not None and str(getattr(obj, reference_type.NAME)) == reference_name:
1481-
continue
1478+
if update:
1479+
obj.update(reference_var)
1480+
elif isinstance(references, list) and str(self) in references:
14821481
update_needed = True
14831482
references.remove(str(self))
1484-
if update: obj.update(reference_var)
1483+
if update:
1484+
obj.update(reference_var)
14851485
elif references == self or references == str(self):
1486-
if reference_name is not None and str(getattr(obj, reference_type.NAME)) == reference_name:
1487-
continue
14881486
update_needed = True
1489-
references = None
1490-
if update: obj.update(reference_var)
1487+
setattr(obj, reference_var, None)
1488+
if update:
1489+
obj.update(reference_var)
14911490

14921491
# Add new reference to self in requested object
14931492
if reference_name is not None:
14941493
obj = parent.find_or_create(reference_name, reference_type, **kwargs)
14951494
var = getattr(obj, reference_var)
1496-
if var is None:
1497-
update_needed = True
1498-
setattr(obj, reference_var, [self])
1499-
if update: obj.update(reference_var)
1500-
elif hasattr(var, "__iter__") and self not in var and str(self) not in var:
1501-
update_needed = True
1502-
var.append(self)
1503-
if update: obj.update(reference_var)
1504-
elif hasattr(var, "__iter__"):
1505-
# The reference already exists so do nothing
1506-
pass
1495+
if var_type == 'list':
1496+
if var is None:
1497+
update_needed = True
1498+
setattr(obj, reference_var, [self, ])
1499+
if update:
1500+
obj.update(reference_var)
1501+
elif not isinstance(var, list):
1502+
if var != self and var != str(self):
1503+
update_needed = True
1504+
setattr(obj, reference_var, [var, self])
1505+
if update:
1506+
obj.update(reference_var)
1507+
elif self not in var and str(self) not in var:
1508+
update_needed = True
1509+
var.append(self)
1510+
if update:
1511+
obj.update(reference_var)
15071512
elif var != self and var != str(self):
15081513
update_needed = True
15091514
setattr(obj, reference_var, self)
1510-
if update: obj.update(reference_var)
1515+
if update:
1516+
obj.update(reference_var)
15111517
if return_type == 'object':
15121518
return obj
15131519

@@ -3088,8 +3094,8 @@ def set_vsys(self, vsys_id, refresh=False, update=False,
30883094
self.XPATH_IMPORT))
30893095

30903096
from pandevice.device import Vsys
3091-
return self._set_reference(vsys_id, Vsys, param_name, True, refresh,
3092-
update, running_config, return_type, True)
3097+
return self._set_reference(vsys_id, Vsys, param_name, 'list',
3098+
True, refresh, update, running_config, return_type, True)
30933099

30943100
@classmethod
30953101
def refreshall(cls, parent, running_config=False, add=True,

pandevice/network.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def set_zone(self, zone_name, mode=None, refresh=False, update=False,
321321
return False
322322

323323
return self._set_reference(
324-
zone_name, Zone, "interface", True, refresh,
324+
zone_name, Zone, "interface", 'list', True, refresh,
325325
update, running_config, return_type, False, mode=mode)
326326

327327
def set_virtual_router(self, virtual_router_name, refresh=False,
@@ -353,8 +353,8 @@ def set_virtual_router(self, virtual_router_name, refresh=False,
353353
354354
"""
355355
return self._set_reference(
356-
virtual_router_name, VirtualRouter, "interface", True, refresh,
357-
update, running_config, return_type, False)
356+
virtual_router_name, VirtualRouter, "interface", 'list',
357+
True, refresh, update, running_config, return_type, False)
358358

359359
def set_vlan(self, vlan_name, refresh=False,
360360
update=False, running_config=False, return_type='object'):
@@ -391,7 +391,7 @@ def set_vlan(self, vlan_name, refresh=False,
391391
raise AttributeError(msg.format(self.__class__))
392392

393393
return self._set_reference(
394-
vlan_name, Vlan, "interface", True,
394+
vlan_name, Vlan, "interface", 'list', True,
395395
refresh, update, running_config, return_type, False)
396396

397397
def get_counters(self):
@@ -674,7 +674,7 @@ def set_virtual_router(self, virtual_router_name, refresh=False, update=False, r
674674
interface = Layer3Subinterface(self.name, self.tag)
675675
interface.parent = self.parent
676676
return interface._set_reference(
677-
virtual_router_name, VirtualRouter, "interface", True,
677+
virtual_router_name, VirtualRouter, "interface", 'list', True,
678678
refresh=False, update=update, running_config=running_config,
679679
return_type='object', name_only=False)
680680

@@ -1220,6 +1220,37 @@ def _setup(self):
12201220

12211221
self._params = tuple(params)
12221222

1223+
def set_vlan_interface(self, vlan_name, refresh=False,
1224+
update=False, running_config=False, return_type='object'):
1225+
"""Sets the VLAN's VLAN interface to this VLAN interface
1226+
1227+
Creates a reference to this interface in the specified vlan and removes
1228+
references to this interface from all other VLANs. The vlan will
1229+
be created if it doesn't exist.
1230+
1231+
Args:
1232+
vlan_name (str): The name of the vlan or
1233+
a :class:`pandevice.network.Vlan` instance
1234+
refresh (bool): Refresh the relevant current state of the device
1235+
before taking action (Default: False)
1236+
update (bool): Apply the changes to the device (Default: False)
1237+
running_config: If refresh is True, refresh from the running
1238+
configuration (Default: False)
1239+
return_type (str): Specify what this function returns, can be
1240+
either 'object' (the default) or 'bool'. If this is 'object',
1241+
then the return value is the Vlan in question. If
1242+
this is 'bool', then the return value is a boolean that tells
1243+
you about if the live device needs updates (update=False) or
1244+
was updated (update=True).
1245+
1246+
Returns:
1247+
Vlan: The VLAN for this interface after the operation completes
1248+
1249+
"""
1250+
return self._set_reference(
1251+
vlan_name, Vlan, 'virtual_interface', 'string', True,
1252+
refresh, update, running_config, return_type, False)
1253+
12231254

12241255
class LoopbackInterface(Interface):
12251256
"""Loopback interface

setup.py

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

2424
setup(
2525
name='pandevice',
26-
version='0.8.0',
26+
version='0.9.0',
2727
description='Framework for interacting with Palo Alto Networks devices via API',
2828
long_description='The Palo Alto Networks Device Framework is a way to interact with Palo Alto Networks devices (including Next-generation Firewalls and Panorama) using the device API that is object oriented and conceptually similar to interaction with the device via the GUI or CLI.',
2929
author='Palo Alto Networks',

0 commit comments

Comments
 (0)