本文整理汇总了Python中salt.exceptions.CommandExecutionError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.CommandExecutionError方法的具体用法?Python exceptions.CommandExecutionError怎么用?Python exceptions.CommandExecutionError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类salt.exceptions
的用法示例。
在下文中一共展示了exceptions.CommandExecutionError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_top_data
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import CommandExecutionError [as 别名]
def _get_top_data(topfile):
'''
Helper method to retrieve and parse the nova topfile
'''
topfile = os.path.join(_hubble_dir()[1], topfile)
try:
with open(topfile) as handle:
topdata = yaml.safe_load(handle)
except Exception as e:
raise CommandExecutionError('Could not load topfile: {0}'.format(e))
if not isinstance(topdata, dict) or 'nova' not in topdata or \
not(isinstance(topdata['nova'], dict)):
raise CommandExecutionError('Nova topfile not formatted correctly')
topdata = topdata['nova']
ret = []
for match, data in topdata.iteritems():
if __salt__['match.compound'](match):
ret.extend(data)
return ret
示例2: get_top_data
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import CommandExecutionError [as 别名]
def get_top_data(topfile):
topfile = __salt__['cp.cache_file'](topfile)
try:
with open(topfile) as handle:
topdata = yaml.safe_load(handle)
except Exception as e:
raise CommandExecutionError('Could not load topfile: {0}'.format(e))
if not isinstance(topdata, dict) or 'nebula' not in topdata or \
not(isinstance(topdata['nebula'], dict)):
raise CommandExecutionError('Nebula topfile not formatted correctly')
topdata = topdata['nebula']
ret = []
for match, data in topdata.iteritems():
if __salt__['match.compound'](match):
ret.extend(data)
return ret
示例3: get_passwd_raw
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import CommandExecutionError [as 别名]
def get_passwd_raw():
'''
Return the raw content of the file /etc/passwd
CLI Example:
.. code-block:: bash
salt '*' account.get_passwd_raw
'''
file_user = '/etc/passwd'
try:
with salt.utils.fopen(file_user, 'r') as fp_:
content = [line for line in fp_]
except:
raise CommandExecutionError(
'An error has occurred while reading {0}'.format(file_user)
)
return content
示例4: cluster_local_node_status
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import CommandExecutionError [as 别名]
def cluster_local_node_status():
'''
Return the status of the local cluster member.
CLI Example:
.. code-block:: bash
salt '*' pacemaker.cluster_local_node_status
'''
try:
node_status = lib_pacemaker.get_local_node_status(
utils.cmd_runner()
)
except LibraryError as e:
raise CommandExecutionError('Unable to get node status: {0}'.format(
'\n'.join([item.message for item in e.args]))
)
return node_status
示例5: get_passwd_data
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import CommandExecutionError [as 别名]
def get_passwd_data(ssh_client, target):
'''
Return a dictionary containing the data found in the file /etc/passwd.
(key = username, value = the raw line of the corresponding user)
'''
tokens = ('username', 'passwd', 'uid', 'gid', 'gecos', 'homedir', 'shell')
User = namedtuple('User', tokens)
try:
passwd_raw = saltstack_module_run(
ssh_client, target, 'account.get_passwd_raw')
user_infos = list(User(*line.rstrip().split(':'))
for line in passwd_raw)
except:
raise CommandExecutionError(
'An error has occurred while reading {0}'.format(filename)
)
def _pack_data(user):
return '{0}:{1}:{2}:{3}:{4}:{5}'.format(
user.username,
user.uid,
user.gid,
user.gecos,
user.homedir,
user.shell)
return dict((user.username, _pack_data(user)) for user in user_infos)
示例6: get_top_data
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import CommandExecutionError [as 别名]
def get_top_data(topfile):
topfile = __salt__['cp.cache_file'](topfile)
try:
with open(topfile) as handle:
topdata = yaml.safe_load(handle)
except Exception as e:
raise CommandExecutionError('Could not load topfile: {0}'.format(e))
if not isinstance(topdata, dict) or 'pulsar' not in topdata or \
not(isinstance(topdata['pulsar'], dict)):
raise CommandExecutionError('Pulsar topfile not formatted correctly')
topdata = topdata['pulsar']
ret = []
for match, data in topdata.iteritems():
if __salt__['match.compound'](match):
ret.extend(data)
return ret
示例7: _cmd_and_result
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import CommandExecutionError [as 别名]
def _cmd_and_result(*args, **kwargs):
cmd = _helm_cmd(*args, **kwargs)
env_string = "".join(['%s="%s" ' % (k, v) for (k, v) in cmd.get('env', {}).items()])
cmd_string = env_string + " ".join(cmd['cmd'])
result = None
try:
result = __salt__['cmd.run_all'](**cmd)
if result['retcode'] != 0:
raise CommandExecutionError(result['stderr'])
return {
'cmd': cmd_string,
'stdout': result['stdout'],
'stderr': result['stderr']
}
except CommandExecutionError as e:
raise HelmExecutionError(cmd_string, e)
示例8: test_no_config_file
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import CommandExecutionError [as 别名]
def test_no_config_file(self):
config_file = "/etc/sysconfig/openattic"
with self.assertRaises(CommandExecutionError) as ctx:
openattic.configure_grafana("grafana.localhost")
self.assertEqual(str(ctx.exception),
"No openATTIC config file found in the following locations: "
"('/etc/default/openattic', '/etc/sysconfig/openattic')")
示例9: _select_config_file_path
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import CommandExecutionError [as 别名]
def _select_config_file_path():
"""
Return an openATTIC configuration pathname
"""
possible_paths = ("/etc/default/openattic", "/etc/sysconfig/openattic")
for path in possible_paths:
if os.access(path, os.F_OK) and os.access(path, os.R_OK | os.W_OK):
return path
raise CommandExecutionError(
("No openATTIC config file found in the following locations: "
"{}".format(possible_paths)))
示例10: get_group_list
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import CommandExecutionError [as 别名]
def get_group_list():
'''
Return the list of the groups configured in /etc/group
CLI Example:
.. code-block:: bash
salt '*' account.get_group_list
'''
file_group = '/etc/group'
tokens = ('groupname', 'passwd', 'gid', 'grouplist')
Group = namedtuple('Group', tokens)
try:
with salt.utils.fopen(file_group, 'r') as fp_:
group_infos = list(Group(*line.split(':')) for line in fp_)
except:
raise CommandExecutionError(
'An error has occurred while reading {0}'.format(file_group)
)
def _secondary_groups(group):
grouplist = group.grouplist.strip()
return grouplist.split(',') if len(grouplist) > 0 else ''
def _pack_data(group):
secgroups = _secondary_groups(group)
return dict(
gid = int(group.gid), grouplist = secgroups
) if secgroups else dict(gid = int(group.gid))
return dict((group.groupname, _pack_data(group)) for group in group_infos)
示例11: get_user_list
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import CommandExecutionError [as 别名]
def get_user_list():
'''
Return the list of the users configured in /etc/passwd
CLI Example:
.. code-block:: bash
salt '*' account.get_user_list
'''
file_user = '/etc/passwd'
tokens = ('username', 'passwd', 'uid', 'gid', 'gecos', 'homedir', 'shell')
User = namedtuple('User', tokens)
try:
with salt.utils.fopen(file_user, 'r') as fp_:
user_infos = list(User(*line.rstrip().split(':')) for line in fp_)
except:
raise CommandExecutionError(
'An error has occurred while reading {0}'.format(file_user)
)
def _pack_data(user):
return dict(
uid = int(user.uid),
gid = int(user.gid),
gecos = user.gecos,
homedir = user.homedir,
shell = user.shell)
return dict((user.username, _pack_data(user)) for user in user_infos)
示例12: get_service_list
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import CommandExecutionError [as 别名]
def get_service_list():
'''
Return the list of the services configured in /etc/services
CLI Example:
.. code-block:: bash
salt '*' service_iana.get_service_list
'''
toks = ('name', 'port')
Service = collections.namedtuple('Service', toks)
skip_line = lambda line: line.lstrip().startswith('#') or not line.strip()
service_infos = []
try:
with salt.utils.fopen(file_services, 'r') as fp_:
# just take the first two tokens and ignore the comment (if any)
service_infos = [Service(*line.split()[:2]) for line in fp_
if not skip_line(line)]
except:
raise CommandExecutionError(
'An error has occurred while reading {0} at line\n{1}'.format(
file_services, line)
)
return dict([
(service.port, {
'name': service.name,
'port': service.port.split('/')[0],
'protocol': service.port.split('/')[1]
}) for service in service_infos])
示例13: cluster_resources
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import CommandExecutionError [as 别名]
def cluster_resources():
'''
Return the cluster status resources.
CLI Example:
.. code-block:: bash
salt '*' pacemaker.cluster_resources
'''
info_dom = utils.getClusterState()
resources = info_dom.getElementsByTagName('resources')
if resources.length == 0:
raise CommandExecutionError('No resources section found')
def _pack_data(resource):
nodes = resource.getElementsByTagName('node')
node = list(node.getAttribute('name')
for node in nodes if nodes.length > 0)
resource_agent = resource.getAttribute('resource_agent')
resource_id = resource.getAttribute('id')
role = resource.getAttribute('role')
return (resource_id, dict(
resource_agent = resource_agent,
role = role,
node = node[0] if len(node) == 1 else node))
return dict(_pack_data(resource)
for resource in resources[0].getElementsByTagName('resource'))
示例14: lscpu
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import CommandExecutionError [as 别名]
def lscpu(*args):
'''
Return the number of core, logical, and CPU sockets, by parsing
the lscpu command and following back to /proc/cpuinfo when this tool
is not available.
CLI Example:
.. code-block:: bash
salt '*' cpuinfo.lscpu
salt '*' cpuinfo.lscpu logicals
'''
(cpus, sockets, cores) = _lscpu() or _proc()
infos = {
'cores': cores,
'logicals': cpus,
'sockets': sockets
}
if not args:
return infos
try:
ret = dict((arg, infos[arg]) for arg in args)
except:
raise CommandExecutionError(
'Invalid flag passed to {0}.proc'.format(__virtualname__)
)
return ret
示例15: get_users_infos
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import CommandExecutionError [as 别名]
def get_users_infos(ssh_client, target, users):
'''
Return a dictionary containing the system informations for
the list of users 'users'.
'''
all_groups = saltstack_module_run(
ssh_client, target, 'account.get_group_list')
group_names = all_groups.keys()
def _pack_data(user):
data = saltstack_module_run(
ssh_client, target, 'user.info', [user])
if not data:
raise CommandExecutionError(
'Unable to find the user: {0}'.format(user))
gid = data['gid']
groups = [grp for grp in group_names if all_groups[grp]['gid'] == gid]
secgroups = [grp for grp in data['groups'] if grp not in groups]
return dict(
group = ','.join(groups),
shell = data['shell'],
home = data['home'],
secgroups = ','.join(secgroups),
)
return dict((user, _pack_data(user)) for user in users)