trigger.cmds — Command execution library

Abstracts the execution of commands on network devices. Allows for integrated parsing and manipulation of return data for rapid integration to existing or newly created tools.

Commando superclass is intended to be subclassed. More documentation soon!

class trigger.cmds.Commando(devices=None, max_conns=10, verbose=False, timeout=30, production_only=True)

I run commands on devices but am not much use unless you subclass me and configure vendor-specific parse/generate methods.

arista_parse(data, device)

Parse output from a device. Overload this to customize this default behavior.

brocade_parse(data, device)

Parse output from a device. Overload this to customize this default behavior.

dell_parse(data, device)

Parse output from a device. Overload this to customize this default behavior.

foundry_parse(data, device)

Parse output from a device. Overload this to customize this default behavior.

generate_arista_cmd(dev=None)

Generate commands to be run on a device. If you don’t overload this, it returns an empty list.

generate_brocade_cmd(dev=None)

Generate commands to be run on a device. If you don’t overload this, it returns an empty list.

generate_dell_cmd(dev=None)

Generate commands to be run on a device. If you don’t overload this, it returns an empty list.

generate_foundry_cmd(dev=None)

Generate commands to be run on a device. If you don’t overload this, it returns an empty list.

generate_ios_cmd(dev=None)

Generate commands to be run on a device. If you don’t overload this, it returns an empty list.

generate_junos_cmd(dev=None)

Generate commands to be run on a device. If you don’t overload this, it returns an empty list.

generate_netscaler_cmd(dev=None)

Generate commands to be run on a device. If you don’t overload this, it returns an empty list.

ios_parse(data, device)

Parse output from a device. Overload this to customize this default behavior.

junos_parse(data, device)

Parse output from a device. Overload this to customize this default behavior.

netscaler_parse(data, device)

Parse output from a device. Overload this to customize this default behavior.

run()

Nothing happens until you execute this to perform the actual work.

set_data(device, data)

Another method for storing results. If you’d rather just change the default method for storing results, overload this. All default parse/generate methods call this.

class trigger.cmds.NetACLInfo(**args)

Class to fetch and parse interface information. Exposes a config attribute which is a dictionary of devices passed to the constructor and their interface information.

Each device is a dictionary of interfaces. Each interface field will default to an empty list if not populated after parsing. Below is a skeleton of the basic config, with expected fields:

config {
    'device1': {
        'interface1': {
            'acl_in': [],
            'acl_out': [],
            'addr': [],
            'description': [],
            'subnets': [],
        }
    }
}

Interface field descriptions:

:addr: List of IPy.IP objects of interface addresses
:acl_in: List of inbound ACL names
:acl_out: List of outbound ACL names
:description: List of interface description(s)
:subnets: List of IPy.IP objects of interface networks/CIDRs

Example:

>>> n = NetACLInfo(devices=['jm10-cc101-lab.lab.aol.net'])
>>> n.run()
Fetching jm10-cc101-lab.lab.aol.net
>>> n.config.keys()
[<NetDevice: jm10-cc101-lab.lab.aol.net>]
>>> dev = n.config.keys()[0]
>>> n.config[dev].keys()
['lo0.0', 'ge-0/0/0.0', 'ge-0/2/0.0', 'ge-0/1/0.0', 'fxp0.0']
>>> n.config[dev]['lo0.0'].keys()
['acl_in', 'subnets', 'addr', 'acl_out', 'description']
>>> lo0 = n.config[dev]['lo0.0']
>>> lo0['acl_in']; lo0['addr']
['abc123']
[IP('66.185.128.160')]
IPsubnet(addr)

Given ‘172.20.1.4/24’, return IP(‘172.20.1.0/24’).

arista_parse(data, device)

Parse IOS config based on EBNF grammar

brocade_parse(data, device)

Parse IOS config based on EBNF grammar

foundry_parse(data, device)

Parse IOS config based on EBNF grammar

generate_arista_cmd(dev)

Similar to IOS, but:

  • Arista has now “show conf” so we have to do “show run”
  • The regex used in the CLI for Arista is more “precise” so we have to change the pattern a little bit compared to the on in generate_ios_cmd
generate_brocade_cmd(dev)

This is the “show me all interface information” command we pass to IOS devices

generate_foundry_cmd(dev)

This is the “show me all interface information” command we pass to IOS devices

generate_ios_cmd(dev)

This is the “show me all interface information” command we pass to IOS devices

generate_junos_cmd(dev)

Generates an etree.Element object suitable for use with JunoScript

ios_parse(data, device)

Parse IOS config based on EBNF grammar

ipv4_cidr_to_netmask(bits)

Convert CIDR bits to netmask

junos_parse(data, device)

Do all the magic to parse Junos interfaces

Previous topic

trigger.changemgmt — Change management library

Next topic

trigger.conf — Configuration & Settings module

This Page