本文整理匯總了Python中novaclient.exceptions.Conflict方法的典型用法代碼示例。如果您正苦於以下問題:Python exceptions.Conflict方法的具體用法?Python exceptions.Conflict怎麽用?Python exceptions.Conflict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類novaclient.exceptions
的用法示例。
在下文中一共展示了exceptions.Conflict方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: attach_volume
# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import Conflict [as 別名]
def attach_volume(context, volume_id, instance_id, device):
volume = ec2utils.get_db_item(context, volume_id)
instance = ec2utils.get_db_item(context, instance_id)
nova = clients.nova(context)
try:
nova.volumes.create_server_volume(instance['os_id'], volume['os_id'],
device)
except (nova_exception.Conflict, nova_exception.BadRequest):
# TODO(andrey-mp): raise correct errors for different cases
LOG.exception('Attach has failed.')
raise exception.UnsupportedOperation()
cinder = clients.cinder(context)
os_volume = cinder.volumes.get(volume['os_id'])
attachment = _format_attachment(context, volume, os_volume,
instance_id=instance_id)
# NOTE(andrey-mp): nova sets deleteOnTermination=False for attached volume
attachment['deleteOnTermination'] = False
return attachment
示例2: do_instance_stop
# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import Conflict [as 別名]
def do_instance_stop(self, uuid):
"""Call Nova instance stop API.
:param :uuid : Instance id
:return : None if succeed
"""
try:
msg = ('Call Stop API with %s' % uuid)
LOG.info(msg)
self.nova_client.servers.stop(uuid)
except exceptions.Conflict as e:
msg = "Server instance %s is already in stopped." % uuid
error_msg = "Original Nova client's error: %e" % e
LOG.error(msg + error_msg)
raise EnvironmentError(msg)
except exceptions.ClientException as e:
msg = 'Fails to call Nova Server Stop API: %s' % e
LOG.error(msg)
raise
示例3: do_instance_start
# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import Conflict [as 別名]
def do_instance_start(self, uuid):
"""Call Nova instance start API.
:uuid : Instance id
:return : None if succeed
"""
try:
msg = ('Call Start API with %s' % uuid)
LOG.info(msg)
self.nova_client.servers.start(uuid)
except exceptions.Conflict as e:
msg = "Server instance %s is already in active." % uuid
error_msg = "Original Nova client's error: %e" % e
LOG.error(msg + error_msg)
raise EnvironmentError(msg)
except exceptions.ClientException as e:
msg = 'Fails to call Nova Server Start API: %s' % e
LOG.error(msg)
raise
示例4: test_setup_failexists
# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import Conflict [as 別名]
def test_setup_failexists(self, mock_clients):
# Setup and mock
new_context = copy.deepcopy(self.context)
new_context["flavors"] = {}
mock_flavor_create = mock_clients().nova().flavors.create
exception = nova_exceptions.Conflict("conflict")
mock_flavor_create.side_effect = exception
# Run
flavors_ctx = flavors.FlavorsGenerator(self.context)
flavors_ctx.setup()
# Assertions
self.assertEqual(new_context, flavors_ctx.context)
mock_clients.assert_called_with(self.context["admin"]["credential"])
mock_flavor_create.assert_called_once_with(
name="flavor_name", ram=2048, vcpus=3,
disk=10, ephemeral=3, swap=5)
示例5: create_key_pair
# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import Conflict [as 別名]
def create_key_pair(context, key_name):
_validate_name(key_name)
nova = clients.nova(context)
try:
key_pair = nova.keypairs.create(key_name)
except nova_exception.OverLimit:
raise exception.ResourceLimitExceeded(resource='keypairs')
except nova_exception.Conflict:
raise exception.InvalidKeyPairDuplicate(key_name=key_name)
formatted_key_pair = _format_key_pair(key_pair)
formatted_key_pair['keyMaterial'] = key_pair.private_key
return formatted_key_pair
示例6: import_key_pair
# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import Conflict [as 別名]
def import_key_pair(context, key_name, public_key_material):
_validate_name(key_name)
if not public_key_material:
raise exception.MissingParameter(
_('The request must contain the parameter PublicKeyMaterial'))
nova = clients.nova(context)
public_key = base64.b64decode(public_key_material).decode("utf-8")
try:
key_pair = nova.keypairs.create(key_name, public_key)
except nova_exception.OverLimit:
raise exception.ResourceLimitExceeded(resource='keypairs')
except nova_exception.Conflict:
raise exception.InvalidKeyPairDuplicate(key_name=key_name)
return _format_key_pair(key_pair)
示例7: test_create_key_pair_invalid
# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import Conflict [as 別名]
def test_create_key_pair_invalid(self):
self.nova.keypairs.create.side_effect = (
nova_exception.Conflict(409))
self.assert_execution_error(
'InvalidKeyPair.Duplicate', 'CreateKeyPair',
{'KeyName': fakes.NAME_KEY_PAIR})
self.assert_execution_error(
'ValidationError', 'CreateKeyPair', {'KeyName': 'k' * 256})
self.nova.keypairs.create.side_effect = (
nova_exception.OverLimit(413))
self.assert_execution_error(
'ResourceLimitExceeded', 'CreateKeyPair',
{'KeyName': fakes.NAME_KEY_PAIR})
示例8: plug_port
# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import Conflict [as 別名]
def plug_port(self, amphora, port):
try:
interface = self.compute.attach_network_or_port(
compute_id=amphora.compute_id, network_id=None,
ip_address=None, port_id=port.id)
plugged_interface = self._nova_interface_to_octavia_interface(
amphora.compute_id, interface)
except exceptions.NotFound as e:
if 'Instance' in str(e):
raise base.AmphoraNotFound(str(e))
if 'Network' in str(e):
raise base.NetworkNotFound(str(e))
raise base.PlugNetworkException(str(e))
except nova_client_exceptions.Conflict:
LOG.info('Port %(portid)s is already plugged, '
'skipping', {'portid': port.id})
plugged_interface = n_data_models.Interface(
compute_id=amphora.compute_id,
network_id=port.network_id,
port_id=port.id,
fixed_ips=port.fixed_ips)
except Exception:
message = _('Error plugging amphora (compute_id: '
'{compute_id}) into port '
'{port_id}.').format(
compute_id=amphora.compute_id,
port_id=port.id)
LOG.exception(message)
raise base.PlugNetworkException(message)
return plugged_interface
示例9: test_attach_network_or_port_conflict_exception
# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import Conflict [as 別名]
def test_attach_network_or_port_conflict_exception(self):
self.manager.manager.interface_attach.side_effect = (
nova_exceptions.Conflict('test_exception'))
interface_mock = mock.MagicMock()
interface_mock.id = self.port_id
bad_interface_mock = mock.MagicMock()
bad_interface_mock.id = uuidutils.generate_uuid()
self.manager.manager.interface_list.side_effect = [
[interface_mock], [bad_interface_mock], [], Exception('boom')]
# No port specified
self.assertRaises(exceptions.ComputeUnknownException,
self.manager.attach_network_or_port,
self.compute_id, self.network_id)
# Port already attached
result = self.manager.attach_network_or_port(self.compute_id,
port_id=self.port_id)
self.assertEqual(interface_mock, result)
# Port not found
self.assertRaises(exceptions.ComputePortInUseException,
self.manager.attach_network_or_port,
self.compute_id, port_id=self.port_id)
# No ports attached
self.assertRaises(exceptions.ComputePortInUseException,
self.manager.attach_network_or_port,
self.compute_id, port_id=self.port_id)
# Get attached ports list exception
self.assertRaises(exceptions.ComputeUnknownException,
self.manager.attach_network_or_port,
self.compute_id, port_id=self.port_id)
示例10: _format_exception
# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import Conflict [as 別名]
def _format_exception(self, exception):
'''Transform a keystone, nova, neutron exception into a vimconn exception'''
if isinstance(exception, (HTTPException, gl1Exceptions.HTTPException, gl1Exceptions.CommunicationError,
ConnectionError, ksExceptions.ConnectionError, neExceptions.ConnectionFailed,
neClient.exceptions.ConnectionFailed)):
raise vimconn.vimconnConnectionException(type(exception).__name__ + ": " + str(exception))
elif isinstance(exception, (nvExceptions.ClientException, ksExceptions.ClientException,
neExceptions.NeutronException, nvExceptions.BadRequest)):
raise vimconn.vimconnUnexpectedResponse(type(exception).__name__ + ": " + str(exception))
elif isinstance(exception, (neExceptions.NetworkNotFoundClient, nvExceptions.NotFound)):
raise vimconn.vimconnNotFoundException(type(exception).__name__ + ": " + str(exception))
elif isinstance(exception, nvExceptions.Conflict):
raise vimconn.vimconnConflictException(type(exception).__name__ + ": " + str(exception))
else: # ()
raise vimconn.vimconnConnectionException(type(exception).__name__ + ": " + str(exception))
示例11: setup
# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import Conflict [as 別名]
def setup(self):
"""Create list of flavors."""
from novaclient import exceptions as nova_exceptions
self.context["flavors"] = {}
clients = osclients.Clients(self.context["admin"]["credential"])
for flavor_config in self.config:
extra_specs = flavor_config.get("extra_specs")
flavor_config = FlavorConfig(**flavor_config)
try:
flavor = clients.nova().flavors.create(**flavor_config)
except nova_exceptions.Conflict:
msg = "Using existing flavor %s" % flavor_config["name"]
if logging.is_debug():
LOG.exception(msg)
else:
LOG.warning(msg)
continue
if extra_specs:
flavor.set_keys(extra_specs)
self.context["flavors"][flavor_config["name"]] = flavor.to_dict()
LOG.debug("Created flavor with id '%s'" % flavor.id)
示例12: translate_nova_exception
# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import Conflict [as 別名]
def translate_nova_exception(method):
"""Transforms a cinder exception but keeps its traceback intact."""
@functools.wraps(method)
def wrapper(self, ctx, *args, **kwargs):
try:
res = method(self, ctx, *args, **kwargs)
except (request_exceptions.Timeout,
nova_exception.CommandError,
keystone_exception.ConnectionError) as exc:
err_msg = encodeutils.exception_to_unicode(exc)
_reraise(exception.MasakariException(reason=err_msg))
except (keystone_exception.BadRequest,
nova_exception.BadRequest) as exc:
err_msg = encodeutils.exception_to_unicode(exc)
_reraise(exception.InvalidInput(reason=err_msg))
except (keystone_exception.Forbidden,
nova_exception.Forbidden) as exc:
err_msg = encodeutils.exception_to_unicode(exc)
_reraise(exception.Forbidden(err_msg))
except (nova_exception.NotFound) as exc:
err_msg = encodeutils.exception_to_unicode(exc)
_reraise(exception.NotFound(reason=err_msg))
except nova_exception.Conflict as exc:
err_msg = encodeutils.exception_to_unicode(exc)
_reraise(exception.Conflict(reason=err_msg))
return res
return wrapper
示例13: attach_network_or_port
# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import Conflict [as 別名]
def attach_network_or_port(self, compute_id, network_id=None,
ip_address=None, port_id=None):
"""Attaching a port or a network to an existing amphora
:param compute_id: id of an amphora in the compute service
:param network_id: id of a network
:param ip_address: ip address to attempt to be assigned to interface
:param port_id: id of the neutron port
:return: nova interface instance
:raises ComputePortInUseException: The port is in use somewhere else
:raises ComputeUnknownException: Unknown nova error
"""
try:
interface = self.manager.interface_attach(
server=compute_id, net_id=network_id, fixed_ip=ip_address,
port_id=port_id)
except nova_exceptions.Conflict as e:
# The port is already in use.
if port_id:
# Check if the port we want is already attached
try:
interfaces = self.manager.interface_list(compute_id)
for interface in interfaces:
if interface.id == port_id:
return interface
except Exception as e:
raise exceptions.ComputeUnknownException(exc=str(e))
raise exceptions.ComputePortInUseException(port=port_id)
# Nova should have created the port, so something is really
# wrong in nova if we get here.
raise exceptions.ComputeUnknownException(exc=str(e))
except nova_exceptions.NotFound as e:
if 'Instance' in str(e):
raise exceptions.NotFound(resource='Instance', id=compute_id)
if 'Network' in str(e):
raise exceptions.NotFound(resource='Network', id=network_id)
if 'Port' in str(e):
raise exceptions.NotFound(resource='Port', id=port_id)
raise exceptions.NotFound(resource=str(e), id=compute_id)
except Exception as e:
LOG.error('Error attaching network %(network_id)s with ip '
'%(ip_address)s and port %(port)s to amphora '
'(compute_id: %(compute_id)s) ',
{
'compute_id': compute_id,
'network_id': network_id,
'ip_address': ip_address,
'port': port_id
})
raise exceptions.ComputeUnknownException(exc=str(e))
return interface
示例14: _get_or_create_override_flavor
# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import Conflict [as 別名]
def _get_or_create_override_flavor(self, flavor, cpu=None, ram=None):
"""
Find or create a new flavor usable for provisioning.
Keep the parameters from the original flavor
"""
self.logger.info(
'RAM/CPU override of flavor %s: RAM %r MB, CPU: %r cores', flavor.name, ram, cpu)
ram = ram or flavor.ram
cpu = cpu or flavor.vcpus
disk = flavor.disk
ephemeral = flavor.ephemeral
swap = flavor.swap
rxtx_factor = flavor.rxtx_factor
is_public = flavor.is_public
try:
new_flavor = self._api.flavors.find(
ram=ram, vcpus=cpu,
disk=disk, ephemeral=ephemeral, swap=swap,
rxtx_factor=rxtx_factor, is_public=is_public)
except os_exceptions.NotFound:
# The requested flavor was not found, create a custom one
self.logger.info('No suitable flavor found, creating a new one.')
base_flavor_name = '{}-{}M-{}C'.format(flavor.name, ram, cpu)
flavor_name = base_flavor_name
counter = 0
new_flavor = None
if not swap:
# Protect against swap empty string
swap = 0
while new_flavor is None:
try:
new_flavor = self._api.flavors.create(
name=flavor_name,
ram=ram, vcpus=cpu,
disk=disk, ephemeral=ephemeral, swap=swap,
rxtx_factor=rxtx_factor, is_public=is_public)
except os_exceptions.Conflict:
self.logger.info(
'Name %s is already taken, changing the name', flavor_name)
counter += 1
flavor_name = base_flavor_name + '_{}'.format(counter)
else:
self.logger.info(
'Created a flavor %r with id %r', new_flavor.name, new_flavor.id)
flavor = new_flavor
else:
self.logger.info('Found a flavor %s', new_flavor.name)
flavor = new_flavor
return flavor