Skip to content

Commit

Permalink
Merge pull request #6 from jmccollum/public_merge
Browse files Browse the repository at this point in the history
Squashed commits to bring internal mirror in sync w/ public repo
  • Loading branch information
Jathan McCollum committed Mar 27, 2014
2 parents 6363349 + db035b7 commit 7a508e5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 30 deletions.
6 changes: 1 addition & 5 deletions bin/load_acl
Expand Up @@ -16,7 +16,7 @@ __author__ = 'Jathan McCollum, Eileen Tschetter, Mark Ellzey Thomas, Michael Shi
__maintainer__ = 'Jathan McCollum'
__email__ = 'jathan.mccollum@teamaol.com'
__copyright__ = 'Copyright 2003-2012, AOL Inc.; 2013 Salesforce.com'
__version__ = '1.9.1'
__version__ = '1.9.2'

# Dist imports
from collections import defaultdict
Expand Down Expand Up @@ -577,7 +577,6 @@ def activate(work, active, failures, jobs, redraw):
reactor.callWhenRunning(handled_first.callback, None)

def chain(result, dev, acls):
#global status
(cmds, status) = result

# Lambda function to call update_board() with proper args
Expand Down Expand Up @@ -693,9 +692,6 @@ def main():
log.msg('No %s file exists and auto option enabled.' % tacacsrc_file)
sys.exit(1)
log.msg('Credential file %s exists, moving on' % tacacsrc_file)
#Tacacsrc()

#print 'Logging to', tmpfile

cm_ticketnum = 0
if not opts.no_cm and not debug_fakeout():
Expand Down
32 changes: 16 additions & 16 deletions bin/netdev
Expand Up @@ -113,7 +113,7 @@ def search_builder(opts):

# For all search arguments, when an explicit match would not be confusing
# or return inconsistent results, the argument is being upper-cased
# and a membership (in) test is being performed.
# and a membership (in) test is being performed.
#
# For explicit matches, use an equality (==) test instead.

Expand All @@ -122,47 +122,47 @@ def search_builder(opts):
vars.append(" '%s' in x.nodeName.lower()" % opts.nodename.lower())

# deviceType
if opts.type:
if opts.type:
vars.append(" '%s' in x.deviceType" % opts.type.upper())

# onCallName (oncall team)
if opts.oncall_team:
if opts.oncall_team:
vars.append (" '%s' in x.onCallName.lower()" % opts.oncall_team.lower())

# owningTeam (owning_team)
if opts.owning_team:
if opts.owning_team:
vars.append (" '%s' in x.owningTeam.lower()" % opts.owning_team.lower())

# owner (owning org)
if opts.owning_org:
if opts.owning_org:
vars.append(" '%s' in x.owner" % opts.owning_org.upper())

# budgetCode (budget code)
if opts.budget_code:
if opts.budget_code:
vars.append(" '%s' in x.budgetCode" % opts.budget_code)

# budgetName (budget name)
if opts.budget_name:
if opts.budget_name:
vars.append(" '%s' in x.budgetName.lower()" % opts.budget_name.lower())

# vendor
if opts.vendor:
vars.append(" '%s' in x.vendor" % opts.vendor.lower())

# manufacturer
if opts.manufacturer:
if opts.manufacturer:
vars.append(" '%s' in x.manufacturer" % opts.manufacturer.upper())

# site
if opts.location:
if opts.location:
vars.append(" '%s' in x.site" % opts.location.upper())

# make
if opts.make:
if opts.make:
vars.append(" '%s' in x.make" % opts.make.upper())

# model
if opts.model:
if opts.model:
vars.append(" '%s' in x.model" % opts.model.upper())

# coordinate/rack
Expand All @@ -174,9 +174,9 @@ def search_builder(opts):
#print 'vlen =', len(vars)

# Build a list comprehension based on the vars list.
# so:
# so:
# [" 'SWITCH' in x.deviceType", 'juniper' in x.vendor"]
# becomes:
# becomes:
# [x for x in nd.all() if 'SWITCH' in x.deviceType and 'juniper' in
# x.vendor]
query += " if"
Expand All @@ -186,19 +186,19 @@ def search_builder(opts):
query += vars[i]
if counter != vlen: query += " and"
counter +=1

# Finalize query
query += "]"
#print query

try:
devlist = eval(query)
except TypeError:
from trigger.conf import settings
from trigger.conf import settings
print "A required field in %s is missing or invalid. Please fix the data and try again." \
% settings.NETDEVICES_SOURCE
sys.exit(1)

devlist.sort()

# Print acls
Expand Down
2 changes: 1 addition & 1 deletion tools/prepend_acl_dot
Expand Up @@ -62,7 +62,7 @@ def main():
(dev.nodeName, acl_name)
log.msg(msg)
print msg

elif opts.dryrun:
msg = "device %s WILL HAVE association %s moved to %s" % \
(dev.nodeName, acl_name, 'acl.%s' % acl_name)
Expand Down
2 changes: 1 addition & 1 deletion trigger/__init__.py
@@ -1,4 +1,4 @@
__version__ = (1, 4, 2, 'b15')
__version__ = (1, 4, 2, 'r16')

full_version = '.'.join(map(str, __version__[0:3])) + ''.join(__version__[3:])
release = full_version
Expand Down
15 changes: 8 additions & 7 deletions trigger/utils/network.py
Expand Up @@ -4,17 +4,21 @@
Functions that perform network-based things like ping, port tests, etc.
"""

__author__ = 'Jathan McCollum'
__author__ = 'Jathan McCollum, Eileen Watson'
__maintainer__ = 'Jathan McCollum'
__email__ = 'jathan.mccollum@teamaol.com'
__copyright__ = 'Copyright 2009-2012, AOL Inc.'
__copyright__ = 'Copyright 2009-2013, AOL Inc.; 2013-2014 Salesforce.com'

import commands
import re
import socket
import telnetlib
from trigger.conf import settings


VALID_HOST_RE = re.compile("^[a-z0-9\-\.]+$")


# Exports
__all__ = ('ping', 'test_tcp_port', 'test_ssh', 'address_is_internal')

Expand All @@ -39,13 +43,10 @@ def ping(host, count=1, timeout=5):
>>> network.ping('192.168.199.253')
False
"""

# Make the command silent even for bad input
import re
valid_host_re = re.compile("^[a-z0-9\-\.]+$")
if not valid_host_re.findall(host):
if not VALID_HOST_RE.findall(host):
return False

ping_command = "ping -q -c%d -W%d %s" % (count, timeout, host)
status, results = commands.getstatusoutput(ping_command)

Expand Down

0 comments on commit 7a508e5

Please sign in to comment.