forked from trigger/trigger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ The commands required to commit/save the configuration on a device are now attached to NetDevice objects under the commit_commands attribute, to make it easier to execute these commands without having to determine them for yourself. + Added a way to optionally perform a "commit full" operation on Juniper devices by defining a dictionary of attributes and values for matching devices using settings.JUNIPER_FULL_COMMIT_FIELDS. This modifies the commit_commands that are assigned when the NetDevice object is created. + Console paging is now disabled by default for async SSH channels.
- Loading branch information
Showing
11 changed files
with
207 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ __author__ = 'Jathan McCollum, Eileen Tschetter, Mark Ellzey Thomas, Michael Shi | |
__maintainer__ = 'Jathan McCollum' | ||
__email__ = '[email protected]' | ||
__copyright__ = 'Copyright 2003-2012, AOL Inc.' | ||
__version__ = '1.7' | ||
__version__ = '1.8' | ||
|
||
# Dist imports | ||
from collections import defaultdict | ||
|
@@ -395,13 +395,16 @@ def get_work(opts, args): | |
|
||
return work | ||
|
||
def junoscript_cmds(acls): | ||
def junoscript_cmds(acls, dev): | ||
""" | ||
Return a list of Junoscript commands to load the given ACLs, and a | ||
matching list of tuples (acls remaining, human-readable status message). | ||
:param acls: | ||
A collection of ACL names | ||
:param dev: | ||
A Juniper `~trigger.netdevices.NetDevice` object | ||
""" | ||
xml = [Element('lock-configuration')] | ||
status = ['locking configuration'] | ||
|
@@ -413,7 +416,8 @@ def junoscript_cmds(acls): | |
xml.append(lc) | ||
status.append('loading ACL ' + acl) | ||
|
||
xml.append(Element('commit-configuration')) | ||
# Add the proper commit command | ||
xml.extend(dev.commit_commands) | ||
status.append('committing for ' + ','.join(acls)) | ||
status.append('done for' + ','.join(acls) ) | ||
|
||
|
@@ -447,7 +451,9 @@ def ioslike_cmds(acls, dev, nonce): | |
template = template_base[dev.vendor.name] | ||
cmds = [template % (get_tftp_source(dev), acl, nonce) for acl in acls] | ||
status = ['loading ACL ' + acl for acl in acls] | ||
cmds.append('write mem') | ||
|
||
# Add the proper write mem command | ||
cmds.extend(dev.commit_commands) | ||
status.append('saving config for ' + ','.join(acls)) | ||
status.append('done for ' + ','.join(acls)) | ||
|
||
|
@@ -591,7 +597,7 @@ def activate(work, active, failures, jobs, redraw): | |
active[dev] = 'connecting' | ||
|
||
if dev.vendor == 'juniper': | ||
cmds, status = junoscript_cmds(acls) | ||
cmds, status = junoscript_cmds(acls, dev) | ||
execute = execute_junoscript | ||
else: | ||
nonce = os.urandom(8).encode('hex') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,10 @@ | |
__maintainer__ = 'Jathan McCollum' | ||
__email__ = '[email protected]' | ||
__copyright__ = 'Copyright 2006-2012, AOL Inc.' | ||
__version__ = '1.4.0' | ||
__version__ = '1.4.1' | ||
|
||
# Imports (duh?) | ||
import copy | ||
import itertools | ||
import os | ||
import sys | ||
|
@@ -47,11 +48,14 @@ | |
except ImportError: | ||
import json | ||
import sqlite3 | ||
from xml.etree.cElementTree import parse | ||
import xml.etree.cElementTree as ET | ||
|
||
|
||
# Constants | ||
SUPPORTED_FORMATS = ('json', 'rancid', 'sqlite', 'xml') | ||
JUNIPER_COMMIT = ET.Element('commit-configuration') | ||
JUNIPER_COMMIT_FULL = copy.copy(JUNIPER_COMMIT) | ||
ET.SubElement(JUNIPER_COMMIT_FULL, 'full') | ||
|
||
|
||
# Exports | ||
|
@@ -83,7 +87,7 @@ def _parse_xml(data_source): | |
""" | ||
# Parsing the complete file into a tree once and extracting outthe device | ||
# nodes is faster than using iterparse(). Curses!! | ||
xml = parse(data_source).findall('device') | ||
xml = ET.parse(data_source).findall('device') | ||
|
||
# This is a generator within a generator. Trust me, it works in _populate() | ||
data = (((e.tag, e.text) for e in node.getchildren()) for node in xml) | ||
|
@@ -309,6 +313,9 @@ def __init__(self, data=None, with_acls=None): | |
# Bind the correct execute/connect methods based on deviceType | ||
self._bind_dynamic_methods() | ||
|
||
# Assign the configuration commit commands (e.g. 'write memory') | ||
self.commit_commands = self._determine_commit_commands() | ||
|
||
def _populate_data(self, data): | ||
""" | ||
Populate the custom attribute data | ||
|
@@ -341,6 +348,45 @@ def _populate_deviceType(self): | |
self.deviceType = settings.DEFAULT_TYPES.get(self.vendor.name, | ||
settings.FALLBACK_TYPE) | ||
|
||
def _determine_commit_commands(self): | ||
""" | ||
Return the proper "commit" command. (e.g. write mem, etc.) | ||
""" | ||
if self.is_ioslike(): | ||
return self._ioslike_commit() | ||
elif self.vendor == 'juniper': | ||
return self._juniper_commit() | ||
elif self.is_netscaler(): | ||
return ['save config'] | ||
else: | ||
return [] | ||
|
||
def _ioslike_commit(self): | ||
""" | ||
Return proper 'write memory' command for IOS-like devices. | ||
""" | ||
if self.vendor == 'brocade' and self.is_switch(): | ||
return ['copy running-config startup-config', 'y'] | ||
else: | ||
return ['write memory'] | ||
|
||
def _juniper_commit(self, fields=settings.JUNIPER_FULL_COMMIT_FIELDS): | ||
""" | ||
Return proper ``commit-configuration`` element for a Juniper | ||
device. | ||
""" | ||
default = [JUNIPER_COMMIT] | ||
if not fields: | ||
return default | ||
|
||
# Either it's a normal "commit-configuration" | ||
for attr, val in fields.iteritems(): | ||
if not getattr(self, attr) == val: | ||
return default | ||
|
||
# Or it's a "commit-configuration full" | ||
return [JUNIPER_COMMIT_FULL] | ||
|
||
def _bind_dynamic_methods(self): | ||
""" | ||
Bind dynamic methods to the instance. Currently does these: | ||
|
Oops, something went wrong.