Skip to content

Commit

Permalink
dev: add recursion to derivate commands
Browse files Browse the repository at this point in the history
  • Loading branch information
greenpau authored Jan 25, 2017
1 parent 0c5f118 commit e8935ab
Show file tree
Hide file tree
Showing 10 changed files with 294 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ docker/alpine/demo/
# Personal files
TODO
*.hidden
.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export USER
PLUGIN_NAME="ndmtk"
PLUGIN_NAME_EGG := $(subst -,_,$(PLUGIN_NAME))
PLUGIN_VER=0.1.2
PLUGIN_VER=0.1.3
DOCKER_IMAGE_NAME="greenpau/ndmtk"
DOCKER_CONTAINER_NAME="ndmtk"
DOCKER_CONTAINER_SHELL="/bin/sh"
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ machine:
version: 2.7.5
environment:
PACKAGE: ndmtk
VERSION: '0.1.2'
VERSION: '0.1.3'
TAG1: ${VERSION}-$(date +%Y%m%dT%H%M)-git-${CIRCLE_SHA1:0:7}
TAG2: ${CIRCLE_PR_USERNAME}_${CIRCLE_BRANCH/pull\//pr_}
services:
Expand Down
4 changes: 2 additions & 2 deletions docker/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ COPY demo/firewall/files/ndmtk/spec/*.yml /etc/ansible/files/ndmtk/spec/
COPY demo/firewall/files/ndmtk/os/*.yml /etc/ansible/files/ndmtk/os/
COPY demo/firewall/files/ndmtk/host/*.yml /etc/ansible/files/ndmtk/host/
COPY demo/firewall/files/ndmtk/exceptions.yml /etc/ansible/files/ndmtk/
COPY dist/ndmtk-0.1.2.tar.gz /usr/local/src/
RUN pip install /usr/local/src/ndmtk-0.1.2.tar.gz
COPY dist/ndmtk-0.1.3.tar.gz /usr/local/src/
RUN pip install /usr/local/src/ndmtk-0.1.3.tar.gz

ENTRYPOINT ["/bin/sh"]
4 changes: 2 additions & 2 deletions docker/centos/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ COPY demo/firewall/files/ndmtk/spec/*.yml /etc/ansible/files/ndmtk/spec/
COPY demo/firewall/files/ndmtk/os/*.yml /etc/ansible/files/ndmtk/os/
COPY demo/firewall/files/ndmtk/host/*.yml /etc/ansible/files/ndmtk/host/
COPY demo/firewall/files/ndmtk/exceptions.yml /etc/ansible/files/ndmtk/
COPY dist/ndmtk-0.1.2.tar.gz /usr/local/src/
RUN pip install /usr/local/src/ndmtk-0.1.2.tar.gz
COPY dist/ndmtk-0.1.3.tar.gz /usr/local/src/
RUN pip install /usr/local/src/ndmtk-0.1.3.tar.gz

ENTRYPOINT ["/bin/bash"]
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
# built documents.
#
# The short X.Y version.
version = u'0.1.2'
version = u'0.1.3'
# The full version, including alpha/beta/rc tags.
release = u'0.1.2'
release = u'0.1.3'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
270 changes: 266 additions & 4 deletions ndmtk/plugins/action/files/cli/os/nuage_timos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ ndmtk:
tags: ['ref:version']
- description: 'Collect running configuration'
cli: 'admin display-config'
tags: ['ref:conf']
tags: ['ref:conf', 'configuration']
- description: 'Collect running configuration (extensive)'
cli: 'admin display-config detail'



- description: 'Collects chassis information'
cli: 'show chassis'
tags: ['inventory']
tags: ['ref:version', 'inventory']
- description: 'Collects hardware and software version'
cli: 'show version'
tags: ['ref:version']
- description: 'Collects BOF information'
cli: 'show bof'

Expand Down Expand Up @@ -95,7 +97,7 @@ ndmtk:

- description: 'Collects the status of BGP process'
cli: 'show router bgp summary all'
tags: ['bgp', 'test']
tags: ['bgp']
derivatives:
- os:
- nuage_timos
Expand Down Expand Up @@ -134,3 +136,263 @@ ndmtk:
- description: 'Collects BGP IPv4 routing table (detailed)'
cli: 'show router bgp routes ipv4 detail'
tags: ['bgp']

- description: 'collect MC-LAG status'
cli: 'show lag'
tags: ['lag', 'network']
conditions_match_any:
- '^\s*lag\s\d+'
derivatives:
- os:
- nuage_timos
regex:
- pattern: '^(?P<LAG_ID>\d+)\s+'
flags: ['add_cli']
actions:
- description: 'collect detailed information about MC-LAG <LAG_ID>'
cli: 'show lag <LAG_ID> detail'
required: ['LAG_ID']
format: 'txt'
- description: 'collect network utilization information about MC-LAG <LAG_ID>'
cli: 'show lag <LAG_ID> statistics'
required: ['LAG_ID']
format: 'txt'
- description: 'collect information about available ports'
cli: 'show port'
tags: ['interface', 'network']
derivatives:
- os:
- nuage_timos
regex:
- pattern: '^(?P<PORT_ID>\S+)\s+.*(Up|Down)'
flags: ['add_cli']
actions:
- description: 'collect detailed information about port <PORT_ID>'
cli: 'show port <PORT_ID> detail'
required: ['PORT_ID']
format: 'txt'
- description: 'collect QoS status'
cli: 'show qos network detail'
tags: ['qos', 'network']
- description: 'collect QoS DSCP configuration'
cli: 'show qos dscp-table'
tags: ['qos', 'network']
- description: 'collect QoS Ingress Policy configuration'
cli: 'show qos ingress'
tags: ['qos', 'network']
- description: 'collect QoS Egress Policy configuration'
cli: 'show qos egress'
tags: ['qos', 'network']

- description: 'collect QoS status'
cli: 'show qos network detail'
tags: ['qos', 'network']
- description: 'collect QoS DSCP configuration'
cli: 'show qos dscp-table'
tags: ['qos', 'network']
- description: 'collect QoS Ingress Policy configuration'
cli: 'show qos ingress'
tags: ['qos', 'network']
- description: 'collect QoS Egress Policy configuration'
cli: 'show qos egress'
tags: ['qos', 'network']
- description: 'collect DHCP statistics'
cli: 'show router dhcp statistics'
tags: ['dhcp', 'network']
- description: 'collect ECMP routing status'
cli: 'show router ecmp'
tags: ['ecmp', 'network']
- description: 'collect VRRP instance status'
cli: 'show router vrrp instance'
tags: ['vrrp', 'hsrp', 'network']
- description: 'collect VRRP instance statistics'
cli: 'show router vrrp statistics'
tags: ['vrrp', 'hsrp', 'network']
- description: 'collect VRRP instance statistics'
cli: 'show router vxlan'
tags: ['vxlan', 'network']
- description: 'collect router interface information'
cli: 'show router interface'
tags: ['router', 'network']
- description: 'collect router interface detailed information'
cli: 'show router interface detail'
tags: ['router', 'network']
- description: 'collect router interface summary information'
cli: 'show router interface summary'
tags: ['router', 'network']
- description: 'collect unicast IPv4 route table'
cli: 'show router route-table ipv4'
tags: ['route', 'network']
- description: 'collect multicast IPv4 route table'
cli: 'show router route-table mcast-ipv4'
tags: ['route', 'multicast', 'network']
- description: 'collect unicast IPv4 route table Summary'
cli: 'show router route-table ipv4 summary'
tags: ['route', 'network']
- description: 'collect multicast IPv4 route table Summary'
cli: 'show router route-table mcast-ipv4 summary'
tags: ['route', 'multicast', 'network']
- description: 'collect static ARP configuration'
cli: 'show router static-arp'
tags: ['arp', 'network']
- description: 'collect tunnel route table'
cli: 'show router tunnel-table'
tags: ['route', 'network']
- description: 'collect tunnel route table summary'
cli: 'show router tunnel-table summary'
tags: ['route', 'network']

- description: 'collect OSPF status'
cli: 'show router ospf status'
tags: ['routing', 'ospf', 'network']
conditions_match_any:
- '^\s*ospf\s*$'
- description: 'collect OSPF routes'
cli: 'show router ospf routes'
tags: ['routing', 'ospf', 'network']
conditions_match_any:
- '^\s*ospf\s*$'
- description: 'collect OSPF database information'
cli: 'show router ospf database'
tags: ['routing', 'ospf', 'network']
conditions_match_any:
- '^\s*ospf\s*$'
- description: 'collect OSPF neighbor information'
cli: 'show router ospf neighbor'
tags: ['routing', 'ospf', 'network']
conditions_match_any:
- '^\s*ospf\s*$'

- description: 'collect Forwarding Database (FDB) information'
cli: 'show service fdb-info'
tags: ['service', 'network']
- description: 'collect information about Customers'
cli: 'show service customer'
tags: ['service', 'network']
- description: 'collect information about Service Access Points'
cli: 'show service sap-using'
tags: ['service', 'network']
- description: 'collect information about Service Oper Group'
cli: 'show service oper-group'
tags: ['service', 'network']
- description: 'collect information about Service Distribution Points (SDP) usage'
cli: 'show service sdp-using'
tags: ['service', 'network']
- description: 'collect information about Services'
cli: 'show service service-using'
tags: ['service', 'network']
- description: 'collect information about Sites'
cli: 'show service site-using'
tags: ['service', 'network']

- description: 'collects TCP connections table'
cli: 'show system connections detail'
tags: ['connections', 'network']
- description: 'collect AAA provider status'
cli: 'show system security authentication'
tags: ['security']
- description: 'collect AAA provider statistics'
cli: 'show system security authentication statistics'
tags: ['security']
- description: 'collect information about IPv4 management access filter'
cli: 'show system security management-access-filter ip-filter'
tags: ['security', 'firewall']
- description: 'collect information about IPv6 management access filter'
cli: 'show system security management-access-filter ipv6-filter'
tags: ['security', 'firewall', 'ipv6']
- description: 'collect information about MAC address management access filter'
cli: 'show system security management-access-filter mac-filter'
tags: ['security', 'firewall']

- description: 'collect information about users'
cli: 'show system security user'
tags: ['security', 'users']
derivatives:
- os:
- nuage_timos
regex:
- pattern: '^(?P<USERNAME>\S+)\s+(y|n)\s+'
flags: ['add_cli']
actions:
- description: 'collect information about user <USERNAME>'
cli: 'show system security user "<USERNAME>" detail'
required: ['USERNAME']
format: 'txt'

- description: 'Collect SSH service status'
cli: 'show system security ssh'
tags: ['security', 'ssh']


- description: 'Collect Virtual Switch Controller summary'
cli: 'show vswitch-controller summary'
tags: ['vswitch']


- description: 'Collect information about Applications'
cli: 'show vswitch-controller application detail'
tags: ['vswitch']
- description: 'Collect information about vSwitches'
cli: 'show vswitch-controller vswitches'
tags: ['vswitch']
- description: 'Collect detailed information about vSwitches'
cli: 'show vswitch-controller vswitches detail'
tags: ['vswitch']

- description: 'collect information about Nuage Enterprises'
cli: 'show vswitch-controller enterprise'
tags: ['vswitch']
derivatives:
- os:
- nuage_timos
regex:
- pattern: '^(?P<NUAGE_VSD_ENTERPRISE>\S+)\s+\d+\s+\d+\s*$'
flags: ['add_cli']
actions:
- description: 'collect information about <NUAGE_VSD_ENTERPRISE> enterprise'
cli: 'show vswitch-controller enterprise "<NUAGE_VSD_ENTERPRISE>" domain'
required: ['NUAGE_VSD_ENTERPRISE']
format: 'txt'
derivatives:
- os:
- nuage_timos
regex:
- pattern: '^(?P<NUAGE_VSD_DOMAIN>\S+)\s*(?P<NUAGE_SVC_ID>\d+)\s*$'
flags: ['add_cli']
actions:
- description: 'collect information about IP routes in <NUAGE_VSD_DOMAIN> domain of <NUAGE_VSD_ENTERPRISE> enterprise'
cli: 'show vswitch-controller ip-routes enterprise "<NUAGE_VSD_ENTERPRISE>" domain "<NUAGE_VSD_DOMAIN>"'
required: ['NUAGE_VSD_ENTERPRISE', 'NUAGE_VSD_DOMAIN']
format: 'txt'
- description: 'collect information about MAC routes in <NUAGE_VSD_DOMAIN> domain of <NUAGE_VSD_ENTERPRISE> enterprise for Service Id <NUAGE_SVC_ID>'
cli: 'show vswitch-controller mac-routes svcId <NUAGE_SVC_ID>'
required: ['NUAGE_SVC_ID']
format: 'txt'
- description: 'collect information about ESI routes in <NUAGE_VSD_DOMAIN> domain of <NUAGE_VSD_ENTERPRISE> enterprise for Service Id <NUAGE_SVC_ID>'
cli: 'show vswitch-controller esi-routes svcId <NUAGE_SVC_ID>'
required: ['NUAGE_SVC_ID']
format: 'txt'
- description: 'collect information about ARP routes in <NUAGE_VSD_DOMAIN> domain of <NUAGE_VSD_ENTERPRISE> enterprise for Service Id <NUAGE_SVC_ID>'
cli: 'show vswitch-controller arp-routes svcId <NUAGE_SVC_ID>'
required: ['NUAGE_SVC_ID']
format: 'txt'
- description: 'collect information about EVPN flood list in <NUAGE_VSD_DOMAIN> domain of <NUAGE_VSD_ENTERPRISE> enterprise for Service Id <NUAGE_SVC_ID>'
cli: 'show vswitch-controller evpn-floodlist svcId <NUAGE_SVC_ID>'
required: ['NUAGE_SVC_ID']
format: 'txt'
- description: 'collect detailed information about <NUAGE_VSD_ENTERPRISE> enterprise'
cli: 'show vswitch-controller enterprise "<NUAGE_VSD_ENTERPRISE>" domain detail'
required: ['NUAGE_VSD_ENTERPRISE']
format: 'txt'
- description: 'collect information about containers in <NUAGE_VSD_ENTERPRISE> enterprise'
cli: 'show vswitch-controller containers enterprise "<NUAGE_VSD_ENTERPRISE>"'
required: ['NUAGE_VSD_ENTERPRISE']
format: 'txt'
- description: 'collect detailed information about containers in <NUAGE_VSD_ENTERPRISE> enterprise'
cli: 'show vswitch-controller containers enterprise "<NUAGE_VSD_ENTERPRISE>" detail'
required: ['NUAGE_VSD_ENTERPRISE']
format: 'txt'
- description: 'collect detailed information about Bridge Virtual Ports in <NUAGE_VSD_ENTERPRISE> enterprise'
cli: 'show vswitch-controller bridges enterprise "<NUAGE_VSD_ENTERPRISE>"'
required: ['NUAGE_VSD_ENTERPRISE']
format: 'txt'
8 changes: 8 additions & 0 deletions ndmtk/plugins/action/ndmtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,9 @@ def _lookup_additional_commands(self, fn, cli_id):
if _os_not_found:
continue;
db = {};
if 'facts' in derivative:
for fact in derivative['facts']:
db[fact] = derivative['facts'][fact];
for line in fc:
_break = False;
flags = [];
Expand All @@ -1687,6 +1690,9 @@ def _lookup_additional_commands(self, fn, cli_id):
gd = m.groupdict();
if 'purge' in p['flags']:
db = {};
if 'facts' in derivative:
for fact in derivative['facts']:
db[fact] = derivative['facts'][fact];
for k in gd:
db[k] = gd[k];
except:
Expand Down Expand Up @@ -1780,6 +1786,7 @@ def _lookup_additional_commands(self, fn, cli_id):
cli_entry['mode'] = 'analytics';
if 'derivatives' in a:
cli_entry['derivatives'] = a['derivatives'];
cli_entry['derivatives'][0]['facts'] = copy.deepcopy(db);
'''
TODO: this is a remnant of some other thing. check `preserve`
'''
Expand Down Expand Up @@ -3076,6 +3083,7 @@ def _normalize_str(cmd, host=None, suffix=None):
cmd = cmd.replace('_', '_US_');
cmd = cmd.replace('/', '_FS_').replace('|', '_PIPE_').replace('.', '_DOT_').replace(' ', '.');
cmd = cmd.replace(':', '_CL_').replace(';', '_SCL_').replace('@', '_ATS_').replace('?', '_QM_');
cmd = cmd.replace('"', '_DQ_');
if host is None or suffix is None:
return cmd;
cmd = host + '.' + cmd + '.' + suffix;
Expand Down
Loading

0 comments on commit e8935ab

Please sign in to comment.