Skip to content

Commit

Permalink
Amended for python2.6 support + added doc + added pyenv ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Cuthbert committed Feb 24, 2016
1 parent 7255d28 commit ca948cf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ _build

# 3rd party
vendor/*
.python-version
16 changes: 16 additions & 0 deletions docs/usage/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ Default::

.. setting:: FIREWALL_DIR

TEXTFSM_TEMPLATE_DIR
~~~~~~~~~~~~~

Default login realm to store user credentials (username, password) for general
use within the ``.tacacsrc`` file.

Default path to TextFSM template directory. It is recommended to pull the Network to Code templates
from here ``https://github.com/networktocode/ntc-ansible/tree/master/ntc_templates`` and place them inside
the vendor directory inside the trigger root.

Default::

'/etc/trigger/vendor/ntc_templates'

.. setting:: TEXTFSM_TEMPLATE_DIR

FIREWALL_DIR
~~~~~~~~~~~~

Expand Down
6 changes: 3 additions & 3 deletions tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ class CheckTemplates(unittest.TestCase):
def setUp(self):
data = cStringIO.StringIO(text_fsm_data)
self.re_table = textfsm.TextFSM(data)
self.assertIsInstance(self.re_table, textfsm.textfsm.TextFSM)
self.assertTrue(isinstance(self.re_table, textfsm.textfsm.TextFSM))

def testTemplatePath(self):
"""Test that template path is correct."""
t_path = get_template_path("show clock", dev_type="cisco_ios")
self.assertIn("vendor/ntc_templates/cisco_ios_show_clock.template", t_path)
self.failUnless("vendor/ntc_templates/cisco_ios_show_clock.template" in t_path)

def testGetTextFsmObject(self):
"""Test that we get structured data back from cli output."""
data = get_textfsm_object(self.re_table, cli_data)
self.assertIsInstance(data, dict)
self.assertTrue(isinstance(data, dict))
keys = ['dayweek', 'time', 'timezone', 'year', 'day', 'month']
for key in keys:
self.assertTrue(data.has_key(key))
Expand Down
6 changes: 0 additions & 6 deletions trigger/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,6 @@ def monitor_result(self, result, reactor):
return task.deferLater(reactor, 0.5, self.monitor_result, result, reactor)


# class StructuredOutput(Commando):
# def from_cisco(self, data, device, commands=None):
# log.msg(data, device, commands)
# self.results[device.nodeName] = _parse_cli_from_textfsm_template(data, device, commands)
# return True


class NetACLInfo(Commando):
"""
Expand Down
2 changes: 1 addition & 1 deletion trigger/utils/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_template_path(cmd, dev_type=None):
:returns: String template path
"""
t_dir = settings.TEXTFSM_TEMPLATE_DIR
return '{0}/{1}_{2}.template'.format(t_dir, dev_type, cmd.replace(' ', '_')) or None
return os.path.join(t_dir, '{1}_{2}.template'.format(t_dir, dev_type, cmd.replace(' ', '_'))) or None


def load_cmd_template(cmd, dev_type=None):
Expand Down

0 comments on commit ca948cf

Please sign in to comment.