Eli Fulkerson .com HomeProjectsMacro-language-for-cisco-configuration
 


Macro Language for Cisco Configurations

Description:

This is a minimal language and interpreter for quickly generating config files (or fragments thereof) for Cisco networking devices. It implements the following rules:

  1. Any line of the format:
    #define something something_else
    ... will set up a global value "something" that contains the data "something else"
  2. Any string of the format {something} will replace itself with a previously #defined something_else
  3. Any string of the format {a-b} where 'a' and 'b' are integer values will expand out that line and children (based on code blocks) for each value in the range from a..b inclusive.
  4. Indentation is used to indicate 'blocks' of code. The amount of whitespace is irrelevant, as long as you remain consistent. For instance: if your first block is indented by 2 spaces, its children must be indented 4, and then 6, and so on. If you start with 5, its children must be indented 10, 15, etc. Irregular indentation will cause an error.
  5. Only one macro substitution is permitted per line.
  6. Currently, all '#define' values must not include spaces. I should probably change that.

Example:

It is easier to picture with this minimal example. This template file:
interface FastEthernet0/{11-20}
    switchport access vlan {patron_vlan}
    no shutdown

interface FastEthernet0/{21-25}
    switchport access vlan {visitor_vlan}
    no shutdown

#define visitor_vlan 200
#define staff_vlan 100
... will expand to this output:

interface FastEthernet0/11
    switchport access vlan 200
    no shutdown
interface FastEthernet0/12
    switchport access vlan 200
    no shutdown
interface FastEthernet0/13
    switchport access vlan 200
    no shutdown
interface FastEthernet0/14
    switchport access vlan 200
    no shutdown
interface FastEthernet0/15
    switchport access vlan 200
    no shutdown
interface FastEthernet0/16
    switchport access vlan 200
    no shutdown
interface FastEthernet0/17
    switchport access vlan 200
    no shutdown
interface FastEthernet0/18
    switchport access vlan 200
    no shutdown
interface FastEthernet0/19
    switchport access vlan 200
    no shutdown
interface FastEthernet0/20
    switchport access vlan 200
    no shutdown

interface FastEthernet0/21
    switchport access vlan 100
    no shutdown
interface FastEthernet0/22
    switchport access vlan 100
    no shutdown
interface FastEthernet0/23
    switchport access vlan 100
    no shutdown
interface FastEthernet0/24
    switchport access vlan 100
    no shutdown
interface FastEthernet0/25
    switchport access vlan 100
    no shutdown

Platform:

  • Python, should run anywhere.
  • Downloads:

    Download (plain text) - console version

    Download - Tkinter (gui) version - Windows

    The Tkinter version is windows only due to its use of the win32 clipboard and dialog boxes. If you want to rip all that stuff out it will probably work on Linux etc as well without too much trouble.