當前位置: 首頁>>代碼示例>>Python>>正文


Python exceptions.ClientException方法代碼示例

本文整理匯總了Python中novaclient.exceptions.ClientException方法的典型用法代碼示例。如果您正苦於以下問題:Python exceptions.ClientException方法的具體用法?Python exceptions.ClientException怎麽用?Python exceptions.ClientException使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在novaclient.exceptions的用法示例。


在下文中一共展示了exceptions.ClientException方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _reload_connection

# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import ClientException [as 別名]
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 
開發者ID:nfvlabs,項目名稱:openmano,代碼行數:18,代碼來源:vimconn_openstack.py

示例2: get_tenant_list

# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import ClientException [as 別名]
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) 
開發者ID:nfvlabs,項目名稱:openmano,代碼行數:20,代碼來源:vimconn_openstack.py

示例3: get_network_list

# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import ClientException [as 別名]
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) 
開發者ID:nfvlabs,項目名稱:openmano,代碼行數:22,代碼來源:vimconn_openstack.py

示例4: delete_network

# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import ClientException [as 別名]
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) 
開發者ID:nfvlabs,項目名稱:openmano,代碼行數:19,代碼來源:vimconn_openstack.py

示例5: delete_vminstance

# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import ClientException [as 別名]
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 
開發者ID:nfvlabs,項目名稱:openmano,代碼行數:21,代碼來源:vimconn_openstack.py

示例6: new_user

# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import ClientException [as 別名]
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 
開發者ID:nfvlabs,項目名稱:openmano,代碼行數:22,代碼來源:vimconn_openstack.py

示例7: delete_user

# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import ClientException [as 別名]
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 
開發者ID:nfvlabs,項目名稱:openmano,代碼行數:25,代碼來源:vimconn_openstack.py

示例8: do_instance_show

# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import ClientException [as 別名]
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 
開發者ID:ntt-sic,項目名稱:masakari,代碼行數:20,代碼來源:masakari_util.py

示例9: do_instance_stop

# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import ClientException [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 
開發者ID:ntt-sic,項目名稱:masakari,代碼行數:23,代碼來源:masakari_util.py

示例10: do_instance_start

# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import ClientException [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 
開發者ID:ntt-sic,項目名稱:masakari,代碼行數:23,代碼來源:masakari_util.py

示例11: do_instance_reset

# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import ClientException [as 別名]
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) 
開發者ID:ntt-sic,項目名稱:masakari,代碼行數:18,代碼來源:masakari_util.py

示例12: fetch_servers_on_hypervisor

# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import ClientException [as 別名]
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 
開發者ID:ntt-sic,項目名稱:masakari,代碼行數:24,代碼來源:masakari_util.py

示例13: do_instance_evacuate

# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import ClientException [as 別名]
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 
開發者ID:ntt-sic,項目名稱:masakari,代碼行數:20,代碼來源:masakari_util.py

示例14: check_compute_node_state

# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import ClientException [as 別名]
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 
開發者ID:ntt-sic,項目名稱:masakari,代碼行數:23,代碼來源:masakari_util.py

示例15: translate_server_exception

# 需要導入模塊: from novaclient import exceptions [as 別名]
# 或者: from novaclient.exceptions import ClientException [as 別名]
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 
開發者ID:openstack,項目名稱:manila,代碼行數:22,代碼來源:nova.py


注:本文中的novaclient.exceptions.ClientException方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。