本文整理汇总了Python中salt.utils.verify.check_user函数的典型用法代码示例。如果您正苦于以下问题:Python check_user函数的具体用法?Python check_user怎么用?Python check_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_user函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: start
def start(self):
'''
Execute this method to start up a syndic.
'''
verify_env([self.opts['pki_dir'], self.opts['cachedir'],
os.path.dirname(self.opts['log_file']),
],
self.opts['user'])
import salt.log
salt.log.setup_logfile_logger(
self.opts['log_file'], self.opts['log_level']
)
for name, level in self.opts['log_granular_levels'].items():
salt.log.set_logger_level(name, level)
import logging
# Late import so logging works correctly
import salt.minion
log = logging.getLogger(__name__)
if self.cli['daemon']:
# Late import so logging works correctly
import salt.utils
salt.utils.daemonize()
set_pidfile(self.cli['pidfile'])
if check_user(self.opts['user'], log):
try:
syndic = salt.minion.Syndic(self.opts)
syndic.tune_in()
except KeyboardInterrupt:
log.warn('Stopping the Salt Syndic Minion')
raise SystemExit('\nExiting on Ctrl-c')
开发者ID:Adapptor,项目名称:salt,代码行数:32,代码来源:__init__.py
示例2: start
def start(self):
'''
Start broker.
'''
self.prepare()
if check_user(self.config['user']):
self.broker.start()
开发者ID:MarloweW,项目名称:salt-broker,代码行数:7,代码来源:__init__.py
示例3: start
def start(self):
'''
Execute this method to start up a minion.
'''
verify_env([self.opts['pki_dir'],
self.opts['cachedir'],
self.opts['extension_modules'],
os.path.dirname(self.opts['log_file']),
])
import salt.log
salt.log.setup_logfile_logger(
self.opts['log_file'], self.opts['log_level']
)
for name, level in self.opts['log_granular_levels'].iteritems():
salt.log.set_logger_level(name, level)
import logging
# Late import so logging works correctly
import salt.minion
log = logging.getLogger(__name__)
if self.cli['daemon']:
# Late import so logging works correctly
import salt.utils
# If the minion key has not been accepted, then Salt enters a loop
# waiting for it, if we daemonize later then the minion cound halt
# the boot process waiting for a key to be accepted on the master.
# This is the latest safe place to daemonize
salt.utils.daemonize()
minion = salt.minion.Minion(self.opts)
set_pidfile(self.cli['pidfile'])
if check_user(self.opts['user'], log):
try:
minion.tune_in()
except KeyboardInterrupt:
log.warn('Stopping the Salt Minion')
raise SystemExit('\nExiting on Ctrl-c')
开发者ID:LinuxJedi,项目名称:salt,代码行数:35,代码来源:__init__.py
示例4: start
def start(self):
'''
Start the actual proxy minion.
If sub-classed, don't **ever** forget to run:
super(YourSubClass, self).start()
NOTE: Run any required code before calling `super()`.
'''
super(ProxyMinion, self).start()
try:
if check_user(self.config['user']):
self.action_log_info('The Proxy Minion is starting up')
self.verify_hash_type()
self.minion.tune_in()
if self.minion.restart:
raise SaltClientError('Proxy Minion could not connect to Master')
except (KeyboardInterrupt, SaltSystemExit) as exc:
self.action_log_info('Proxy Minion Stopping')
if isinstance(exc, KeyboardInterrupt):
log.warning('Exiting on Ctrl-c')
self.shutdown()
else:
log.error(str(exc))
self.shutdown(exc.code)
开发者ID:bryson,项目名称:salt,代码行数:26,代码来源:daemons.py
示例5: run
def run(self):
'''
Execute salt-run
'''
import salt.runner
self.parse_args()
# Setup file logging!
self.setup_logfile_logger()
verify_log(self.config)
profiling_enabled = self.options.profiling_enabled
runner = salt.runner.Runner(self.config)
if self.options.doc:
runner.print_docs()
self.exit(salt.defaults.exitcodes.EX_OK)
# Run this here so SystemExit isn't raised anywhere else when
# someone tries to use the runners via the python API
try:
if check_user(self.config['user']):
pr = activate_profile(profiling_enabled)
try:
ret = runner.run()
if isinstance(ret, dict) and 'retcode' in ret:
self.exit(ret['retcode'])
finally:
output_profile(
pr,
stats_path=self.options.profiling_path,
stop=True)
except SaltClientError as exc:
raise SystemExit(str(exc))
开发者ID:HowardMei,项目名称:saltstack,代码行数:34,代码来源:run.py
示例6: run
def run(self):
"""
Execute salt-run
"""
self.parse_args()
if self.config["verify_env"]:
verify_env(
[self.config["pki_dir"], self.config["cachedir"]],
self.config["user"],
permissive=self.config["permissive_pki_access"],
pki_dir=self.config["pki_dir"],
)
if not self.config["log_file"].startswith(("tcp://", "udp://", "file://")):
# Logfile is not using Syslog, verify
verify_files([self.config["log_file"]], self.config["user"])
# Setup file logging!
self.setup_logfile_logger()
runner = salt.runner.Runner(self.config)
if self.options.doc:
runner._print_docs()
self.exit(salt.exitcodes.EX_OK)
# Run this here so SystemExit isn't raised anywhere else when
# someone tries to use the runners via the python API
try:
if check_user(self.config["user"]):
runner.run()
except SaltClientError as exc:
raise SystemExit(str(exc))
开发者ID:wikimedia,项目名称:operations-debs-salt,代码行数:32,代码来源:__init__.py
示例7: start
def start(self):
'''
Start the actual minion.
If sub-classed, don't **ever** forget to run:
super(YourSubClass, self).start()
NOTE: Run any required code before calling `super()`.
'''
reconnect = True
while reconnect:
reconnect = False
try:
self.prepare()
if check_user(self.config['user']):
self.minion.tune_in()
except (KeyboardInterrupt, SaltSystemExit) as exc:
logger.warn('Stopping the Salt Minion')
if isinstance(exc, KeyboardInterrupt):
logger.warn('Exiting on Ctrl-c')
else:
logger.error(str(exc))
except SaltClientError as exc:
logger.error(exc)
if self.config.get('restart_on_error'):
logger.warn('** Restarting minion **')
s = randint(0, self.config.get('random_reauth_delay', 10))
logger.info('Sleeping random_reauth_delay of {0} seconds'.format(s))
time.sleep(s)
reconnect = True
finally:
self.shutdown()
开发者ID:wikimedia,项目名称:operations-debs-salt,代码行数:33,代码来源:__init__.py
示例8: call
def call(self, cleanup_protecteds):
'''
Start the actual minion as a caller minion.
cleanup_protecteds is list of yard host addresses that should not be
cleaned up this is to fix race condition when salt-caller minion starts up
If sub-classed, don't **ever** forget to run:
super(YourSubClass, self).start()
NOTE: Run any required code before calling `super()`.
'''
try:
self.prepare()
if check_user(self.config['user']):
self.minion.opts['__role'] = kinds.APPL_KIND_NAMES[kinds.applKinds.caller]
self.minion.opts['raet_cleanup_protecteds'] = cleanup_protecteds
self.minion.call_in()
except (KeyboardInterrupt, SaltSystemExit) as exc:
log.warn('Stopping the Salt Minion')
if isinstance(exc, KeyboardInterrupt):
log.warn('Exiting on Ctrl-c')
self.shutdown()
else:
log.error(str(exc))
self.shutdown(exc.code)
开发者ID:HowardMei,项目名称:saltstack,代码行数:27,代码来源:daemons.py
示例9: __process_multiprocessing_logging_queue
def __process_multiprocessing_logging_queue(opts, queue):
import salt.utils
salt.utils.appendproctitle('MultiprocessingLoggingQueue')
# Assign UID/GID of user to proc if set
from salt.utils.verify import check_user
user = opts.get('user')
if user:
check_user(user)
if salt.utils.is_windows():
# On Windows, creating a new process doesn't fork (copy the parent
# process image). Due to this, we need to setup all of our logging
# inside this process.
setup_temp_logger()
setup_console_logger(
log_level=opts.get('log_level'),
log_format=opts.get('log_fmt_console'),
date_format=opts.get('log_datefmt_console')
)
setup_logfile_logger(
opts.get('log_file'),
log_level=opts.get('log_level_logfile'),
log_format=opts.get('log_fmt_logfile'),
date_format=opts.get('log_datefmt_logfile'),
max_bytes=opts.get('log_rotate_max_bytes', 0),
backup_count=opts.get('log_rotate_backup_count', 0)
)
setup_extended_logging(opts)
while True:
try:
record = queue.get()
if record is None:
# A sentinel to stop processing the queue
break
# Just log everything, filtering will happen on the main process
# logging handlers
logger = logging.getLogger(record.name)
logger.handle(record)
except (EOFError, KeyboardInterrupt, SystemExit):
break
except Exception as exc: # pylint: disable=broad-except
logging.getLogger(__name__).warning(
'An exception occurred in the multiprocessing logging '
'queue thread: {0}'.format(exc),
exc_info_on_loglevel=logging.DEBUG
)
开发者ID:bryson,项目名称:salt,代码行数:47,代码来源:setup.py
示例10: start
def start(self):
'''
Start the actual master.
If sub-classed, don't **ever** forget to run:
super(YourSubClass, self).start()
NOTE: Run any required code before calling `super()`.
'''
super(Master, self).start()
if check_user(self.config['user']):
log.info('The salt master is starting up')
self.master.start()
开发者ID:HowardMei,项目名称:saltstack,代码行数:14,代码来源:daemons.py
示例11: start
def start(self):
"""
Start the actual master.
If sub-classed, don't **ever** forget to run:
super(YourSubClass, self).start()
NOTE: Run any required code before calling `super()`.
"""
super(SaltAPI, self).start()
if check_user(self.config["user"]):
log.info("The salt-api is starting up")
self.api.run()
开发者ID:bryson,项目名称:salt,代码行数:14,代码来源:api.py
示例12: start
def start(self):
'''
Start the actual syndic.
If sub-classed, don't **ever** forget to run:
super(YourSubClass, self).start()
NOTE: Run any required code before calling `super()`.
'''
self.prepare()
if check_user(self.config['user']):
try:
self.syndic.tune_in()
except KeyboardInterrupt:
logger.warn('Stopping the Salt Syndic Minion')
self.shutdown()
开发者ID:1mentat,项目名称:salt,代码行数:17,代码来源:__init__.py
示例13: run
def run(self):
'''
Execute salt-key
'''
import salt.key
self.parse_args()
if self.config['verify_env']:
verify_env_dirs = []
if not self.config['gen_keys']:
if self.config['transport'] == 'raet':
verify_env_dirs.extend([
self.config['pki_dir'],
os.path.join(self.config['pki_dir'], 'accepted'),
os.path.join(self.config['pki_dir'], 'pending'),
os.path.join(self.config['pki_dir'], 'rejected'),
])
elif self.config['transport'] == 'zeromq':
verify_env_dirs.extend([
self.config['pki_dir'],
os.path.join(self.config['pki_dir'], 'minions'),
os.path.join(self.config['pki_dir'], 'minions_pre'),
os.path.join(self.config['pki_dir'], 'minions_rejected'),
])
verify_env(
verify_env_dirs,
self.config['user'],
permissive=self.config['permissive_pki_access'],
pki_dir=self.config['pki_dir'],
)
if not self.config['log_file'].startswith(('tcp://',
'udp://',
'file://')):
# Logfile is not using Syslog, verify
verify_files(
[self.config['key_logfile']],
self.config['user']
)
self.setup_logfile_logger()
key = salt.key.KeyCLI(self.config)
if check_user(self.config['user']):
key.run()
开发者ID:qzchenwl,项目名称:saltstack-verify,代码行数:46,代码来源:key.py
示例14: start
def start(self):
'''
Run the sequence to start a salt master server
'''
self.parse_args()
try:
if self.config['verify_env']:
verify_env([
self.config['pki_dir'],
os.path.join(self.config['pki_dir'], 'minions'),
os.path.join(self.config['pki_dir'], 'minions_pre'),
os.path.join(self.config['pki_dir'], 'minions_rejected'),
self.config['cachedir'],
os.path.join(self.config['cachedir'], 'jobs'),
os.path.join(self.config['cachedir'], 'proc'),
os.path.dirname(self.config['log_file']),
self.config['sock_dir'],
self.config['token_dir'],
],
self.config['user'],
permissive=self.config['permissive_pki_access'],
pki_dir=self.config['pki_dir'],
)
except OSError as err:
sys.exit(err.errno)
self.setup_logfile_logger()
logging.getLogger(__name__).warn('Setting up the Salt Master')
# Late import so logging works correctly
if not verify_socket(self.config['interface'],
self.config['publish_port'],
self.config['ret_port']):
self.exit(4, 'The ports are not available to bind\n')
migrations.migrate_paths(self.config)
import salt.master
master = salt.master.Master(self.config)
self.daemonize_if_required()
self.set_pidfile()
if check_user(self.config['user']):
try:
master.start()
except salt.master.MasterExit:
sys.exit()
开发者ID:gspradeep,项目名称:salt,代码行数:45,代码来源:__init__.py
示例15: run
def run(self):
'''
Execute salt-key
'''
import salt.key
self.parse_args()
multi = False
if self.config.get('zmq_behavior') and self.config.get('transport') == 'raet':
multi = True
self.setup_logfile_logger()
if multi:
key = salt.key.MultiKeyCLI(self.config)
else:
key = salt.key.KeyCLI(self.config)
if check_user(self.config['user']):
key.run()
开发者ID:DaveQB,项目名称:salt,代码行数:18,代码来源:key.py
示例16: test_no_user
def test_no_user(self):
# Catch sys.stderr here since no logging is configured and
# check_user WILL write to sys.stderr
class FakeWriter(object):
def __init__(self):
self.output = ""
def write(self, data):
self.output += data
stderr = sys.stderr
writer = FakeWriter()
sys.stderr = writer
# Now run the test
self.assertFalse(check_user('nouser'))
# Restore sys.stderr
sys.stderr = stderr
if writer.output != 'CRITICAL: User not found: "nouser"\n':
# If there's a different error catch, write it to sys.stderr
sys.stderr.write(writer.output)
开发者ID:herlo,项目名称:salt,代码行数:19,代码来源:verify_test.py
示例17: start
def start(self):
'''
Execute this method to start up a syndic.
'''
self.parse_args()
try:
if self.config['verify_env']:
verify_env([
self.config['pki_dir'],
self.config['cachedir'],
self.config['sock_dir'],
self.config['extension_modules'],
os.path.dirname(self.config['log_file']),
],
self.config['user'],
permissive=self.config['permissive_pki_access'],
pki_dir=self.config['pki_dir'],
)
except OSError as err:
sys.exit(err.errno)
self.setup_logfile_logger()
log = logging.getLogger(__name__)
log.warn(
'Setting up the Salt Syndic Minion "{0}"'.format(
self.config['id']
)
)
# Late import so logging works correctly
import salt.minion
self.daemonize_if_required()
self.set_pidfile()
if check_user(self.config['user']):
try:
syndic = salt.minion.Syndic(self.config)
syndic.tune_in()
except KeyboardInterrupt:
log.warn('Stopping the Salt Syndic Minion')
raise SystemExit('\nExiting on Ctrl-c')
开发者ID:DamianZaremba,项目名称:salt,代码行数:41,代码来源:__init__.py
示例18: run
def run(self):
'''
Execute salt-run
'''
import salt.runner
self.parse_args()
if self.config['verify_env']:
verify_env([
self.config['pki_dir'],
self.config['cachedir'],
],
self.config['user'],
permissive=self.config['permissive_pki_access'],
pki_dir=self.config['pki_dir'],
)
if not self.config['log_file'].startswith(('tcp://',
'udp://',
'file://')):
# Logfile is not using Syslog, verify
verify_files(
[self.config['log_file']],
self.config['user']
)
# Setup file logging!
self.setup_logfile_logger()
runner = salt.runner.Runner(self.config)
if self.options.doc:
runner.print_docs()
self.exit(os.EX_OK)
# Run this here so SystemExit isn't raised anywhere else when
# someone tries to use the runners via the python API
try:
if check_user(self.config['user']):
runner.run()
except SaltClientError as exc:
raise SystemExit(str(exc))
开发者ID:qzchenwl,项目名称:saltstack-verify,代码行数:40,代码来源:run.py
示例19: run
def run(self):
'''
Execute the salt-cloud command line
'''
if HAS_LIBCLOUD is False:
self.error('salt-cloud requires >= libcloud 0.11.4')
libcloud_version()
# Parse shell arguments
self.parse_args()
salt_master_user = self.config.get('user', getpass.getuser())
if salt_master_user is not None and not check_user(salt_master_user):
self.error(
'salt-cloud needs to run as the same user as salt-master, '
'{0!r}, but was unable to switch credentials. Please run '
'salt-cloud as root or as {0!r}'.format(salt_master_user)
)
try:
if self.config['verify_env']:
verify_env(
[os.path.dirname(self.config['conf_file'])],
salt_master_user
)
logfile = self.config['log_file']
if logfile is not None and not logfile.startswith('tcp://') \
and not logfile.startswith('udp://') \
and not logfile.startswith('file://'):
# Logfile is not using Syslog, verify
verify_files([logfile], salt_master_user)
except (IOError, OSError) as err:
log.error('Error while verifying the environment: {0}'.format(err))
sys.exit(err.errno)
# Setup log file logging
self.setup_logfile_logger()
if self.options.update_bootstrap:
import urllib2
url = 'http://bootstrap.saltstack.org'
req = urllib2.urlopen(url)
if req.getcode() != 200:
self.error(
'Failed to download the latest stable version of the '
'bootstrap-salt.sh script from {0}. HTTP error: '
'{1}'.format(
url, req.getcode()
)
)
for entry in self.config.get('deploy_scripts_search_path'):
deploy_path = os.path.join(entry, 'bootstrap-salt.sh')
try:
print(
'Updating bootstrap-salt.sh.'
'\n\tSource: {0}'
'\n\tDestination: {1}'.format(
url,
deploy_path
)
)
with salt.utils.fopen(deploy_path, 'w') as fp_:
fp_.write(req.read())
# We were able to update, no need to continue trying to
# write up the search path
self.exit(0)
except (OSError, IOError), err:
log.debug(
'Failed to write the updated script: {0}'.format(err)
)
continue
self.error('Failed to update the bootstrap script')
开发者ID:1mentat,项目名称:salt,代码行数:74,代码来源:cli.py
示例20: run
def run(self):
'''
Execute the salt-cloud command line
'''
# Parse shell arguments
self.parse_args()
salt_master_user = self.config.get('user')
if salt_master_user is None:
salt_master_user = salt.utils.get_user()
if not check_user(salt_master_user):
self.error(
'If salt-cloud is running on a master machine, salt-cloud '
'needs to run as the same user as the salt-master, \'{0}\'. '
'If salt-cloud is not running on a salt-master, the '
'appropriate write permissions must be granted to \'{1}\'. '
'Please run salt-cloud as root, \'{0}\', or change '
'permissions for \'{1}\'.'.format(
salt_master_user,
syspaths.CONFIG_DIR
)
)
try:
if self.config['verify_env']:
verify_env(
[os.path.dirname(self.config['conf_file'])],
salt_master_user
)
logfile = self.config['log_file']
if logfile is not None and not logfile.startswith('tcp://') \
and not logfile.startswith('udp://') \
and not logfile.startswith('file://'):
# Logfile is not using Syslog, verify
verify_files([logfile], salt_master_user)
except (IOError, OSError) as err:
log.error('Error while verifying the environment: {0}'.format(err))
sys.exit(err.errno)
# Setup log file logging
self.setup_logfile_logger()
verify_log(self.config)
if self.options.update_bootstrap:
ret = salt.utils.cloud.update_bootstrap(self.config)
salt.output.display_output(ret,
self.options.output,
opts=self.config)
self.exit(salt.defaults.exitcodes.EX_OK)
log.info('salt-cloud starting')
try:
mapper = salt.cloud.Map(self.config)
except SaltCloudSystemExit as exc:
self.handle_exception(exc.args, exc)
except SaltCloudException as exc:
msg = 'There was an error generating the mapper.'
self.handle_exception(msg, exc)
names = self.config.get('names', None)
if names is not None:
filtered_rendered_map = {}
for map_profile in mapper.rendered_map:
filtered_map_profile = {}
for name in mapper.rendered_map[map_profile]:
if name in names:
filtered_map_profile[name] = mapper.rendered_map[map_profile][name]
if filtered_map_profile:
filtered_rendered_map[map_profile] = filtered_map_profile
mapper.rendered_map = filtered_rendered_map
ret = {}
if self.selected_query_option is not None:
if self.selected_query_option == 'list_providers':
try:
ret = mapper.provider_list()
except (SaltCloudException, Exception) as exc:
msg = 'There was an error listing providers: {0}'
self.handle_exception(msg, exc)
elif self.selected_query_option == 'list_profiles':
provider = self.options.list_profiles
try:
ret = mapper.profile_list(provider)
except(SaltCloudException, Exception) as exc:
msg = 'There was an error listing profiles: {0}'
self.handle_exception(msg, exc)
elif self.config.get('map', None):
log.info(
'Applying map from \'{0}\'.'.format(self.config['map'])
)
try:
ret = mapper.interpolated_map(
query=self.selected_query_option
)
except (SaltCloudException, Exception) as exc:
msg = 'There was an error with a custom map: {0}'
#.........这里部分代码省略.........
开发者ID:HowardMei,项目名称:saltstack,代码行数:101,代码来源:cli.py
注:本文中的salt.utils.verify.check_user函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论