Python novaclient.exceptions.ClientException() Examples
The following are 30
code examples of novaclient.exceptions.ClientException().
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: masakari_util.py From masakari with Apache License 2.0 | 6 votes |
def do_instance_evacuate(self, uuid, targethost): """Call evacuate API for server instance. :uuid : Instance id :targethost: The name or ID of the host where the server is evacuated. """ try: msg = ('Call Evacuate API with %s to %s' % (uuid, targethost)) LOG.info(msg) self.nova_client.servers.evacuate(uuid, host=targethost, on_shared_storage=True) except exceptions.ClientException as e: msg = ('Fails to call Instance Evacuate API onto %s: %s' % (targethost, e)) LOG.error(msg) raise
Example #2
Source File: masakari_util.py From masakari with Apache License 2.0 | 6 votes |
def do_instance_show(self, uuid): """Returns Server Intance. :uuid : Instance id :return : Server instance """ try: msg = ('Call Server Details API with %s' % uuid) LOG.info(msg) server = self.nova_client.servers.get(uuid) except exceptions.ClientException as e: msg = 'Fails to call Nova get Server Details API: %s' % e LOG.error(msg) raise return server
Example #3
Source File: masakari_util.py From masakari with Apache License 2.0 | 6 votes |
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
Example #4
Source File: vimconn_openstack.py From openmano with Apache License 2.0 | 6 votes |
def _reload_connection(self): '''Called before any operation, it check if credentials has changed Throw keystoneclient.apiclient.exceptions.AuthorizationFailure ''' #TODO control the timing and possible token timeout, but it seams that python client does this task for us :-) if self.reload_client: #test valid params if len(self.n_creds) <4: raise ksExceptions.ClientException("Not enough parameters to connect to openstack") self.nova = nClient.Client(2, **self.n_creds) self.keystone = ksClient.Client(**self.k_creds) self.glance_endpoint = self.keystone.service_catalog.url_for(service_type='image', endpoint_type='publicURL') self.glance = glClient.Client(self.glance_endpoint, token=self.keystone.auth_token, **self.k_creds) #TODO check k_creds vs n_creds self.ne_endpoint=self.keystone.service_catalog.url_for(service_type='network', endpoint_type='publicURL') self.neutron = neClient.Client('2.0', endpoint_url=self.ne_endpoint, token=self.keystone.auth_token, **self.k_creds) self.reload_client = False
Example #5
Source File: masakari_util.py From masakari with Apache License 2.0 | 6 votes |
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
Example #6
Source File: masakari_util.py From masakari with Apache License 2.0 | 6 votes |
def do_instance_reset(self, uuid, status): """ Call Nova reset state API. :uuid : Instance id :status : Status reset to """ try: msg = ('Call Reset State API with %s to %s' % (uuid, status)) LOG.info(msg) self.nova_client.servers.reset_state(uuid, status) except exceptions.ClientException as e: msg = 'Fails to call Nova Server Reset State API: %s' % e LOG.error(msg) raise EnvironmentError(msg)
Example #7
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 #8
Source File: vimconn_openstack.py From openmano with Apache License 2.0 | 6 votes |
def new_user(self, user_name, user_passwd, tenant_id=None): '''Adds a new user to openstack VIM''' '''Returns the user identifier''' self.logger.debug("osconnector: Adding a new user to VIM") try: self._reload_connection() user=self.keystone.users.create(user_name, user_passwd, tenant_id=tenant_id) #self.keystone.tenants.add_user(self.k_creds["username"], #role) return 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.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: self.logger.debug("new_user " + error_text) return error_value, error_text
Example #9
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 #10
Source File: masakari_util.py From masakari with Apache License 2.0 | 6 votes |
def fetch_servers_on_hypervisor(self, hypervisor): """Fetch server instance list on the hypervisor. :hypervisor : hypervisor's hostname :return : A list of servers """ opts = { 'host': hypervisor, 'all_tenants': True, } try: msg = ('Fetch Server list on %s' % hypervisor) LOG.info(msg) servers = self.nova_client.servers.list(detailed=False, search_opts=opts) return [s.id for s in servers] except exceptions.ClientException as e: msg = 'Fails to call Nova Servers List API: %s' % e LOG.error(msg) raise
Example #11
Source File: masakari_util.py From masakari with Apache License 2.0 | 6 votes |
def check_compute_node_state(self, hostname, state): """Check state (up or down) of specified compute node. :hostname : hostname of compute node to check state. :state : return True if current state of target compute node equals this value. """ try: msg = 'Call compute services API with hostname={0} state={1}'.format(hostname, state) LOG.info(msg) services = self.nova_client.services.list() for service in services: if service.binary != 'nova-compute': continue if service.host == hostname and service.state == state: return True return False except exceptions.ClientException as e: msg = 'Fails to Call compute services API with hostname={0} state={1}: {2}'.format(hostname, state, e) LOG.error(msg) raise
Example #12
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 #13
Source File: nova.py From avos with Apache License 2.0 | 6 votes |
def image_name(self): import glanceclient.exc as glance_exceptions # noqa from openstack_dashboard.api import glance # noqa if not self.image: return _("-") if hasattr(self.image, 'name'): return self.image.name if 'name' in self.image: return self.image['name'] else: try: image = glance.image_get(self.request, self.image['id']) return image.name except glance_exceptions.ClientException: return _("-")
Example #14
Source File: vimconn_openstack.py From openmano with Apache License 2.0 | 6 votes |
def delete_network(self, net_id): '''Deletes a tenant network from VIM. Returns the old network identifier''' self.logger.debug("Deleting network '%s' from VIM", net_id) try: self._reload_connection() #delete VM ports attached to this networks before the network ports = self.neutron.list_ports(network_id=net_id) for p in ports['ports']: try: self.neutron.delete_port(p["id"]) except Exception as e: self.logger.error("Error deleting port %s: %s", p["id"], str(e)) self.neutron.delete_network(net_id) return net_id except (neExceptions.ConnectionFailed, neExceptions.NetworkNotFoundClient, neExceptions.NeutronException, neClient.exceptions.ConnectionFailed, ksExceptions.ClientException, neExceptions.NeutronException) as e: self._format_exception(e)
Example #15
Source File: vimconn_openstack.py From openmano with Apache License 2.0 | 6 votes |
def get_network_list(self, filter_dict={}): '''Obtain tenant networks of VIM Filter_dict can be: name: network name id: network uuid shared: boolean tenant_id: tenant admin_state_up: boolean status: 'ACTIVE' Returns the network list of dictionaries ''' self.logger.debug("Getting network from VIM filter: '%s'", str(filter_dict)) try: self._reload_connection() net_dict=self.neutron.list_networks(**filter_dict) net_list=net_dict["networks"] self.__net_os2mano(net_list) return net_list except (neExceptions.ConnectionFailed, neClient.exceptions.ConnectionFailed, ksExceptions.ClientException, neExceptions.NeutronException) as e: self._format_exception(e)
Example #16
Source File: nova.py From avos with Apache License 2.0 | 6 votes |
def evacuate_host(request, host, target=None, on_shared_storage=False): # TODO(jmolle) This should be change for nova atomic api host_evacuate hypervisors = novaclient(request).hypervisors.search(host, True) response = [] err_code = None for hypervisor in hypervisors: hyper = Hypervisor(hypervisor) # if hypervisor doesn't have servers, the attribute is not present for server in hyper.servers: try: novaclient(request).servers.evacuate(server['uuid'], target, on_shared_storage) except nova_exceptions.ClientException as err: err_code = err.code msg = _("Name: %(name)s ID: %(uuid)s") msg = msg % {'name': server['name'], 'uuid': server['uuid']} response.append(msg) if err_code: msg = _('Failed to evacuate instances: %s') % ', '.join(response) raise nova_exceptions.ClientException(err_code, msg) return True
Example #17
Source File: vimconn_openstack.py From openmano with Apache License 2.0 | 6 votes |
def get_tenant_list(self, filter_dict={}): '''Obtain tenants of VIM filter_dict can contain the following keys: name: filter by tenant name id: filter by tenant uuid/id <other VIM specific> Returns the tenant list of dictionaries: [{'name':'<name>, 'id':'<id>, ...}, ...] ''' self.logger.debug("Getting tenant from VIM filter: '%s'", str(filter_dict)) try: self._reload_connection() tenant_class_list=self.keystone.tenants.findall(**filter_dict) tenant_list=[] for tenant in tenant_class_list: tenant_list.append(tenant.to_dict()) return tenant_list except (ksExceptions.ConnectionError, ksExceptions.ClientException) as e: self._format_exception(e)
Example #18
Source File: nova_protection_plugin.py From karbor with Apache License 2.0 | 6 votes |
def _fetch_server(self, nova_client, server_id): server = None try: server = nova_client.servers.get(server_id) except exceptions.OverLimit as exc: LOG.warning("Received an OverLimit response when " "fetching server (%(id)s) : %(exception)s", {'id': server_id, 'exception': exc}) except exceptions.ClientException as exc: if ((getattr(exc, 'http_status', getattr(exc, 'code', None)) in (500, 503))): LOG.warning("Received the following exception when " "fetching server (%(id)s) : %(exception)s", {'id': server_id, 'exception': exc}) else: raise return server
Example #19
Source File: nova_api.py From Cloud99 with Apache License 2.0 | 5 votes |
def nova_stop_server(self, instance_name): """ Stop the server using id :param instance_name: """ try: server = self.novaclient.servers.find(name=instance_name) ret = self.novaclient.servers.stop(server.id) except (ClientException, Exception) as e: return 400, e.message, [] return 200, "success", ret
Example #20
Source File: exceptions.py From avos with Apache License 2.0 | 5 votes |
def data(TEST): TEST.exceptions = utils.TestDataContainer() unauth = keystone_exceptions.Unauthorized TEST.exceptions.keystone_unauthorized = create_stubbed_exception(unauth) keystone_exception = keystone_exceptions.ClientException TEST.exceptions.keystone = create_stubbed_exception(keystone_exception) nova_exception = nova_exceptions.ClientException TEST.exceptions.nova = create_stubbed_exception(nova_exception) nova_unauth = nova_exceptions.Unauthorized TEST.exceptions.nova_unauthorized = create_stubbed_exception(nova_unauth) glance_exception = glance_exceptions.ClientException TEST.exceptions.glance = create_stubbed_exception(glance_exception) ceilometer_exception = ceilometer_exceptions.HTTPException TEST.exceptions.ceilometer = create_stubbed_exception(ceilometer_exception) neutron_exception = neutron_exceptions.NeutronClientException TEST.exceptions.neutron = create_stubbed_exception(neutron_exception) swift_exception = swift_exceptions.ClientException TEST.exceptions.swift = create_stubbed_exception(swift_exception) cinder_exception = cinder_exceptions.BadRequest TEST.exceptions.cinder = create_stubbed_exception(cinder_exception) trove_exception = trove_exceptions.ClientException TEST.exceptions.trove = create_stubbed_exception(trove_exception) trove_auth = trove_exceptions.Unauthorized TEST.exceptions.trove_unauthorized = \ create_stubbed_exception(trove_auth)
Example #21
Source File: test_openstack.py From flocker with Apache License 2.0 | 5 votes |
def test_novaclient_exception(self, logger): """ The details of ``novaclient.exceptions.ClientException`` are logged when it is raised by the decorated method and the exception is still raised. """ result = NovaClientException( code=INTERNAL_SERVER_ERROR, message="Some things went wrong with some other things.", details={"key": "value"}, request_id="abcdefghijklmnopqrstuvwxyz", url="/foo/bar", method="POST", ) logging_dummy = LoggingDummy(Dummy(result)) self.assertRaises(NovaClientException, logging_dummy.raise_method) logged = LoggedMessage.of_type( logger.messages, NOVA_CLIENT_EXCEPTION, )[0] assertContainsFields( self, logged.message, { u"code": result.code, u"message": result.message, u"details": result.details, u"request_id": result.request_id, u"url": result.url, u"method": result.method, }, )
Example #22
Source File: nova_api.py From Cloud99 with Apache License 2.0 | 5 votes |
def nova_start_server(self, instance_name): """ Start the server using id :param instance_name: """ try: server = self.novaclient.servers.find(name=instance_name) ret = self.novaclient.servers.start(server.id) except (ClientException, Exception) as e: return 400, e.message, [] return 200, "success", ret
Example #23
Source File: nova_api.py From Cloud99 with Apache License 2.0 | 5 votes |
def nova_service_list(self): """ Get the list of nova services """ try: service_list = self.novaclient.services.list() except (ClientException, Exception) as e: return 400, e.message, [] return 200, "success", service_list
Example #24
Source File: vimconn_openstack.py From openmano with Apache License 2.0 | 5 votes |
def get_hosts(self, vim_tenant): '''Get the hosts and deployed instances Returns the hosts content''' r, hype_dict = self.get_hosts_info() if r<0: return r, hype_dict hypervisors = hype_dict["hosts"] try: servers = self.nova.servers.list() for hype in hypervisors: for server in servers: if server.to_dict()['OS-EXT-SRV-ATTR:hypervisor_hostname']==hype['hypervisor_hostname']: if 'vm' in hype: hype['vm'].append(server.id) else: hype['vm'] = [server.id] return 1, hype_dict 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 " + error_text return error_value, error_text
Example #25
Source File: vimconn_openstack.py From openmano with Apache License 2.0 | 5 votes |
def get_vminstance(self,vm_id): '''Returns the VM instance information from VIM''' #self.logger.debug("Getting VM from VIM") try: self._reload_connection() server = self.nova.servers.find(id=vm_id) #TODO parse input and translate to VIM format (openmano_schemas.new_vminstance_response_schema) return server.to_dict() except (ksExceptions.ClientException, nvExceptions.ClientException, nvExceptions.NotFound) as e: self._format_exception(e)
Example #26
Source File: vimconn_openstack.py From openmano with Apache License 2.0 | 5 votes |
def delete_image(self, image_id): '''Deletes a tenant image from openstack VIM. Returns the old id ''' try: self._reload_connection() self.nova.images.delete(image_id) return image_id except (nvExceptions.NotFound, ksExceptions.ClientException, nvExceptions.ClientException, gl1Exceptions.CommunicationError) as e: #TODO remove self._format_exception(e)
Example #27
Source File: vimconn_openstack.py From openmano with Apache License 2.0 | 5 votes |
def delete_flavor(self,flavor_id): '''Deletes a tenant flavor from openstack VIM. Returns the old flavor_id ''' try: self._reload_connection() self.nova.flavors.delete(flavor_id) return flavor_id #except nvExceptions.BadRequest as e: except (nvExceptions.NotFound, ksExceptions.ClientException, nvExceptions.ClientException) as e: self._format_exception(e)
Example #28
Source File: vimconn_openstack.py From openmano with Apache License 2.0 | 5 votes |
def get_flavor(self, flavor_id): '''Obtain flavor details from the VIM. Returns the flavor dict details''' self.logger.debug("Getting flavor '%s'", flavor_id) try: self._reload_connection() flavor = self.nova.flavors.find(id=flavor_id) #TODO parse input and translate to VIM format (openmano_schemas.new_vminstance_response_schema) return flavor.to_dict() except (nvExceptions.NotFound, nvExceptions.ClientException, ksExceptions.ClientException) as e: self._format_exception(e)
Example #29
Source File: vimconn_openstack.py From openmano with Apache License 2.0 | 5 votes |
def delete_tenant(self, tenant_id): '''Delete a tenant from openstack VIM. Returns the old tenant identifier''' self.logger.debug("Deleting tenant %s from VIM", tenant_id) try: self._reload_connection() self.keystone.tenants.delete(tenant_id) return tenant_id except (ksExceptions.ConnectionError, ksExceptions.ClientException) as e: self._format_exception(e)
Example #30
Source File: vimconn_openstack.py From openmano with Apache License 2.0 | 5 votes |
def new_tenant(self, tenant_name, tenant_description): '''Adds a new tenant to openstack VIM. Returns the tenant identifier''' self.logger.debug("Adding a new tenant name: %s", tenant_name) try: self._reload_connection() tenant=self.keystone.tenants.create(tenant_name, tenant_description) return tenant.id except (ksExceptions.ConnectionError, ksExceptions.ClientException) as e: self._format_exception(e)