Skip to content

Commit

Permalink
trigger.netdevices.NetDevices is now properly subclassable. (fix trig…
Browse files Browse the repository at this point in the history
jathanism committed Aug 18, 2015
1 parent 93beb77 commit 1cd034b
Showing 2 changed files with 27 additions and 12 deletions.
7 changes: 7 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -7,6 +7,13 @@ Changelog
1.5.2
=====

New Features
------------

+ `~trigger.netdevices.NetDevices` can now be properly subclassed and extended.
+ A disable paging command has been added for Citrix NetScaler devices.


Bug Fixes
---------

32 changes: 20 additions & 12 deletions trigger/netdevices/__init__.py
Original file line number Diff line number Diff line change
@@ -24,9 +24,9 @@

__author__ = 'Jathan McCollum, Eileen Tschetter, Mark Thomas, Michael Shields'
__maintainer__ = 'Jathan McCollum'
__email__ = 'jathan.mccollum@teamaol.com'
__email__ = 'jathan@gmail.com'
__copyright__ = 'Copyright 2006-2013, AOL Inc.; 2013 Salesforce.com'
__version__ = '2.3'
__version__ = '2.3.1'

# Imports
import copy
@@ -358,6 +358,7 @@ def disable_paging_cisco():
'aruba': ['no paging'], # v6.2.x this is not necessary
'brocade': disable_paging_brocade(), # See comments above
'cisco': disable_paging_cisco(),
'citrix': ['set cli mode page off'],
'dell': ['terminal datadump'],
'f5': ['modify cli preference pager disabled'],
'force10': default,
@@ -814,9 +815,15 @@ def __init__(self, production_only, with_acls):
def __getitem__(self, key):
return self._dict[key]

def __contains__(self, item):
return item in self._dict

def keys(self):
return self._dict.keys()

def values(self):
return self._dict.values()

def find(self, key):
"""
Return either the exact nodename, or a unique dot-delimited
@@ -827,18 +834,18 @@ def find(self, key):
:param string key: Hostname prefix to find.
:returns: NetDevice object
"""
if key in self._dict:
return self._dict[key]
if key in self:
return self[key]

matches = [x for x in self._dict.keys() if x.startswith(key+'.')]
matches = [x for x in self.keys() if x.startswith(key + '.')]

if matches:
return self._dict[matches[0]]
return self[matches[0]]
raise KeyError(key)

def all(self):
"""Returns all NetDevice objects."""
return self._dict.values()
return self.values()

def search(self, token, field='nodeName'):
"""
@@ -953,12 +960,13 @@ def __init__(self, production_only=True, with_acls=None):
"""
if with_acls is None:
with_acls = settings.WITH_ACLS
if NetDevices._Singleton is None:
NetDevices._Singleton = NetDevices._actual(production_only=production_only,
with_acls=with_acls)
classobj = self.__class__
if classobj._Singleton is None:
classobj._Singleton = classobj._actual(production_only=production_only,
with_acls=with_acls)

def __getattr__(self, attr):
return getattr(NetDevices._Singleton, attr)
return getattr(self.__class__._Singleton, attr)

def __setattr__(self, attr, value):
return setattr(NetDevices._Singleton, attr, value)
return setattr(self.__class__._Singleton, attr, value)

0 comments on commit 1cd034b

Please sign in to comment.