Parse RANCID db files so they can be converted into Trigger NetDevice objects.
New in version 1.2.
Far from complete. Very early in development. Here is a basic example.
>>> from trigger import rancid
>>> rancid_root = '/path/to/rancid/data'
>>> r = Rancid(rancid_root)
>>> dev = r.devices.get('test1-abc.net.aol.com')
>>> dev
RancidDevice(nodeName='test-abc.net.aol.com', manufacturer='juniper', deviceStatus='up', deviceType=None)
Another option if you want to get the parsed RANCID data directly without having to create an object is as simple as this:
>>> parsed = rancid.parse_rancid_data('/path/to/dancid/data')
Or using multiple RANCID instances within a single root:
>>> multi_parsed = rancid.parse_rancid_data('/path/to/rancid/data', recurse_subdirs=True)
Parse a RANCID file and return generator representing a list of lists mapped to the fields.
Parameters: |
|
---|
Iterate device metadata to use parser to create and return a list of network device objects.
Parameters: |
|
---|
Walk the rancid_root and parse the included RANCID files.
Returns a dictionary keyed by the name of the subdirs with values set to the parsed data for each RANCID file found inside.
>>> from trigger import rancid
>>> subdirs = rancid.walk_rancid_subdirs('/data/rancid')
>>> subdirs.get('network-security')
{'router.db': <generator object <genexpr> at 0xa5b852c>,
'routers.all': <generator object <genexpr> at 0xa5a348c>,
'routers.down': <generator object <genexpr> at 0xa5be9dc>,
'routers.up': <generator object <genexpr> at 0xa5bea54>}
Parameters: |
|
---|
Parse single or multiple RANCID instances and return an iterator of the device metadata.
A single instance expects to find ‘router.db’ in rancid_root.
If you set recurise_subdirs, multiple instances will be expected, and a router.db will be expected to be found in each subdirectory.
Parameters: |
|
---|
Returns a chained iterator of parsed RANCID data, based from the results of walk_rancid_subdirs.
This iterator is suitable for consumption by parse_devices or Trigger’s NetDevices.
Parameters: |
|
---|
Holds RANCID data. INCOMPLETE.
Defaults to a single RANID instance specified as rancid_root. It will parse the file found at rancid_db_file and use this to populate the devices dictionary with instances of device_class.
If you set recurse_subdirs, it is assumed that rancid_root holds one or more individual RANCID instances and will attempt to walk them, parse them, and then aggregate all of the resulting device instances into the devices dictionary.
Still needs:
Parameters: |
|
---|
A simple subclass of namedtuple to store contents of parsed RANCID files.
Designed to support all router.* files. The field names are intended to be compatible with Trigger’s NetDevice objects.
Parameters: |
|
---|