本文整理汇总了Python中salt.exceptions.SaltInvocationError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.SaltInvocationError方法的具体用法?Python exceptions.SaltInvocationError怎么用?Python exceptions.SaltInvocationError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类salt.exceptions
的用法示例。
在下文中一共展示了exceptions.SaltInvocationError方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: normalize_input_values
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import SaltInvocationError [as 别名]
def normalize_input_values(config, devices):
# This is special for pcdummy and his ext_pillar mongo usage.
#
# It translates:
# [{key: key1, value: value1}, {key: key2, value: value2}]
# to:
# {key1: value1, key2: value2}
#
# MongoDB doesn't like dots in field names.
if isinstance(config, list):
if (len(config) > 0 and
'key' in config[0] and
'value' in config[0]):
config = {d['key']: d['value'] for d in config}
else:
config = {}
if isinstance(config, six.string_types):
raise SaltInvocationError(
"config can't be a string, validate your YAML input."
)
if isinstance(devices, six.string_types):
raise SaltInvocationError(
"devices can't be a string, validate your YAML input."
)
# Golangs wants strings
if config is not None:
for k, v in six.iteritems(config):
config[k] = six.text_type(v)
if devices is not None:
for dn in devices:
for k, v in six.iteritems(devices[dn]):
devices[dn][k] = v
return (config, devices,)
示例2: _set_property_dict_item
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import SaltInvocationError [as 别名]
def _set_property_dict_item(obj, prop, key, value):
''' Sets the dict item key of the attr from obj.
Basicaly it does getattr(obj, prop)[key] = value.
For the disk device we added some checks to make
device changes on the CLI saver.
'''
attr = getattr(obj, prop)
if prop == 'devices':
device_type = value['type']
if device_type == 'disk' and 'source' not in value:
raise SaltInvocationError(
"source must be given as parameter"
)
if device_type == 'disk' and 'path' not in value:
raise SaltInvocationError(
"path must be given as parameter"
)
for k in value.keys():
if k.startswith('__'):
del value[k]
attr[key] = value
else: # config
attr[key] = str(value)
pylxd_save_object(obj)
return _pylxd_model_to_dict(obj)
示例3: _get_property_dict_item
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import SaltInvocationError [as 别名]
def _get_property_dict_item(obj, prop, key):
attr = getattr(obj, prop)
if key not in attr:
raise SaltInvocationError(
"'{0}' doesn't exists".format(key)
)
return attr[key]
示例4: _delete_property_dict_item
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import SaltInvocationError [as 别名]
def _delete_property_dict_item(obj, prop, key):
attr = getattr(obj, prop)
if key not in attr:
raise SaltInvocationError(
"'{0}' doesn't exists".format(key)
)
del attr[key]
pylxd_save_object(obj)
return True
示例5: _verify_image
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import SaltInvocationError [as 别名]
def _verify_image(image,
remote_addr=None,
cert=None,
key=None,
verify_cert=True):
# Get image by alias/fingerprint or check for fingerprint attribute
if isinstance(image, six.string_types):
name = image
# This will fail with a SaltInvocationError if
# the image doesn't exists on the source and with a
# CommandExecutionError on connection problems.
image = None
try:
image = image_get_by_alias(
name, remote_addr, cert,
key, verify_cert, _raw=True
)
except SaltInvocationError:
image = image_get(
name, remote_addr, cert,
key, verify_cert, _raw=True
)
elif not hasattr(image, 'fingerprint'):
raise SaltInvocationError(
'Invalid image \'{0}\''.format(image)
)
return image
示例6: queue
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import SaltInvocationError [as 别名]
def queue(**kwargs):
"""
Fire an event if a queue is empty
"""
# The same event drives the deletion and this check. Give sqlite two
# seconds to complete its update
time.sleep(2)
# defaults
settings = {
'backend': 'sqlite',
'queue': 'prep',
'next': 'discovery'
}
settings.update(kwargs)
queue_funcs = salt.loader.queues(__opts__)
cmd = '{0}.list_length'.format(settings['backend'])
if cmd not in queue_funcs:
raise SaltInvocationError('Function "{0}" is not available'.format(cmd))
ret = queue_funcs[cmd](queue=settings['queue'])
if (ret == 0):
event = salt.utils.event.get_event(
'master',
__opts__['sock_dir'],
__opts__['transport'],
opts=__opts__,
listen=False)
# skip dunder keys
settings = {k:v for k,v in settings.iteritems() if not k.startswith('__')}
event.fire_event(settings, tagify(['start', settings['next'], 'stage'], prefix='ceph'))
log.info("firing event for stage {}".format(settings['next']))
else:
log.info("size of queue {} is {}".format(settings['queue'], ret))
return ret
示例7: container_get
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import SaltInvocationError [as 别名]
def container_get(name=None, remote_addr=None,
cert=None, key=None, verify_cert=True, _raw=False):
''' Gets a container from the LXD
name :
The name of the container to get.
remote_addr :
An URL to a remote Server, you also have to give cert and key if
you provide remote_addr and its a TCP Address!
Examples:
https://myserver.lan:8443
/var/lib/mysocket.sock
cert :
PEM Formatted SSL Certificate.
Examples:
~/.config/lxc/client.crt
key :
PEM Formatted SSL Key.
Examples:
~/.config/lxc/client.key
verify_cert : True
Wherever to verify the cert, this is by default True
but in the most cases you want to set it off as LXD
normaly uses self-signed certificates.
_raw :
Return the pylxd object, this is internal and by states in use.
'''
client = pylxd_client_get(remote_addr, cert, key, verify_cert)
if name is None:
containers = client.containers.all()
if _raw:
return containers
else:
containers = []
try:
containers = [client.containers.get(name)]
except pylxd.exceptions.LXDAPIException:
raise SaltInvocationError(
'Container \'{0}\' not found'.format(name)
)
if _raw:
return containers[0]
infos = []
for container in containers:
infos.append(dict([
(container.name, _pylxd_model_to_dict(container))
]))
return infos
示例8: container_rename
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import SaltInvocationError [as 别名]
def container_rename(name, newname, remote_addr=None,
cert=None, key=None, verify_cert=True):
'''
Rename a container
name :
Name of the container to Rename
newname :
The new name of the contianer
remote_addr :
An URL to a remote Server, you also have to give cert and key if
you provide remote_addr and its a TCP Address!
Examples:
https://myserver.lan:8443
/var/lib/mysocket.sock
cert :
PEM Formatted SSL Certificate.
Examples:
~/.config/lxc/client.crt
key :
PEM Formatted SSL Key.
Examples:
~/.config/lxc/client.key
verify_cert : True
Wherever to verify the cert, this is by default True
but in the most cases you want to set it off as LXD
normaly uses self-signed certificates.
'''
container = container_get(
name, remote_addr, cert, key, verify_cert, _raw=True
)
if container.status_code == CONTAINER_STATUS_RUNNING:
raise SaltInvocationError(
"Can't rename the running container '{0}'.".format(name)
)
container.rename(newname, wait=True)
return _pylxd_model_to_dict(container)
示例9: container_state
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import SaltInvocationError [as 别名]
def container_state(name=None, remote_addr=None,
cert=None, key=None, verify_cert=True):
'''
Get container state
remote_addr :
An URL to a remote Server, you also have to give cert and key if
you provide remote_addr and its a TCP Address!
Examples:
https://myserver.lan:8443
/var/lib/mysocket.sock
cert :
PEM Formatted SSL Certificate.
Examples:
~/.config/lxc/client.crt
key :
PEM Formatted SSL Key.
Examples:
~/.config/lxc/client.key
verify_cert : True
Wherever to verify the cert, this is by default True
but in the most cases you want to set it off as LXD
normaly uses self-signed certificates.
'''
client = pylxd_client_get(remote_addr, cert, key, verify_cert)
if name is None:
containers = client.containers.all()
else:
try:
containers = [client.containers.get(name)]
except pylxd.exceptions.LXDAPIException:
raise SaltInvocationError(
'Container \'{0}\' not found'.format(name)
)
states = []
for container in containers:
state = {}
state = container.state()
states.append(dict([
(
container.name,
dict([
(k, getattr(state, k))
for k in dir(state)
if not k.startswith('_')
])
)
]))
return states
示例10: profile_get
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import SaltInvocationError [as 别名]
def profile_get(name, remote_addr=None,
cert=None, key=None, verify_cert=True, _raw=False):
''' Gets a profile from the LXD
name :
The name of the profile to get.
remote_addr :
An URL to a remote Server, you also have to give cert and key if
you provide remote_addr and its a TCP Address!
Examples:
https://myserver.lan:8443
/var/lib/mysocket.sock
cert :
PEM Formatted SSL Certificate.
Examples:
~/.config/lxc/client.crt
key :
PEM Formatted SSL Key.
Examples:
~/.config/lxc/client.key
verify_cert : True
Wherever to verify the cert, this is by default True
but in the most cases you want to set it off as LXD
normaly uses self-signed certificates.
_raw :
Return the pylxd object, this is internal and by states in use.
CLI Examples:
.. code-block:: bash
$ salt '*' lxd.profile_get autostart
'''
client = pylxd_client_get(remote_addr, cert, key, verify_cert)
profile = None
try:
profile = client.profiles.get(name)
except pylxd.exceptions.LXDAPIException:
raise SaltInvocationError(
'Profile \'{0}\' not found'.format(name)
)
if _raw:
return profile
return _pylxd_model_to_dict(profile)
示例11: image_get
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import SaltInvocationError [as 别名]
def image_get(fingerprint,
remote_addr=None,
cert=None,
key=None,
verify_cert=True,
_raw=False):
''' Get an image by its fingerprint
fingerprint :
The fingerprint of the image to retrieve
remote_addr :
An URL to a remote Server, you also have to give cert and key if
you provide remote_addr and its a TCP Address!
Examples:
https://myserver.lan:8443
/var/lib/mysocket.sock
cert :
PEM Formatted SSL Certificate.
Examples:
~/.config/lxc/client.crt
key :
PEM Formatted SSL Key.
Examples:
~/.config/lxc/client.key
verify_cert : True
Wherever to verify the cert, this is by default True
but in the most cases you want to set it off as LXD
normaly uses self-signed certificates.
_raw : False
Return the raw pylxd object or a dict of it?
CLI Examples:
..code-block:: bash
$ salt '*' lxd.image_get <fingerprint>
'''
client = pylxd_client_get(remote_addr, cert, key, verify_cert)
image = None
try:
image = client.images.get(fingerprint)
except pylxd.exceptions.LXDAPIException:
raise SaltInvocationError(
'Image with fingerprint \'{0}\' not found'.format(fingerprint)
)
if _raw:
return image
return _pylxd_model_to_dict(image)
示例12: queue
# 需要导入模块: from salt import exceptions [as 别名]
# 或者: from salt.exceptions import SaltInvocationError [as 别名]
def queue(**kwargs):
"""
Fire an event if a queue is empty
"""
# The same event drives the deletion and this check. Give sqlite two
# seconds to complete its update
time.sleep(2)
# defaults
settings = {
'backend': 'sqlite',
'queue': 'prep',
'next': 'discovery'
}
settings.update(kwargs)
queue_funcs = salt.loader.queues(__opts__)
cmd = '{0}.list_length'.format(settings['backend'])
if cmd not in queue_funcs:
raise SaltInvocationError('Function "{0}" is not available'.format(cmd))
ret = queue_funcs[cmd](queue=settings['queue'])
if (ret == 0):
event = salt.utils.event.get_event(
'master',
__opts__['sock_dir'],
__opts__['transport'],
opts=__opts__,
listen=False)
# skip dunder keys
settings = {k:v for k,v in settings.iteritems() if not k.startswith('__')}
event.fire_event(settings, tagify(['start', settings['next'], 'stage'], prefix='ceph'))
log.info("firing event for stage {}".format(settings['next']))
else:
log.info("size of queue {} is {}".format(settings['queue'], ret))
return ret