Python novaclient.exceptions.NotFound() Examples
The following are 30
code examples of novaclient.exceptions.NotFound().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
novaclient.exceptions
, or try the search function
.
Example #1
Source File: nova.py From manila with Apache License 2.0 | 6 votes |
def translate_server_exception(method): """Transforms the exception for the instance. Note: keeps its traceback intact. """ @six.wraps(method) def wrapper(self, ctx, instance_id, *args, **kwargs): try: res = method(self, ctx, instance_id, *args, **kwargs) return res except nova_exception.ClientException as e: if isinstance(e, nova_exception.NotFound): raise exception.InstanceNotFound(instance_id=instance_id) elif isinstance(e, nova_exception.BadRequest): raise exception.InvalidInput(reason=six.text_type(e)) else: raise exception.ManilaException(e) return wrapper
Example #2
Source File: instance.py From ec2-api with Apache License 2.0 | 6 votes |
def get_ec2_network_interfaces(self, context, instance_ids=None): # NOTE(ft): we would be glad to use filters with this describe # operation, but: # 1. A selective filter by network interface IDs is improper because # it leads to rising NotFound exception if at least one of specified # network interfaces is obsolete. This is the legal case of describing # an instance after its terminating. # 2. A general filter by instance ID is unsupported now. # 3. A general filter by network interface IDs leads to additional # call of DB here to get corresponding network interfaces, but doesn't # lead to decrease DB and OS throughtput in called describe operation. enis = network_interface_api.describe_network_interfaces( context)['networkInterfaceSet'] ec2_network_interfaces = collections.defaultdict(list) for eni in enis: if (eni['status'] == 'in-use' and (not instance_ids or eni['attachment']['instanceId'] in instance_ids)): ec2_network_interfaces[ eni['attachment']['instanceId']].append(eni) return ec2_network_interfaces
Example #3
Source File: instance.py From ec2-api with Apache License 2.0 | 6 votes |
def _format_state_change(instance, os_instance): if os_instance: prev_state = _cloud_state_description(getattr(os_instance, 'OS-EXT-STS:vm_state')) try: os_instance.get() curr_state = _cloud_state_description( getattr(os_instance, 'OS-EXT-STS:vm_state')) except nova_exception.NotFound: curr_state = _cloud_state_description(vm_states_WIPED_OUT) else: prev_state = curr_state = _cloud_state_description(vm_states_WIPED_OUT) return { 'instanceId': instance['id'], 'previousState': prev_state, 'currentState': curr_state, }
Example #4
Source File: instance.py From ec2-api with Apache License 2.0 | 6 votes |
def terminate_instances(context, instance_id): instance_ids = set(instance_id) instances = ec2utils.get_db_items(context, 'i', instance_ids) nova = clients.nova(context) state_changes = [] for instance in instances: if instance.get('disable_api_termination'): message = _("The instance '%s' may not be terminated. Modify its " "'disableApiTermination' instance attribute and try " "again.") % instance['id'] raise exception.OperationNotPermitted(message=message) for instance in instances: try: os_instance = nova.servers.get(instance['os_id']) except nova_exception.NotFound: os_instance = None else: os_instance.delete() state_change = _format_state_change(instance, os_instance) state_changes.append(state_change) # NOTE(ft): don't delete items from DB until they disappear from OS. # They will be auto deleted by a describe operation return {'instancesSet': state_changes}
Example #5
Source File: nova_driver.py From octavia with Apache License 2.0 | 6 votes |
def validate_flavor(self, flavor_id): """Validates that a flavor exists in nova. :param flavor_id: ID of the flavor to lookup in nova. :raises: NotFound :returns: None """ try: self.flavor_manager.get(flavor_id) except nova_exceptions.NotFound: LOG.info('Flavor %s was not found in nova.', flavor_id) raise exceptions.InvalidSubresource(resource='Nova flavor', id=flavor_id) except Exception as e: LOG.exception('Nova reports a failure getting flavor details for ' 'flavor ID %s: %s', flavor_id, e) raise
Example #6
Source File: nova_driver.py From octavia with Apache License 2.0 | 6 votes |
def validate_availability_zone(self, availability_zone): """Validates that an availability zone exists in nova. :param availability_zone: Name of the availability zone to lookup. :raises: NotFound :returns: None """ try: compute_zones = [ a.zoneName for a in self.availability_zone_manager.list( detailed=False)] if availability_zone not in compute_zones: LOG.info('Availability zone %s was not found in nova. %s', availability_zone, compute_zones) raise exceptions.InvalidSubresource( resource='Nova availability zone', id=availability_zone) except Exception as e: LOG.exception('Nova reports a failure getting listing ' 'availability zones: %s', e) raise
Example #7
Source File: vimconn_openstack.py From openmano with Apache License 2.0 | 6 votes |
def delete_vminstance(self, vm_id): '''Removes a VM instance from VIM. Returns the old identifier ''' #print "osconnector: Getting VM from VIM" try: self._reload_connection() #delete VM ports attached to this networks before the virtual machine ports = self.neutron.list_ports(device_id=vm_id) for p in ports['ports']: try: self.neutron.delete_port(p["id"]) except Exception as e: self.logger.error("Error deleting port: " + type(e).__name__ + ": "+ str(e)) self.nova.servers.delete(vm_id) return vm_id except (nvExceptions.NotFound, ksExceptions.ClientException, nvExceptions.ClientException) as e: self._format_exception(e) #TODO insert exception vimconn.HTTP_Unauthorized #if reaching here is because an exception
Example #8
Source File: vimconn_openstack.py From openmano with Apache License 2.0 | 6 votes |
def delete_user(self, user_id): '''Delete a user from openstack VIM''' '''Returns the user identifier''' if self.debug: print "osconnector: Deleting a user from VIM" try: self._reload_connection() self.keystone.users.delete(user_id) return 1, user_id except ksExceptions.ConnectionError as e: error_value=-vimconn.HTTP_Bad_Request error_text= type(e).__name__ + ": "+ (str(e) if len(e.args)==0 else str(e.args[0])) except ksExceptions.NotFound as e: error_value=-vimconn.HTTP_Not_Found error_text= type(e).__name__ + ": "+ (str(e) if len(e.args)==0 else str(e.args[0])) except ksExceptions.ClientException as e: #TODO remove error_value=-vimconn.HTTP_Bad_Request error_text= type(e).__name__ + ": "+ (str(e) if len(e.args)==0 else str(e.args[0])) #TODO insert exception vimconn.HTTP_Unauthorized #if reaching here is because an exception if self.debug: print "delete_tenant " + error_text return error_value, error_text
Example #9
Source File: vimconn_openstack.py From openmano with Apache License 2.0 | 6 votes |
def get_hosts_info(self): '''Get the information of deployed hosts Returns the hosts content''' if self.debug: print "osconnector: Getting Host info from VIM" try: h_list=[] self._reload_connection() hypervisors = self.nova.hypervisors.list() for hype in hypervisors: h_list.append( hype.to_dict() ) return 1, {"hosts":h_list} except nvExceptions.NotFound as e: error_value=-vimconn.HTTP_Not_Found error_text= (str(e) if len(e.args)==0 else str(e.args[0])) except (ksExceptions.ClientException, nvExceptions.ClientException) as e: error_value=-vimconn.HTTP_Bad_Request error_text= type(e).__name__ + ": "+ (str(e) if len(e.args)==0 else str(e.args[0])) #TODO insert exception vimconn.HTTP_Unauthorized #if reaching here is because an exception if self.debug: print "get_hosts_info " + error_text return error_value, error_text
Example #10
Source File: services.py From cloudbridge with MIT License | 6 votes |
def get(self, instance_id): """ Returns an instance given its id. """ try: os_instance = self.provider.nova.servers.get(instance_id) except NovaNotFound: log.debug("Instance %s was not found.", instance_id) return None if (getattr(os_instance, 'OS-EXT-AZ:availability_zone', "") != self.provider.service_zone_name(self)): log.debug("Instance %s was found in availability zone '%s' while " "the OpenStack provider is in zone '%s'", instance_id, getattr(os_instance, 'OS-EXT-AZ:availability_zone', ""), self.provider.service_zone_name(self)) return None return OpenStackInstance(self.provider, os_instance)
Example #11
Source File: openstack.py From wrapanapi with MIT License | 6 votes |
def get_template(self, name=None, id=None): """ Get a template by name OR id """ if name: matches = self.find_templates(name) if not matches: raise ImageNotFoundError(name) elif len(matches) > 1: raise MultipleImagesError(name) result = matches[0] elif id: try: raw_image = self.api.images.get(id) except os_exceptions.NotFound: raise ImageNotFoundError(id) result = OpenstackImage(system=self, uuid=raw_image.id, raw=raw_image) else: raise AttributeError("Must specify either 'name' or 'id' with get_template") return result
Example #12
Source File: openstack_api.py From disk_perf_test_tool with Apache License 2.0 | 6 votes |
def create_flavor(conn: OSConnection, name: str, ram_size: int, hdd_size: int, cpu_count: int) -> None: """create flavor, if doesn't exisis yet parameters: nova: nova connection name: str - flavor name ram_size: int - ram size (UNIT?) hdd_size: int - root hdd size (UNIT?) cpu_count: int - cpu cores returns: None """ try: conn.nova.flavors.find(name) return except NotFound: pass conn.nova.flavors.create(name, cpu_count, ram_size, hdd_size)
Example #13
Source File: validators.py From rally-openstack with Apache License 2.0 | 6 votes |
def _get_validated_flavor(self, config, clients, param_name): from novaclient import exceptions as nova_exc flavor_value = config.get("args", {}).get(param_name) if not flavor_value: self.fail("Parameter %s is not specified." % param_name) try: flavor_processor = openstack_types.Flavor( context={"admin": {"credential": clients.credential}}) flavor_id = flavor_processor.pre_process(flavor_value, config={}) flavor = clients.nova().flavors.get(flavor=flavor_id) return flavor except (nova_exc.NotFound, exceptions.InvalidScenarioArgument): try: return self._get_flavor_from_context(config, flavor_value) except validation.ValidationError: pass self.fail("Flavor '%s' not found" % flavor_value)
Example #14
Source File: test_validators.py From rally-openstack with Apache License 2.0 | 6 votes |
def test__get_validated_flavor_not_found(self, mock_flavor): mock_flavor.return_value.pre_process.return_value = "flavor_id" clients = mock.MagicMock() clients.nova().flavors.get.side_effect = nova_exc.NotFound("") e = self.assertRaises( validators.validation.ValidationError, self.validator._get_validated_flavor, self.config, clients, "flavor") self.assertEqual("Flavor '%s' not found" % self.config["args"]["flavor"], e.message) mock_flavor_obj = mock_flavor.return_value mock_flavor_obj.pre_process.assert_called_once_with( self.config["args"]["flavor"], config={})
Example #15
Source File: nova_servers.py From tripleo-validations with Apache License 2.0 | 5 votes |
def run(self, terms, variables=None, **kwargs): """Returns server information from nova.""" nova = utils.get_nova_client(variables) servers = [] if len(terms) > 0: # Look up servers by network and IP if terms[0] == 'ip': for ip in terms[2]: try: servers.append(nova.servers.find( networks={terms[1]: [ip]})) except NotFound: pass # Look up servers by attribute else: for value in terms[1]: try: search_data = {terms[0]: value} servers.append(nova.servers.find(**search_data)) except NotFound: pass else: servers = nova.servers.list() # For each server only return properties whose value # can be properly serialized. (Things like # novaclient.v2.servers.ServerManager will make # Ansible return the whole result as a string.) return [utils.filtered(server) for server in servers]
Example #16
Source File: test_resources.py From rally-openstack with Apache License 2.0 | 5 votes |
def test_is_deleted_true(self): from osc_lib import exceptions as osc_exc clients = mock.MagicMock() octavia_client = clients.octavia.return_value octavia_client.some_show.side_effect = osc_exc.NotFound(404, "foo") resource = OctaviaSimpleResource( user=clients, resource={"id": "test_id"}) self.assertTrue(resource.is_deleted()) octavia_client.some_show.assert_called_once_with("test_id")
Example #17
Source File: test_resources.py From rally-openstack with Apache License 2.0 | 5 votes |
def test_is_deleted(self, mock__manager): mock__manager.return_value.get.return_value = None watcher = resources.WatcherActionPlan() watcher.id = mock.Mock() self.assertFalse(watcher.is_deleted()) mock__manager.side_effect = [watcher_exceptions.NotFound()] self.assertTrue(watcher.is_deleted())
Example #18
Source File: nova.py From masakari with Apache License 2.0 | 5 votes |
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
Example #19
Source File: test_resources.py From rally-openstack with Apache License 2.0 | 5 votes |
def test_is_deleted(self, mock__manager): mock__manager.return_value.get.return_value = None watcher = resources.WatcherAudit() watcher.id = mock.Mock() self.assertFalse(watcher.is_deleted()) mock__manager.side_effect = [watcher_exceptions.NotFound()] self.assertTrue(watcher.is_deleted())
Example #20
Source File: test_resources.py From rally-openstack with Apache License 2.0 | 5 votes |
def test_is_deleted(self, mock__manager): mock__manager.return_value.get.return_value = None watcher = resources.WatcherTemplate() watcher.id = mock.Mock() self.assertFalse(watcher.is_deleted()) mock__manager.side_effect = [watcher_exceptions.NotFound()] self.assertTrue(watcher.is_deleted())
Example #21
Source File: test_resources.py From rally-openstack with Apache License 2.0 | 5 votes |
def test_list_with_not_found(self): class NotFound(Exception): status_code = 404 user = mock.MagicMock() trunk = resources.NeutronTrunk(user=user) user.neutron().list_trunks.side_effect = NotFound() self.assertEqual([], trunk.list()) user.neutron().list_trunks.assert_called_once_with( tenant_id=None)
Example #22
Source File: test_resources.py From rally-openstack with Apache License 2.0 | 5 votes |
def test_is_deleted_true(self): from neutronclient.common import exceptions as n_exceptions neutron_lb = self.get_neutron_lbaasv2_lb() neutron_lb._manager().show_loadbalancer.side_effect = ( n_exceptions.NotFound) self.assertTrue(neutron_lb.is_deleted()) neutron_lb._manager().show_loadbalancer.assert_called_once_with( neutron_lb.id())
Example #23
Source File: test_resources.py From rally-openstack with Apache License 2.0 | 5 votes |
def test_is_deleted(self, mock_resource_manager__manager): exc = nova_exc.NotFound(404) mock_resource_manager__manager().get.side_effect = exc flavor = resources.NovaFlavors() flavor.raw_resource = mock.MagicMock() self.assertTrue(flavor.is_deleted())
Example #24
Source File: instance.py From ec2-api with Apache License 2.0 | 5 votes |
def get_os_items(self): self.os_volumes = _get_os_volumes(self.context) self.os_flavors = _get_os_flavors(self.context) nova = clients.nova(ec2_context.get_os_admin_context()) if len(self.ids) == 1 and len(self.items) == 1: try: return [nova.servers.get(self.items[0]['os_id'])] except nova_exception.NotFound: return [] else: return nova.servers.list( search_opts={'all_tenants': True, 'project_id': self.context.project_id})
Example #25
Source File: fakes.py From rally-openstack with Apache License 2.0 | 5 votes |
def find(self, name, **kwargs): kwargs["name"] = name for resource in self.cache.values(): match = True for key, value in kwargs.items(): if getattr(resource, key, None) != value: match = False break if match: return resource raise nova_exceptions.NotFound("Security Group not found")
Example #26
Source File: resources.py From rally-openstack with Apache License 2.0 | 5 votes |
def is_deleted(self): from watcherclient.common.apiclient import exceptions try: self._manager().get(self.id()) return False except exceptions.NotFound: return True
Example #27
Source File: resources.py From rally-openstack with Apache License 2.0 | 5 votes |
def is_deleted(self): from gnocchiclient import exceptions as gnocchi_exc try: self._manager().get(self.raw_resource["type"], self.id()) except gnocchi_exc.NotFound: return True return False
Example #28
Source File: resources.py From rally-openstack with Apache License 2.0 | 5 votes |
def is_deleted(self): from osc_lib import exceptions as osc_exc show_method = getattr(self._client, "%s_show" % self._resource) try: show_method(self.id()) except osc_exc.NotFound: return True return False
Example #29
Source File: resources.py From rally-openstack with Apache License 2.0 | 5 votes |
def is_deleted(self): from novaclient import exceptions as nova_exc try: self._manager().get(self.name()) except nova_exc.NotFound: return True return False
Example #30
Source File: attr_validator.py From magnum with Apache License 2.0 | 5 votes |
def validate_image(cli, image): """Validate image""" try: image_found = api_utils.get_openstack_resource(cli.glance().images, image, 'images') except (glance_exception.NotFound, exception.ResourceNotFound): raise exception.ImageNotFound(image_id=image) except glance_exception.HTTPForbidden: raise exception.ImageNotAuthorized(image_id=image) if not image_found.get('os_distro'): raise exception.OSDistroFieldNotFound(image_id=image) return image_found