trigger.netdevices — Network device metadata library

The heart and soul of Trigger, NetDevices is an abstract interface to network device metadata and ACL associations.

Parses netdevices.xml and makes available a dictionary of NetDevice objects, which is keyed by the FQDN of every network device.

Other interfaces are non-public.


>>> from trigger.netdevices import NetDevices
>>> nd = NetDevices()
>>> dev = nd['']
>>> dev.manufacturer, dev.make
>>> dev.bounce.next_ok('green')
datetime.datetime(2010, 4, 9, 9, 0, tzinfo=<UTC>)
trigger.netdevices.device_match(name, production_only=True)

Return a matching NetDevice object based on partial name. Return None if no match or if multiple matches is cancelled:

>>> device_match('test')
2 possible matches found for 'test':
  [ 1]
  [ 2]
  [ 0] Exit

Enter a device number: 2

If there is only a single match, that device object is returned without a prompt:

>>> device_match('fw')
Matched ''.
class trigger.netdevices.NetDevice(data=None)

Almost all the attributes are populated by netdevices._populate() and are mostly dependent upon the source data. This is prone to implementation problems and should be revisited in the long-run as there are certain fields that are baked into the core functionality of Trigger.

Users usually won’t create NetDevice objects directly! Rely instead upon NetDevices to do this for you.

allowable(action, when=None)

Ok to perform the specified action? Returns a boolean value. False means a bounce window conflict. For now ‘load-acl’ is the only valid action and moratorium status is not checked.


Prints details for a device.


Am I a firewall?


Am I a NetScaler?


Am I a router?


Am I a switch?

next_ok(action, when=None)

Return the next time at or after the specified time (default now) that it will be ok to perform the specified action.

class trigger.netdevices.NetDevices(production_only=True)

Returns an immutable Singleton dictionary of NetDevice objects. By default it will only return devices for which adminStatus=='PRODUCTION'.

There are hardly any use cases where NON-PRODUCTION devices are needed, and it can cause real bugs of two sorts:

  1. trying to contact unreachable devices and reporting spurious failures,
  2. hot spares with the same nodeName.

You may override this by passing production_only=False.

class _actual(production_only=True)

This is the real class that stays active upon instantiation. All attributes are inherited by NetDevices from this object. This means you do NOT reference _actual itself, and instead call the methods from the parent object.


>>> nd = NetDevices()


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unbound method match() must be called with _actual
instance as first argument (got str instance instead)

Returns all NetDevice objects.


Return either the exact nodename, or a unique dot-delimited prefix. For example, if there is a node ‘’, then any of find(‘test1-abc’) or find(‘’) or find(‘’) will match, but not find(‘test1’).

Parameters:key (string) – Hostname prefix to find.
Returns:NetDevice object

Returns a list of NetDevice objects with deviceType matching type.

Known deviceTypes: [‘FIREWALL’, ‘ROUTER’, ‘SWITCH’, ‘DWDM’]


Returns a list of NetDevice objects with deviceType of FIREWALL


Returns a list of NetDevice objects with deviceType of ROUTER


Returns a list of NetDevice objects with deviceType of SWITCH


Attempt to match values to all keys in @kwargs by dynamically building a list comprehension. Will throw errors if the keys don’t match legit NetDevice attributes.

Keys and values are case IN-senstitive. Matches against non-string values will FAIL.

Example by reference:

>>> nd = NetDevices()
>>> myargs = {'onCallName':'Data Center', 'model':'FCSLB'}
>>> mydevices = nd(**kwargs)

Example by keyword arguments:

>>> mydevices = nd(oncallname='data center', model='fcslb')
Returns:List of NetDevice objects
search(token, field='nodeName')

Returns a list of NetDevice objects where other is in dev.nodeName. The getattr call in the search will allow a AttributeError from a bogus field lookup so that you don’t get an empty list thinking you performed a legit query.

For example, this:

>>> field = 'bacon'
>>> [x for x in nd.all() if 'ash' in getattr(x, field)]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NetDevice' object has no attribute 'bacon'

Is better than this:

>>> [x for x in nd.all() if 'ash' in getattr(x, field, '')]

Because then you know that ‘bacon’ isn’t a field you can search on.

  • token (string) – Token to search match on in @field
  • field (string) – The field to match on when searching

List of NetDevice objects

Previous topic

trigger.conf — Configuration & Settings module

Next topic

trigger.netscreen — Juniper NetScreen firewall parser

This Page