Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_mac_group_add(self):
'''
Tests the add group function
'''
try:
self.run_function('group.add', [ADD_GROUP, 3456])
group_info = self.run_function('group.info', [ADD_GROUP])
self.assertEqual(group_info['name'], ADD_GROUP)
except CommandExecutionError:
self.run_function('group.delete', [ADD_GROUP])
raise
headers = [_ for _ in lines[0].split(' ') if len(_) > 0]
jails = []
if len(lines) > 1:
for l in lines[1:]:
# omit all non-iocage jails
if l == '--- non iocage jails currently active ---':
break
jails.append({
headers[k]: v for k, v in enumerate([_ for _ in l.split(' ')
if len(_) > 0])
})
return jails
else:
raise CommandExecutionError(
'Error in command "%s" : no results found' % (cmd, ))
:param value: The new value
:return: boolean value indicating whether the record was updated.
'''
user = _find_user('/Local/Default', name)
if user is None:
raise CommandExecutionError(
'user {} does not exist'.format(name)
)
didSet, err = user.setValue_forAttribute_error_(value, od_attribute, None)
if err is not None:
log.error('failed to set attribute {} on user {}, reason: {}'.format(od_attribute, name, err.localizedDescription()))
synced, err = user.synchronizeAndReturnError_(None)
if err is not None:
raise CommandExecutionError(
'could not save updated user record, reason: {}'.format(err.localizedDescription())
)
if not synced:
return False
return True
auto_claim_storage: false
compression_enabled: true
dedup_enabled: true
enabled: true
'''
proxy_type = __salt__['vsphere.get_proxy_type']()
if proxy_type == 'esxdatacenter':
cluster_name, datacenter_name = \
name, __salt__['esxdatacenter.get_details']()['datacenter']
elif proxy_type == 'esxcluster':
cluster_name, datacenter_name = \
__salt__['esxcluster.get_details']()['cluster'], \
__salt__['esxcluster.get_details']()['datacenter']
else:
raise salt.exceptions.CommandExecutionError('Unsupported proxy {0}'
''.format(proxy_type))
log.info('Running {0} for cluster \'{1}\' in datacenter '
'\'{2}\''.format(name, cluster_name, datacenter_name))
cluster_dict = cluster_config
log.trace('cluster_dict = {0}'.format(cluster_dict))
changes_required = False
ret = {'name': name,
'changes': {}, 'result': None, 'comment': 'Default'}
comments = []
changes = {}
changes_required = False
try:
log.trace('Validating cluster_configured state input')
schema = ESXClusterConfigSchema.serialize()
log.trace('schema = {0}'.format(schema))
ret = {'name': name,
'result': True,
'changes': {'old': 'unknown',
'new': '********'},
'comment': 'Host password was updated.'}
esxi_cmd = 'esxi.cmd'
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Host password will change.'
return ret
else:
try:
__salt__[esxi_cmd]('update_host_password',
new_password=password)
except CommandExecutionError as err:
ret['result'] = False
ret['comment'] = 'Error: {0}'.format(err)
return ret
return ret
Raises:
CommandExecutionError: On failure
CLI Example:
.. code-block:: bash
salt '*' dsc.restore_config
'''
cmd = 'Restore-DscConfiguration'
try:
_pshell(cmd, ignore_retcode=True)
except CommandExecutionError as exc:
if 'A previous configuration does not exist' in exc.info['stderr']:
raise CommandExecutionError('Previous Configuration Not Found')
raise
return True
.. code-block:: bash
salt-run digicert.show_company example.com
'''
data = salt.utils.http.query(
'{0}/companies/domain/{1}'.format(_base_url(), domain),
status=True,
decode=True,
decode_type='json',
header_dict={
'tppl-api-key': _api_key(),
},
)
status = data['status']
if str(status).startswith('4') or str(status).startswith('5'):
raise CommandExecutionError(
'There was an API error: {0}'.format(data['error'])
)
return data.get('dict', {})
elif pull_type == 'dkr':
# No need to validate the index URL, machinectl will take care of this
# for us.
if 'index' in kwargs:
pull_opts.append('--dkr-index-url={0}'.format(kwargs['index']))
cmd = 'pull-{0} {1} {2} {3}'.format(
pull_type, ' '.join(pull_opts), image, name
)
result = _machinectl(cmd, use_vt=True)
if result['retcode'] != 0:
msg = 'Error occurred pulling image. Stderr from the pull command ' \
'(if any) follows: '
if result['stderr']:
msg += '\n\n{0}'.format(result['stderr'])
raise CommandExecutionError(msg)
return True
output = output['output']
result = list()
if isinstance(output, list):
for each in output:
log.info('PARSE_RESPONSE: {0} {1}'.format(each.get('code'), each.get('msg')))
if each.get('code') != '200':
msg = '{0} {1}'.format(each.get('code'), each.get('msg'))
raise CommandExecutionError(msg)
else:
result.append(each['body'])
else:
log.info('PARSE_RESPONSE: {0} {1}'.format(output.get('code'), output.get('msg')))
if output.get('code') != '200':
msg = '{0} {1}'.format(output.get('code'), output.get('msg'))
raise CommandExecutionError(msg)
else:
result.append(output['body'])
return result