mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
- pep 8 adjustments
This commit is contained in:
parent
cb24583053
commit
f206a4563d
14 changed files with 42 additions and 35 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -27,3 +27,5 @@ share/
|
|||
.coverage
|
||||
coverage.xml
|
||||
htmlcov/
|
||||
/.project
|
||||
/.pydevproject
|
||||
|
|
|
@ -10,6 +10,7 @@ import copy
|
|||
import salt.client
|
||||
import salt.output
|
||||
|
||||
|
||||
class Batch(object):
|
||||
'''
|
||||
Manage the execution of batch runs
|
||||
|
|
|
@ -13,6 +13,7 @@ import salt.utils as utils
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Key(object):
|
||||
'''
|
||||
The object that encapsulates saltkey actions
|
||||
|
@ -188,6 +189,7 @@ class Key(object):
|
|||
os.remove(rej)
|
||||
self._log('Removed rejected key {0}'.format(delete),
|
||||
level='info')
|
||||
|
||||
def _delete_all(self):
|
||||
'''
|
||||
Delete all keys
|
||||
|
@ -196,7 +198,6 @@ class Key(object):
|
|||
for key in self._keys(dir):
|
||||
self._delete_key(key)
|
||||
|
||||
|
||||
def _reject(self, key):
|
||||
'''
|
||||
Reject a specified host's public key
|
||||
|
|
|
@ -47,10 +47,10 @@ from salt.exceptions import SaltClientError, SaltInvocationError
|
|||
# Try to import range from https://github.com/ytoolshed/range
|
||||
RANGE = False
|
||||
try:
|
||||
import seco.range
|
||||
RANGE = True
|
||||
import seco.range
|
||||
RANGE = True
|
||||
except ImportError:
|
||||
pass
|
||||
pass
|
||||
|
||||
|
||||
def condition_kwarg(arg, kwarg):
|
||||
|
@ -103,7 +103,7 @@ class LocalClient(object):
|
|||
# If the running user is just the specified user in the
|
||||
# conf file, don't pass the user as it's implied.
|
||||
elif user == self.opts['user']:
|
||||
return None
|
||||
return None
|
||||
return user
|
||||
|
||||
def _check_glob_minions(self, expr):
|
||||
|
@ -156,10 +156,10 @@ class LocalClient(object):
|
|||
def _convert_range_to_list(self, tgt):
|
||||
range = seco.range.Range(self.opts['range_server'])
|
||||
try:
|
||||
return range.expand(tgt)
|
||||
return range.expand(tgt)
|
||||
except seco.range.RangeException as e:
|
||||
print(("Range server exception: {0}".format(e)))
|
||||
return []
|
||||
print(("Range server exception: {0}".format(e)))
|
||||
return []
|
||||
|
||||
def gather_job_info(self, jid, tgt, tgt_type):
|
||||
'''
|
||||
|
@ -695,8 +695,8 @@ class LocalClient(object):
|
|||
# Convert a range expression to a list of nodes and change expression
|
||||
# form to list
|
||||
if expr_form == 'range' and RANGE:
|
||||
tgt = self._convert_range_to_list(tgt)
|
||||
expr_form = 'list'
|
||||
tgt = self._convert_range_to_list(tgt)
|
||||
expr_form = 'list'
|
||||
|
||||
# Run a check_minions, if no minions match return False
|
||||
# format the payload - make a function that does this in the payload
|
||||
|
@ -718,14 +718,14 @@ class LocalClient(object):
|
|||
'minions': minions}
|
||||
|
||||
# Generate the standard keyword args to feed to format_payload
|
||||
payload_kwargs = { 'cmd': 'publish',
|
||||
payload_kwargs = {'cmd': 'publish',
|
||||
'tgt': tgt,
|
||||
'fun': fun,
|
||||
'arg': arg,
|
||||
'key': self.key,
|
||||
'tgt_type': expr_form,
|
||||
'ret': ret,
|
||||
'jid': jid }
|
||||
'jid': jid}
|
||||
|
||||
# If we have a salt user, add it to the payload
|
||||
if self.salt_user:
|
||||
|
@ -735,7 +735,7 @@ class LocalClient(object):
|
|||
if self.opts['order_masters']:
|
||||
payload_kwargs['to'] = timeout
|
||||
|
||||
package = salt.payload.format_payload( 'clear', **payload_kwargs)
|
||||
package = salt.payload.format_payload('clear', **payload_kwargs)
|
||||
|
||||
# Prep zmq
|
||||
context = zmq.Context()
|
||||
|
|
|
@ -17,7 +17,6 @@ try:
|
|||
except:
|
||||
pass
|
||||
|
||||
|
||||
# Import salt libs
|
||||
import salt.crypt
|
||||
import salt.loader
|
||||
|
@ -42,6 +41,7 @@ def _validate_file_roots(file_roots):
|
|||
file_roots[env] = []
|
||||
return file_roots
|
||||
|
||||
|
||||
def _append_domain(opts):
|
||||
'''
|
||||
Append a domain to the existing id if it doesn't already exist
|
||||
|
@ -54,6 +54,7 @@ def _append_domain(opts):
|
|||
return opts['id']
|
||||
return "{0[id]}.{0[append_domain]}".format(opts)
|
||||
|
||||
|
||||
def _read_conf_file(path):
|
||||
with open(path, 'r') as conf_file:
|
||||
conf_opts = yaml.safe_load(conf_file.read()) or {}
|
||||
|
@ -77,7 +78,7 @@ def load_config(opts, path, env_var):
|
|||
if os.path.isfile(template):
|
||||
with open(path, 'w') as out:
|
||||
with open(template, 'r') as f:
|
||||
f.readline() # skip first line
|
||||
f.readline() # skip first line
|
||||
out.write(f.read())
|
||||
|
||||
if os.path.isfile(path):
|
||||
|
@ -268,4 +269,3 @@ def master_config(path):
|
|||
opts['auto_accept'] = opts['auto_accept'] is True
|
||||
opts['file_roots'] = _validate_file_roots(opts['file_roots'])
|
||||
return opts
|
||||
|
||||
|
|
|
@ -118,7 +118,6 @@ class MasterKeys(dict):
|
|||
return open(self.pub_path, 'r').read()
|
||||
|
||||
|
||||
|
||||
class Auth(object):
|
||||
'''
|
||||
The Auth class provides the sequence for setting up communication with
|
||||
|
|
|
@ -2,71 +2,71 @@
|
|||
This module is a central location for all salt exceptions
|
||||
'''
|
||||
|
||||
|
||||
class SaltException(Exception):
|
||||
'''
|
||||
Base exception class; all Salt-specific exceptions should subclass this
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
class SaltClientError(SaltException):
|
||||
'''
|
||||
Problem reading the master root key
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
class SaltMasterError(SaltException):
|
||||
'''
|
||||
Problem reading the master root key
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
class AuthenticationError(SaltException):
|
||||
'''
|
||||
If sha256 signature fails during decryption
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
class CommandNotFoundError(SaltException):
|
||||
'''
|
||||
Used in modules or grains when a required binary is not available
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
class CommandExecutionError(SaltException):
|
||||
'''
|
||||
Used when a module runs a command which returns an error and wants
|
||||
to show the user the output gracefully instead of dying
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
class LoaderError(SaltException):
|
||||
'''
|
||||
Problems loading the right renderer
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
class MinionError(SaltException):
|
||||
'''
|
||||
Minion problems reading uris such as salt:// or http://
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
class SaltInvocationError(SaltException):
|
||||
'''
|
||||
Used when the wrong number of arguments are sent to modules or invalid
|
||||
arguments are specified on the command line
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
class PkgParseError(SaltException):
|
||||
'''
|
||||
Used when of the pkg modules cannot correctly parse the output from
|
||||
the CLI tool (pacman, yum, apt, aptitude, etc)
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
class SaltRenderError(SaltException):
|
||||
'''
|
||||
Used when a renderer needs to raise an explicit error
|
||||
'''
|
||||
pass
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
|
||||
|
||||
def shell():
|
||||
'''
|
||||
Return the default shell to use on this system
|
||||
|
|
|
@ -126,7 +126,7 @@ def daemonize():
|
|||
try:
|
||||
status = win32serviceutil.QueryServiceStatus(servicename)
|
||||
except win32service.error as details:
|
||||
if details[0]==winerror.ERROR_SERVICE_DOES_NOT_EXIST:
|
||||
if details[0] == winerror.ERROR_SERVICE_DOES_NOT_EXIST:
|
||||
saltminionservice.instart(saltminionservice.MinionService, servicename, 'Salt Minion')
|
||||
sys.exit(0)
|
||||
if status[1] == win32service.SERVICE_RUNNING:
|
||||
|
@ -334,7 +334,7 @@ def required_module_list(docstring=None):
|
|||
ret = []
|
||||
txt = 'Required python modules: '
|
||||
data = docstring.split('\n') if docstring else []
|
||||
mod_list = filter(lambda x: x.startswith(txt), data)
|
||||
mod_list = filter(lambda x: x.startswith(txt), data)
|
||||
if not mod_list:
|
||||
return []
|
||||
modules = mod_list[0].replace(txt, '').split(', ')
|
||||
|
@ -358,6 +358,7 @@ def required_modules_error(name, docstring):
|
|||
msg = '\'{0}\' requires these python modules: {1}'
|
||||
return msg.format(filename, ', '.join(modules))
|
||||
|
||||
|
||||
def prep_jid(cachedir, sum_type):
|
||||
'''
|
||||
Return a job id and prepare the job id directory
|
||||
|
@ -373,6 +374,7 @@ def prep_jid(cachedir, sum_type):
|
|||
return prep_jid(cachedir, sum_type)
|
||||
return jid
|
||||
|
||||
|
||||
def jid_dir(jid, cachedir, sum_type):
|
||||
'''
|
||||
Return the jid_dir for the given job id
|
||||
|
@ -380,6 +382,7 @@ def jid_dir(jid, cachedir, sum_type):
|
|||
jhash = getattr(hashlib, sum_type)(jid).hexdigest()
|
||||
return os.path.join(cachedir, 'jobs', jhash[:2], jhash[2:])
|
||||
|
||||
|
||||
def check_or_die(command):
|
||||
'''
|
||||
Simple convienence function for modules to use
|
||||
|
|
|
@ -10,6 +10,7 @@ import datetime
|
|||
import tempfile
|
||||
import traceback
|
||||
|
||||
|
||||
def _makepretty(printout, stack):
|
||||
'''
|
||||
Pretty print the stack trace and environment information
|
||||
|
@ -35,6 +36,7 @@ def _handle_sigusr1(sig, stack):
|
|||
with open(destfile, 'w') as output:
|
||||
_makepretty(output, stack)
|
||||
|
||||
|
||||
def enable_sigusr1_handler():
|
||||
'''
|
||||
Pretty print a stack trace to the console or a debug log under /tmp
|
||||
|
|
|
@ -5,6 +5,7 @@ import winerror
|
|||
import salt
|
||||
import sys
|
||||
|
||||
|
||||
class MinionService(Service):
|
||||
def start(self):
|
||||
self.runflag=True
|
||||
|
@ -24,7 +25,7 @@ if __name__ == '__main__':
|
|||
try:
|
||||
status = win32serviceutil.QueryServiceStatus(servicename)
|
||||
except win32service.error as details:
|
||||
if details[0]==winerror.ERROR_SERVICE_DOES_NOT_EXIST:
|
||||
if details[0] == winerror.ERROR_SERVICE_DOES_NOT_EXIST:
|
||||
instart(MinionService, servicename, 'Salt Minion')
|
||||
sys.exit(0)
|
||||
if status[1] == win32service.SERVICE_RUNNING:
|
||||
|
@ -32,4 +33,3 @@ if __name__ == '__main__':
|
|||
win32serviceutil.StartService(servicename)
|
||||
else:
|
||||
win32serviceutil.StartService(servicename)
|
||||
|
||||
|
|
|
@ -153,4 +153,3 @@ template_registry = {
|
|||
'mako': mako,
|
||||
'py': py,
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ def zmq_version():
|
|||
log.warn(msg.format(ver))
|
||||
return True
|
||||
|
||||
major,minor,point = match.groups()
|
||||
major, minor, point = match.groups()
|
||||
|
||||
if major.isdigit():
|
||||
major = int(major)
|
||||
|
|
|
@ -59,4 +59,3 @@ class CustomLoader(yaml.reader.Reader, yaml.scanner.Scanner, yaml.parser.Parser,
|
|||
yaml.composer.Composer.__init__(self)
|
||||
CustomeConstructor.__init__(self)
|
||||
yaml.resolver.Resolver.__init__(self)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue