本文整理汇总了Python中salt.ext.six.itervalues函数的典型用法代码示例。如果您正苦于以下问题:Python itervalues函数的具体用法?Python itervalues怎么用?Python itervalues使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了itervalues函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execution
def execution():
'''
Collect all the sys.doc output from each minion and return the aggregate
CLI Example:
.. code-block:: bash
salt-run doc.execution
'''
client = salt.client.get_local_client(__opts__['conf_file'])
docs = {}
try:
for ret in client.cmd_iter('*', 'sys.doc', timeout=__opts__['timeout']):
for v in six.itervalues(ret):
docs.update(v)
except SaltClientError as exc:
print exc
return []
i = itertools.chain.from_iterable([i.items() for i in six.itervalues(docs)])
ret = dict(list(i))
return ret
示例2: get_instance
def get_instance(name, provider=None):
'''
Return details on an instance.
Similar to the cloud action show_instance
but returns only the instance details.
CLI Example:
.. code-block:: bash
salt '*' cloud.get_instance myinstance
SLS Example:
.. code-block:: bash
{{ salt['cloud.get_instance']('myinstance')['mac_address'] }}
'''
data = action(fun='show_instance', names=[name], provider=provider)
info = salt.utils.simple_types_filter(data)
try:
# get the first: [alias][driver][vm_name]
info = next(six.itervalues(next(six.itervalues(next(six.itervalues(info))))))
except AttributeError:
return None
return info
示例3: ip_addrs6
def ip_addrs6(interface=None, include_loopback=False, interface_data=None):
'''
Returns a list of IPv6 addresses assigned to the host. ::1 is ignored,
unless 'include_loopback=True' is indicated. If 'interface' is provided,
then only IP addresses from that interface will be returned.
'''
ret = set()
ifaces = interface_data \
if isinstance(interface_data, dict) \
else interfaces()
if interface is None:
target_ifaces = ifaces
else:
target_ifaces = dict([(k, v) for k, v in six.iteritems(ifaces)
if k == interface])
if not target_ifaces:
log.error('Interface {0} not found.'.format(interface))
for ipv6_info in six.itervalues(target_ifaces):
for ipv6 in ipv6_info.get('inet6', []):
if include_loopback or ipv6['address'] != '::1':
ret.add(ipv6['address'])
for secondary in ipv6_info.get('secondary', []):
addr = secondary.get('address')
if addr and secondary.get('type') == 'inet6':
if include_loopback or addr != '::1':
ret.add(addr)
return sorted(list(ret))
示例4: ip_addrs
def ip_addrs(interface=None, include_loopback=False, interface_data=None):
'''
Returns a list of IPv4 addresses assigned to the host. 127.0.0.1 is
ignored, unless 'include_loopback=True' is indicated. If 'interface' is
provided, then only IP addresses from that interface will be returned.
'''
ret = set()
ifaces = interface_data \
if isinstance(interface_data, dict) \
else interfaces()
if interface is None:
target_ifaces = ifaces
else:
target_ifaces = dict([(k, v) for k, v in six.iteritems(ifaces)
if k == interface])
if not target_ifaces:
log.error('Interface {0} not found.'.format(interface))
for ipv4_info in six.itervalues(target_ifaces):
for ipv4 in ipv4_info.get('inet', []):
loopback = in_subnet('127.0.0.0/8', [ipv4.get('address')]) or ipv4.get('label') == 'lo'
if not loopback or include_loopback:
ret.add(ipv4['address'])
for secondary in ipv4_info.get('secondary', []):
addr = secondary.get('address')
if addr and secondary.get('type') == 'inet':
if include_loopback or (not include_loopback and not in_subnet('127.0.0.0/8', [addr])):
ret.add(addr)
return sorted(list(ret))
示例5: __clean_tmp
def __clean_tmp(sfn):
if sfn.startswith(tempfile.gettempdir()):
all_roots = itertools.chain.from_iterable(
six.itervalues(__opts__['file_roots']))
in_roots = any(sfn.startswith(root) for root in all_roots)
if os.path.exists(sfn) and not in_roots:
os.remove(sfn)
示例6: _alarms_present
def _alarms_present(name, alarms, alarms_from_pillar, region, key, keyid, profile):
'''helper method for present. ensure that cloudwatch_alarms are set'''
# load data from alarms_from_pillar
tmp = __salt__['config.option'](alarms_from_pillar, {})
# merge with data from alarms
if alarms:
tmp = dictupdate.update(tmp, alarms)
# set alarms, using boto_cloudwatch_alarm.present
merged_return_value = {'name': name, 'result': True, 'comment': '', 'changes': {}}
for _, info in six.iteritems(tmp):
# add asg to name and description
info['name'] = name + ' ' + info['name']
info['attributes']['description'] = name + ' ' + info['attributes']['description']
# add dimension attribute
info['attributes']['dimensions'] = {'AutoScalingGroupName': [name]}
# set alarm
kwargs = {
'name': info['name'],
'attributes': info['attributes'],
'region': region,
'key': key,
'keyid': keyid,
'profile': profile,
}
ret = __salt__['state.single']('boto_cloudwatch_alarm.present', **kwargs)
results = next(six.itervalues(ret))
if not results['result']:
merged_return_value['result'] = False
if results.get('changes', {}) != {}:
merged_return_value['changes'][info['name']] = results['changes']
if 'comment' in results:
merged_return_value['comment'] += results['comment']
return merged_return_value
示例7: kill_children
def kill_children(self, *args):
'''
Kill all of the children
'''
# check that this is the correct process, children inherit this
# handler, if we are in a child lets just run the original handler
if os.getpid() != self._pid:
if callable(self._sigterm_handler):
return self._sigterm_handler(*args)
elif self._sigterm_handler is not None:
return signal.default_int_handler(signal.SIGTERM)(*args)
else:
return
for p_map in six.itervalues(self._process_map):
p_map['Process'].terminate()
end_time = time.time() + self.wait_for_kill # when to die
while self._process_map and time.time() < end_time:
for pid, p_map in self._process_map.items():
p_map['Process'].join(0)
# This is a race condition if a signal was passed to all children
try:
del self._process_map[pid]
except KeyError:
pass
# if anyone is done after
for pid in self._process_map:
try:
os.kill(signal.SIGKILL, pid)
# in case the process has since decided to die, os.kill returns OSError
except OSError:
pass
示例8: file_list
def file_list(load):
'''
Return a list of all files on the file server in a specified environment
'''
if 'env' in load:
salt.utils.warn_until(
'Oxygen',
'Parameter \'env\' has been detected in the argument list. This '
'parameter is no longer used and has been replaced by \'saltenv\' '
'as of Salt 2016.11.0. This warning will be removed in Salt Oxygen.'
)
load.pop('env')
ret = []
if 'saltenv' not in load:
return ret
saltenv = load['saltenv']
metadata = _init()
if not metadata or saltenv not in metadata:
return ret
for buckets in six.itervalues(_find_files(metadata[saltenv])):
files = [f for f in buckets if not fs.is_file_ignored(__opts__, f)]
ret += _trim_env_off_path(files, saltenv)
return ret
示例9: latest_version
def latest_version(*names, **kwargs):
'''
Return the latest version of the named package available for upgrade or
installation
Currently chooses stable versions, falling back to devel if that does not
exist.
CLI Example:
.. code-block:: bash
salt '*' pkg.latest_version <package name>
salt '*' pkg.latest_version <package1> <package2> <package3>
'''
refresh = salt.utils.is_true(kwargs.pop('refresh', True))
if refresh:
refresh_db()
def get_version(pkg_info):
# Perhaps this will need an option to pick devel by default
return pkg_info['versions']['stable'] or pkg_info['versions']['devel']
versions_dict = dict((key, get_version(val)) for key, val in six.iteritems(_info(*names)))
if len(names) == 1:
return next(six.itervalues(versions_dict))
else:
return versions_dict
示例10: owner
def owner(*paths):
'''
Return the name of the package that owns the file. Multiple file paths can
be passed. Like :mod:`pkg.version <salt.modules.opkg.version`, if a single
path is passed, a string will be returned, and if multiple paths are passed,
a dictionary of file/package name pairs will be returned.
If the file is not owned by a package, or is not present on the minion,
then an empty string will be returned for that path.
CLI Example:
salt '*' pkg.owner /usr/bin/apachectl
salt '*' pkg.owner /usr/bin/apachectl /usr/bin/basename
'''
if not paths:
return ''
ret = {}
cmd_search = ['opkg', 'search']
for path in paths:
cmd = cmd_search[:]
cmd.append(path)
output = __salt__['cmd.run_stdout'](cmd,
output_loglevel='trace',
python_shell=False)
if output:
ret[path] = output.split(' - ')[0].strip()
else:
ret[path] = ''
if len(ret) == 1:
return six.itervalues(ret)
return ret
示例11: _get_service
def _get_service(name):
'''
Get information about a service. If the service is not found, raise an
error
:param str name: Service label, file name, or full path
:return: The service information for the service, otherwise an Error
:rtype: dict
'''
services = __salt__['service.available_services']()
name = name.lower()
if name in services:
# Match on label
return services[name]
for service in six.itervalues(services):
if service['file_path'].lower() == name:
# Match on full path
return service
basename, ext = os.path.splitext(service['file_name'])
if basename.lower() == name:
# Match on basename
return service
# Could not find service
raise CommandExecutionError('Service not found: {0}'.format(name))
示例12: _subnets
def _subnets(proto='inet', interfaces_=None):
'''
Returns a list of subnets to which the host belongs
'''
if interfaces_ is None:
ifaces = interfaces()
elif isinstance(interfaces_, list):
ifaces = {}
for key, value in six.iteritems(interfaces()):
if key in interfaces_:
ifaces[key] = value
else:
ifaces = {interfaces_: interfaces().get(interfaces_, {})}
ret = set()
if proto == 'inet':
subnet = 'netmask'
elif proto == 'inet6':
subnet = 'prefixlen'
else:
log.error('Invalid proto {0} calling subnets()'.format(proto))
return
for ip_info in six.itervalues(ifaces):
addrs = ip_info.get(proto, [])
addrs.extend([addr for addr in ip_info.get('secondary', []) if addr.get('type') == proto])
for intf in addrs:
intf = ipaddress.ip_interface('{0}/{1}'.format(intf['address'], intf[subnet]))
if not intf.is_loopback:
ret.add(intf.network)
return [str(net) for net in sorted(ret)]
示例13: version
def version(*names, **kwargs):
'''
Common interface for obtaining the version of installed packages.
CLI Example:
.. code-block:: bash
salt '*' pkg_resource.version vim
salt '*' pkg_resource.version foo bar baz
salt '*' pkg_resource.version 'python*'
'''
ret = {}
versions_as_list = \
salt.utils.is_true(kwargs.pop('versions_as_list', False))
pkg_glob = False
if len(names) != 0:
pkgs = __salt__['pkg.list_pkgs'](versions_as_list=True, **kwargs)
for name in names:
if '*' in name:
pkg_glob = True
for match in fnmatch.filter(pkgs, name):
ret[match] = pkgs.get(match, [])
else:
ret[name] = pkgs.get(name, [])
if not versions_as_list:
__salt__['pkg_resource.stringify'](ret)
# Return a string if no globbing is used, and there is one item in the
# return dict
if len(ret) == 1 and not pkg_glob:
try:
return next(six.itervalues(ret))
except StopIteration:
return ''
return ret
示例14: file_list
def file_list(load):
'''
Return a list of all files on the file server in a specified environment
'''
if 'env' in load:
salt.utils.warn_until(
'Boron',
'Passing a salt environment should be done using \'saltenv\' '
'not \'env\'. This functionality will be removed in Salt Boron.'
)
load['saltenv'] = load.pop('env')
ret = []
if 'saltenv' not in load:
return ret
saltenv = load['saltenv']
metadata = _init()
if not metadata or saltenv not in metadata:
return ret
for buckets in six.itervalues(_find_files(metadata[saltenv])):
files = [f for f in buckets if not fs.is_file_ignored(__opts__, f)]
ret += _trim_env_off_path(files, saltenv)
return ret
示例15: dir_list
def dir_list(load):
'''
Return a list of all directories on the master
'''
if 'env' in load:
salt.utils.warn_until(
'Boron',
'Passing a salt environment should be done using \'saltenv\' '
'not \'env\'. This functionality will be removed in Salt Boron.'
)
load['saltenv'] = load.pop('env')
ret = []
if 'saltenv' not in load:
return ret
saltenv = load['saltenv']
metadata = _init()
if not metadata or saltenv not in metadata:
return ret
# grab all the dirs from the buckets cache file
for dirs in six.itervalues(_find_dirs(metadata[saltenv])):
# trim env and trailing slash
dirs = _trim_env_off_path(dirs, saltenv, trim_slash=True)
# remove empty string left by the base env dir in single bucket mode
ret += [_f for _f in dirs if _f]
return ret