本文整理汇总了Python中salt.log.debug函数的典型用法代码示例。如果您正苦于以下问题:Python debug函数的具体用法?Python debug怎么用?Python debug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了debug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: grain_match
def grain_match(self, tgt):
'''
Reads in the grains glob match
'''
log.debug('grains target: {0}'.format(tgt))
comps = tgt.rsplit(':', 1)
if len(comps) != 2:
log.error('Got insufficient arguments for grains match '
'statement from master')
return False
match = self._traverse_dict(self.opts['grains'], comps[0])
if match == {}:
log.error('Targeted grain "{0}" not found'.format(comps[0]))
return False
if isinstance(match, dict):
log.error('Targeted grain "{0}" must correspond to a list, '
'string, or numeric value'.format(comps[0]))
return False
if isinstance(match, list):
# We are matching a single component to a single list member
for member in match:
if fnmatch.fnmatch(str(member).lower(), comps[1].lower()):
return True
return False
return bool(fnmatch.fnmatch(str(match).lower(), comps[1].lower()))
示例2: _handle_aes
def _handle_aes(self, load):
'''
Takes the aes encrypted load, decrypts is and runs the encapsulated
instructions
'''
try:
data = self.crypticle.loads(load)
except AuthenticationError:
self.authenticate()
data = self.crypticle.loads(load)
# Verify that the publication is valid
if 'tgt' not in data or 'jid' not in data or 'fun' not in data \
or 'arg' not in data:
return
# Verify that the publication applies to this minion
if 'tgt_type' in data:
if not getattr(self.matcher,
'{0}_match'.format(data['tgt_type']))(data['tgt']):
return
else:
if not self.matcher.glob_match(data['tgt']):
return
# If the minion does not have the function, don't execute,
# this prevents minions that could not load a minion module
# from returning a predictable exception
#if data['fun'] not in self.functions:
# return
if 'user' in data:
log.info(('User {0[user]} Executing command {0[fun]} with jid '
'{0[jid]}'.format(data)))
else:
log.info(('Executing command {0[fun]} with jid {0[jid]}'
.format(data)))
log.debug('Command details {0}'.format(data))
self._handle_decoded_payload(data)
示例3: load_config
def load_config(opts, path, env_var):
'''
Attempts to update ``opts`` dict by parsing either the file described by
``path`` or the environment variable described by ``env_var`` as YAML.
'''
if not path or not os.path.isfile(path):
path = os.environ.get(env_var, path)
# If the configuration file is missing, attempt to copy the template,
# after removing the first header line.
if not os.path.isfile(path):
template = '{0}.template'.format(path)
if os.path.isfile(template):
with open(path, 'w') as out:
with open(template, 'r') as f:
f.readline() # skip first line
out.write(f.read())
if os.path.isfile(path):
try:
opts.update(_read_conf_file(path))
opts['conf_file'] = path
except Exception as e:
import salt.log
msg = 'Error parsing configuration file: {0} - {1}'
if salt.log.is_console_configured():
log.warn(msg.format(path, e))
else:
print(msg.format(path, e))
else:
log.debug('Missing configuration file: {0}'.format(path))
示例4: _dism
def _dism(action,
image=None):
'''
Run a DISM servicing command on the given image.
'''
command='dism {0} {1}'.format(
'/Image:{0}'.format(image) if image else '/Online',
action
)
ret = {'action': action,
'image': image,
'result': True,
'message': ''}
output = __salt__['cmd.run'](command, ignore_retcode=True)
if not re.search('The operation completed successfully.', output):
ret['result'] = False
ret['message'] = re.search(
'(Error: \d+\r?\n\r?\n([^\r\n]+\r?\n)+\r?\nThe DISM log file can be found at [^\r\n]\r?\n)',
output,
re.MULTILINE
).group(1)
log.exception('DISM command \'{0}\' on image {1} failed: {2}'.format(action, image, ret['message']))
else:
ret['message'] = output
log.debug('DISM command \'{0}\' on image {1} completed with the following output: {2}'.format(action, image, output))
return ret
示例5: _get_cached_minion_data
def _get_cached_minion_data(self, *minion_ids):
# Return two separate dicts of cached grains and pillar data of the minions
grains = dict([(minion_id, {}) for minion_id in minion_ids])
pillars = grains.copy()
if not self.opts.get('minion_data_cache', False):
log.debug('Skipping cached data because minion_data_cache is not enabled.')
return grains, pillars
serial = salt.payload.Serial(self.opts)
mdir = os.path.join(self.opts['cachedir'], 'minions')
# salt.utils.verify.valid_id has changed in git development to require opts arg
valid_id_args = inspect.getargspec(salt.utils.verify.valid_id).args
log.debug('salt.utils.verify.valid_id accepts args: {0}'.format(valid_id_args))
try:
for minion_id in minion_ids:
if 'opts' in valid_id_args:
if not salt.utils.verify.valid_id(self.opts, minion_id):
continue
else:
if not salt.utils.verify.valid_id(self.opts, minion_id):
continue
path = os.path.join(mdir, minion_id, 'data.p')
if os.path.isfile(path):
with salt.utils.fopen(path) as fp_:
mdata = serial.loads(fp_.read())
if mdata.get('grains', False):
grains[minion_id] = mdata['grains']
if mdata.get('pillar', False):
pillars[minion_id] = mdata['pillar']
except (OSError, IOError):
return grains, pillars
return grains, pillars
示例6: ext_pillar
def ext_pillar(minion_id, # pylint: disable=W0613
pillar, # pylint: disable=W0613
config_file):
'''
Execute LDAP searches and return the aggregated data
'''
if os.path.isfile(config_file):
try:
#open(config_file, 'r') as raw_config:
config = _render_template(config_file) or {}
opts = yaml.safe_load(config) or {}
opts['conf_file'] = config_file
except Exception as err:
import salt.log
msg = 'Error parsing configuration file: {0} - {1}'
if salt.log.is_console_configured():
log.warn(msg.format(config_file, err))
else:
print(msg.format(config_file, err))
else:
log.debug('Missing configuration file: {0}'.format(config_file))
data = {}
for source in opts['search_order']:
config = opts[source]
result = _do_search(config)
print('source {0} got result {1}'.format(source, result))
if result:
data = _result_to_dict(data, result, config)
return data
示例7: __init__
def __init__(self, opts, log_queue=None):
'''
starts the timer and inits the cache itself
'''
super(ConnectedCache, self).__init__(log_queue=log_queue)
log.debug('ConCache initializing...')
# the possible settings for the cache
self.opts = opts
# the actual cached minion ids
self.minions = []
self.cache_sock = os.path.join(self.opts['sock_dir'], 'con_cache.ipc')
self.update_sock = os.path.join(self.opts['sock_dir'], 'con_upd.ipc')
self.upd_t_sock = os.path.join(self.opts['sock_dir'], 'con_timer.ipc')
self.cleanup()
# the timer provides 1-second intervals to the loop in run()
# to make the cache system most responsive, we do not use a loop-
# delay which makes it hard to get 1-second intervals without a timer
self.timer_stop = Event()
self.timer = CacheTimer(self.opts, self.timer_stop)
self.timer.start()
self.running = True
示例8: stop
def stop(self,
signal,
frame):
'''
we override stop() to brake our main loop
and have a pretty log message
'''
log.info("received signal {0}".format(signal))
# if we have running workers, run through all and join() the ones
# that have finished. if we still have running workers after that,
# wait 5 secs for the rest and then exit. Maybe we should improv
# this a litte bit more
if( len(self.running_workers) > 0 ):
clean_workers = []
for count in range(0, 2):
for worker in self.running_workers:
if worker.isAlive():
clean_workers.append(worker)
else:
worker.join()
log.debug("joined worker #{0}".format(worker.getName()))
if( len(clean_workers) > 0 ):
log.info("waiting 5secs for remaining workers..")
time.sleep(5)
else:
break
log.info("salt-eventsd has shut down")
# leave the cleanup to the supers stop
super(SaltEventsDaemon, self).stop(signal, frame)
示例9: start
def start(self):
log.debug("starting monitor with {} task{}".format(len(self.tasks), "" if len(self.tasks) == 1 else "s"))
if self.tasks:
for task in self.tasks:
threading.Thread(target=task.run).start()
else:
log.error("no monitor tasks to run")
示例10: _get_cached_minion_data
def _get_cached_minion_data(self, *minion_ids):
# Return two separate dicts of cached grains and pillar data of the
# minions
grains = dict([(minion_id, {}) for minion_id in minion_ids])
pillars = grains.copy()
if not self.opts.get('minion_data_cache', False):
log.debug('Skipping cached data because minion_data_cache is not '
'enabled.')
return grains, pillars
mdir = os.path.join(self.opts['cachedir'], 'minions')
try:
for minion_id in minion_ids:
if not salt.utils.verify.valid_id(self.opts, minion_id):
continue
path = os.path.join(mdir, minion_id, 'data.p')
if os.path.isfile(path):
with salt.utils.fopen(path, 'rb') as fp_:
mdata = self.serial.loads(fp_.read())
if mdata.get('grains', False):
grains[minion_id] = mdata['grains']
if mdata.get('pillar', False):
pillars[minion_id] = mdata['pillar']
except (OSError, IOError):
return grains, pillars
return grains, pillars
示例11: get_minion_grains
def get_minion_grains(self):
'''
Get grains data for the targeted minions, either by fetching the
cached minion data on the master, or by fetching the grains
directly on the minion.
By default, this function tries hard to get the pillar data:
- Try to get the cached minion grains if the master
has minion_data_cache: True
- If the grains data for the minion is cached, use it.
- If there is no cached grains data for a minion,
then try to get the minion grains directly from the minion.
'''
minion_grains = {}
minion_ids = self._tgt_to_list()
if any(arg for arg in [self.use_cached_grains, self.grains_fallback]):
log.debug('Getting cached minion data.')
cached_minion_grains, cached_minion_pillars = self._get_cached_minion_data(*minion_ids)
else:
cached_minion_grains = {}
log.debug('Getting minion grain data for: {0}'.format(minion_ids))
minion_grains = self._get_minion_grains(
*minion_ids,
cached_grains=cached_minion_grains)
return minion_grains
示例12: __init__
def __init__(self,
tgt='',
expr_form='glob',
env=None,
use_cached_grains=True,
use_cached_pillar=True,
grains_fallback=True,
pillar_fallback=True,
opts=None):
log.debug('New instance of {0} created.'.format(
self.__class__.__name__))
if opts is None:
log.error('{0}: Missing master opts init arg.'.format(
self.__class__.__name__))
raise SaltException('{0}: Missing master opts init arg.'.format(
self.__class__.__name__))
else:
self.opts = opts
self.tgt = tgt
self.expr_form = expr_form
self.env = env
self.use_cached_grains = use_cached_grains
self.use_cached_pillar = use_cached_pillar
self.grains_fallback = grains_fallback
self.pillar_fallback = pillar_fallback
log.debug('Init settings: tgt: \"{0}\", expr_form: \"{1}\", env: \"{2}\", use_cached_grains: {3}, use_cached_pillar: {4}, grains_fallback: {5}, pillar_fallback: {6}'.format(tgt, expr_form, env, use_cached_grains, use_cached_pillar, grains_fallback, pillar_fallback))
示例13: __init__
def __init__(self, parser):
self.parser = parser
log.debug("TODO: load more manager here")
self.manager = LibvirtManager()
self.image = ImageService()
self.flavor = FlavorService()
示例14: immutable_encoder
def immutable_encoder(obj):
log.debug('IMMUTABLE OBJ: {0}'.format(obj))
if isinstance(obj, immutabletypes.ImmutableDict):
return dict(obj)
if isinstance(obj, immutabletypes.ImmutableList):
return list(obj)
if isinstance(obj, immutabletypes.ImmutableSet):
return set(obj)
示例15: get_cached_mine_data
def get_cached_mine_data(self):
'''
Get cached mine data for the targeted minions.
'''
mine_data = {}
minion_ids = self._tgt_to_list()
log.debug('Getting cached mine data for: {0}'.format(minion_ids))
mine_data = self._get_cached_mine_data(*minion_ids)
return mine_data