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_SOURCE 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.vendor, dev.make
(<Vendor: Juniper>, 'MX960-BASE-AC')
>>> 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, with_acls=None)

An object that represents a distinct network device and its metadata.

Almost all of the attributes are populated by _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 these objects directly! Rely instead upon NetDevices to do this for you.

allowable(action, when=None)

Return whether it’s okay to perform the specified action.

False means a bounce window conflict. For now 'load-acl' is the only valid action and moratorium status is not checked.

  • action – The action to check.
  • when – A datetime object.

Am I enabled to use SSH async?


Am I enabled to use SSH pty?


Prints details for a device.


Am I even listening on SSH?


Am I a Brocade VDX switch?

This is used to account for the disparity between the Brocade FCX switches (which behave like Foundry devices) and the Brocade VDX switches (which behave differently from classic Foundry devices).


Am I a firewall?


Am I an IOS-like device (as determined by :settings:`IOSLIKE_VENDORS`)?


Am I a NetScaler?


Am I a NetScreen running ScreenOS?


Do I respond to a ping?


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.

  • action – The action to check.
  • when – A datetime object.
class trigger.netdevices.Vendor(manufacturer=None)

Map a manufacturer name to Trigger’s canonical name.

Given a manufacturer name like ‘CISCO SYSTEMS’, this will attempt to map it to the canonical vendor name specified in settings.VENDOR_MAP. If this can’t be done, attempt to split the name up (‘CISCO, ‘SYSTEMS’) and see if any of the words map. An exception is raised as a last resort.

This exposes a normalized name that can be used in the event of a multi-word canonical name.


Try to turn the provided vendor name into the cname.


Return the normalized name for the vendor.

class trigger.netdevices.NetDevices(production_only=True, with_acls=None)

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, with_acls)

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’]


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(**myargs)

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.gorc — Determine commands to run upon login

Next topic

trigger.netscreen — Juniper NetScreen firewall parser

This Page