Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove disabled code and PEP8 cleanups

  • Loading branch information...
commit 60996847ca0018c996623da4e4aa7c9f8a55dbc4 1 parent 8be72be
dhubbard authored
Showing with 27 additions and 47 deletions.
  1. +23 −23 sshmap/sshmap
  2. +4 −24 sshmap/sshmap.py
View
46 sshmap/sshmap
@@ -3,7 +3,7 @@
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
-
+#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@@ -24,12 +24,11 @@ import hostlists
if __name__ == "__main__":
parser = optparse.OptionParser()
- #parser.add_option("--html", dest="html", default=False,action="store_true", help="Use HTML for formatting")
parser.add_option("--output_json", dest="output_json",
default=False, action="store_true",
help = "Output in JSON format")
- parser.add_option("--output_base64", dest = "output_base64", default = False, action = "store_true",
- help = "Output in base64 format")
+ parser.add_option("--output_base64", dest="output_base64", default=False,
+ action="store_true", help="Output in base64 format")
parser.add_option("--summarize_failed", dest = "summarize_failed", default = False, action = "store_true",
help = "Print a list of hosts that failed at the end")
parser.add_option("--aggregate_output", "--collapse", dest = "aggregate_output", default = False,
@@ -55,8 +54,8 @@ if __name__ == "__main__":
help = "Don't show a status count as the command progresses")
parser.add_option("--sudo", dest = "sudo", default = False, action = "store_true",
help = "Use sudo to run the command as root")
- parser.add_option("--password", dest = "password", default = None, action = "store_true",
- help = "Prompt for a password")
+ parser.add_option("--password", dest="password", default=None,
+ action="store_true", help="Prompt for a password")
(options, args) = parser.parse_args()
@@ -66,14 +65,6 @@ if __name__ == "__main__":
command = firstline[2:]
args.append(command)
- #if len(args) != 2:
- # if len(args) and args[0] in ['test']:
- # Unit testing
- # import doctest
-
- # doctest.testmod()
- #sys.exit(0)
-
# Default option values
options.password = None
options.username = getpass.getuser()
@@ -99,21 +90,27 @@ if __name__ == "__main__":
if options.sudo:
# Prompt for password, we really need to add a password file option
try:
- options.password = os.environ['OS_PASSWORD']
+ options.password = os.environ['SUDO_PASSWORD']
except KeyError:
- options.password = getpass.getpass('Enter sudo password for user ' + getpass.getuser() + ': ')
+ options.password = getpass.getpass(
+ 'Enter sudo password for user ' + getpass.getuser() + ': ')
elif options.password:
# Prompt for password, we really need to add a password file option
try:
- options.password = os.environ['OS_PASSWORD']
+ options.password = os.environ['SUDO_PASSWORD']
except KeyError:
- options.password = getpass.getpass('Enter password for user ' + getpass.getuser() + ': ')
+ options.password = getpass.getpass(
+ 'Enter password for user ' + getpass.getuser() + ': ')
command = ' '.join(args[1:])
range = args[0]
- results = sshmap.run(args[0], command, username=options.username, password=options.password, sudo=options.sudo,
- timeout=options.timeout, script=options.runscript, jobs=options.jobs, sort=options.sort,
- shuffle=options.shuffle, output_callback=callback, parms=vars(options))
+ results = sshmap.run(
+ args[0], command, username=options.username,
+ password=options.password, sudo=options.sudo,
+ timeout=options.timeout, script=options.runscript, jobs=options.jobs,
+ sort=options.sort,
+ shuffle=options.shuffle, output_callback=callback, parms=vars(options)
+ )
if options.aggregate_output:
aggregate_hosts = results.setting('aggregate_hosts')
collapsed_output = results.setting('collapsed_output')
@@ -126,5 +123,8 @@ if __name__ == "__main__":
stdout, stderr = collapsed_output[md5]
if len(stdout): print ''.join(stdout)
if len(stderr): print >> sys.stderr, '\n'.join(stderr)
- if options.summarize_failed and 'failures' in results.parm.keys() and len(results.parm['failures']):
- print 'SSH Failed to: %s' % hostlists.compress(results.parm['failures'])
+ if options.summarize_failed and 'failures' in results.parm.keys() and \
+ len(results.parm['failures']):
+ print(
+ 'SSH Failed to: %s' % hostlists.compress(results.parm['failures'])
+ )
View
28 sshmap/sshmap.py
@@ -327,33 +327,12 @@ def run_command(host, command="uname -a", username=None, password=None,
# Send the password
stdin.write(password + '\r')
stdin.flush()
-
- if False:
- # Remove the password prompt and password from the output
- # should only be needed if using a pty
- prompt = _term_readline(stdout)
- seen_password = False
- seen_password_prompt = False
- #print 'READ:',prompt
- while 'assword:' in prompt or False or password in prompt or \
- 'try again' in prompt or len(prompt.strip()) == 0:
- if 'try again' in prompt:
- result.ssh_retcode = defaults.RUN_FAIL_BADPASSWORD
- return result
- prompt_new = _term_readline(stdout)
- if 'assword:' in prompt:
- seen_password_prompt = True
- if password in prompt:
- seen_password = True
- if seen_password_prompt or seen_password:
- break
- prompt = prompt_new
except socket.timeout:
result.err = ['Timeout during sudo connect, likely bad password']
result.ssh_retcode = defaults.RUN_FAIL_TIMEOUT
return result
if script:
- # Pass the script over stdin and close the channel so the receving end
+ # Pass the script over stdin and close the channel so the receiving end
# gets an EOF process it as a django template with the arguments passed
# noinspection PyBroadException
try:
@@ -371,7 +350,7 @@ def run_command(host, command="uname -a", username=None, password=None,
else:
c = django.template.Context({})
stdin.write(django.template.Template(template).render(c))
- except Exception as e:
+ except:
if os.path.exists(script):
stdin.write(open(script, 'r').read())
else:
@@ -401,7 +380,6 @@ def run_command(host, command="uname -a", username=None, password=None,
skip = False
result.err = err
- #print result.err
result.retcode = chan.recv_exit_status()
if close_client:
client.close()
@@ -420,6 +398,8 @@ def init_worker():
def run_with_runner(*args, **kwargs):
"""
Run a command with a python runner script
+ :param args:
+ :param kwargs:
"""
if 'runner' in kwargs.keys() and isinstance(
kwargs['runner'], type.FunctionType):
Please sign in to comment.
Something went wrong with that request. Please try again.