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


Python encodeutils.exception_to_unicode方法代碼示例

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


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

示例1: _bucket_exists

# 需要導入模塊: from oslo_utils import encodeutils [as 別名]
# 或者: from oslo_utils.encodeutils import exception_to_unicode [as 別名]
def _bucket_exists(s3_client, bucket):
        """Check whether bucket exists in the S3.

        :param s3_client: An object with credentials to connect to S3
        :param bucket: S3 bucket name
        :returns: boolean value; If the value is true, the bucket is exist
                  if false, it is not.
        :raises: BadStoreConfiguration if cannot connect to S3 successfully
        """
        try:
            s3_client.head_bucket(Bucket=bucket)
        except boto_exceptions.ClientError as e:
            error_code = e.response['Error']['Code']
            if error_code == '404':
                return False
            msg = ("Failed to get bucket info: %s" %
                   encodeutils.exception_to_unicode(e))
            LOG.error(msg)
            raise glance_store.BadStoreConfiguration(store_name='s3',
                                                     reason=msg)
        else:
            return True 
開發者ID:openstack,項目名稱:glance_store,代碼行數:24,代碼來源:s3.py

示例2: _object_exists

# 需要導入模塊: from oslo_utils import encodeutils [as 別名]
# 或者: from oslo_utils.encodeutils import exception_to_unicode [as 別名]
def _object_exists(s3_client, bucket, key):
        """Check whether object exists in the specific bucket of S3.

        :param s3_client: An object with credentials to connect to S3
        :param bucket: S3 bucket name
        :param key: The image object name
        :returns: boolean value; If the value is true, the object is exist
                  if false, it is not.
        :raises: BadStoreConfiguration if cannot connect to S3 successfully
        """
        try:
            s3_client.head_object(Bucket=bucket, Key=key)
        except boto_exceptions.ClientError as e:
            error_code = e.response['Error']['Code']
            if error_code == '404':
                return False
            msg = ("Failed to get object info: %s" %
                   encodeutils.exception_to_unicode(e))
            LOG.error(msg)
            raise glance_store.BadStoreConfiguration(store_name='s3',
                                                     reason=msg)
        else:
            return True 
開發者ID:openstack,項目名稱:glance_store,代碼行數:25,代碼來源:s3.py

示例3: _create_bucket

# 需要導入模塊: from oslo_utils import encodeutils [as 別名]
# 或者: from oslo_utils.encodeutils import exception_to_unicode [as 別名]
def _create_bucket(s3_client, s3_host, bucket):
        """Create bucket into the S3.

        :param s3_client: An object with credentials to connect to S3
        :param s3_host: S3 endpoint url
        :param bucket: S3 bucket name
        :raises: BadStoreConfiguration if cannot connect to S3 successfully
        """
        region = get_s3_location(s3_host)
        try:
            s3_client.create_bucket(
                Bucket=bucket,
            ) if region == '' else s3_client.create_bucket(
                Bucket=bucket,
                CreateBucketConfiguration={
                    'LocationConstraint': region
                }
            )
        except boto_exceptions.ClientError as e:
            msg = ("Failed to add bucket to S3: %s" %
                   encodeutils.exception_to_unicode(e))
            LOG.error(msg)
            raise glance_store.BadStoreConfiguration(store_name='s3',
                                                     reason=msg) 
開發者ID:openstack,項目名稱:glance_store,代碼行數:26,代碼來源:s3.py

示例4: validate_buffering

# 需要導入模塊: from oslo_utils import encodeutils [as 別名]
# 或者: from oslo_utils.encodeutils import exception_to_unicode [as 別名]
def validate_buffering(buffer_dir):
    if buffer_dir is None:
        msg = _('Configuration option "swift_upload_buffer_dir" is '
                'not set. Please set it to a valid path to buffer '
                'during Swift uploads.')
        raise exceptions.BadStoreConfiguration(store_name='swift',
                                               reason=msg)

    # NOTE(dharinic): Ensure that the provided directory path for
    # buffering is valid
    try:
        _tmpfile = tempfile.TemporaryFile(dir=buffer_dir)
    except OSError as err:
        msg = (_('Unable to use buffer directory set with '
                 '"swift_upload_buffer_dir". Error: %s') %
               encodeutils.exception_to_unicode(err))
        raise exceptions.BadStoreConfiguration(store_name='swift',
                                               reason=msg)
    else:
        _tmpfile.close()
        return True 
開發者ID:openstack,項目名稱:glance_store,代碼行數:23,代碼來源:buffered.py

示例5: _get_storage_url

# 需要導入模塊: from oslo_utils import encodeutils [as 別名]
# 或者: from oslo_utils.encodeutils import exception_to_unicode [as 別名]
def _get_storage_url(self):
        """Get swift endpoint from keystone

        Return endpoint for swift from service catalog. The method works only
        Keystone v3. If you are using different version (1 or 2)
        it returns None.
        :return: swift endpoint
        """
        if self.store.auth_version == '3':
            try:
                return self.client.session.get_endpoint(
                    service_type=self.store.service_type,
                    interface=self.store.endpoint_type,
                    region_name=self.store.region
                )
            except Exception as e:
                # do the same that swift driver does
                # when catching ClientException
                msg = _("Cannot find swift service endpoint : "
                        "%s") % encodeutils.exception_to_unicode(e)
                raise exceptions.BackendException(msg) 
開發者ID:openstack,項目名稱:glance_store,代碼行數:23,代碼來源:connection_manager.py

示例6: get_size

# 需要導入模塊: from oslo_utils import encodeutils [as 別名]
# 或者: from oslo_utils.encodeutils import exception_to_unicode [as 別名]
def get_size(self, location, context=None):
        """
        Takes a `glance_store.location.Location` object that indicates
        where to find the image file, and returns the size

        :param location: `glance_store.location.Location` object, supplied
                        from glance_store.location.get_location_from_uri()
        """
        conn = None
        try:
            conn, resp, size = self._query(location, 'HEAD')
        except requests.exceptions.ConnectionError as exc:
            err_msg = encodeutils.exception_to_unicode(exc)
            reason = _("The HTTP URL is invalid: %s") % err_msg
            LOG.info(reason)
            raise exceptions.BadStoreUri(message=reason)
        finally:
            # NOTE(sabari): Close the connection as the request was made with
            # stream=True
            if conn is not None:
                conn.close()
        return size 
開發者ID:openstack,項目名稱:glance_store,代碼行數:24,代碼來源:http.py

示例7: configure

# 需要導入模塊: from oslo_utils import encodeutils [as 別名]
# 或者: from oslo_utils.encodeutils import exception_to_unicode [as 別名]
def configure(self, re_raise_bsc=False):
        """
        Configure the store to use the stored configuration options
        and initialize capabilities based on current configuration.

        Any store that needs special configuration should implement
        this method.
        """

        try:
            self.configure_add()
        except exceptions.BadStoreConfiguration as e:
            self.unset_capabilities(capabilities.BitMasks.WRITE_ACCESS)
            msg = (_(u"Failed to configure store correctly: %s "
                     "Disabling add method.")
                   % encodeutils.exception_to_unicode(e))
            LOG.warning(msg)
            if re_raise_bsc:
                raise
        finally:
            self.update_capabilities() 
開發者ID:openstack,項目名稱:glance_store,代碼行數:23,代碼來源:driver.py

示例8: facets

# 需要導入模塊: from oslo_utils import encodeutils [as 別名]
# 或者: from oslo_utils.encodeutils import exception_to_unicode [as 別名]
def facets(self, req, index_name=None, doc_type=None,
               all_projects=False, limit_terms=0, include_fields=True,
               exclude_options=False):
        try:
            search_repo = self.gateway.get_catalog_search_repo(req.context)
            return search_repo.facets(index_name, doc_type,
                                      all_projects, limit_terms,
                                      include_fields=include_fields,
                                      exclude_options=exclude_options)
        except exception.Forbidden as e:
            raise webob.exc.HTTPForbidden(explanation=e.msg)
        except exception.NotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.msg)
        except Exception as e:
            LOG.error(encodeutils.exception_to_unicode(e))
            raise webob.exc.HTTPInternalServerError() 
開發者ID:openstack,項目名稱:searchlight,代碼行數:18,代碼來源:search.py

示例9: get_index_refresh_interval

# 需要導入模塊: from oslo_utils import encodeutils [as 別名]
# 或者: from oslo_utils.encodeutils import exception_to_unicode [as 別名]
def get_index_refresh_interval(index_name):
    """Get the refresh_interval of a given index, if refresh_interval isn't
       set, return default 1s.
    """

    es_engine = searchlight.elasticsearch.get_api()
    try:
        result = es_engine.indices.get_settings(index_name,
                                                'index.refresh_interval')
    except Exception as e:
        # If we cannot get index setting, something must be wrong,
        # no need to continue, log the error message and raise.
        LOG.error(encodeutils.exception_to_unicode(e))
        raise

    if result:
        return result[index_name]['settings']['index']['refresh_interval']
    else:
        return '1s' 
開發者ID:openstack,項目名稱:searchlight,代碼行數:21,代碼來源:utils.py

示例10: set_index_refresh_interval

# 需要導入模塊: from oslo_utils import encodeutils [as 別名]
# 或者: from oslo_utils.encodeutils import exception_to_unicode [as 別名]
def set_index_refresh_interval(index_name, refresh_interval):
    """Set refresh_interval of a given index, basically it is used in the
       reindexing phase. By setting refresh_interval to -1 we disable the
       refresh of offline index to gain a performance boost for the bulk
       updates. After reindexing is done, we will restore refresh_interval
       and put the index online.
    """

    es_engine = searchlight.elasticsearch.get_api()

    body = {
        'index': {
            'refresh_interval': refresh_interval
        }
    }

    try:
        es_engine.indices.put_settings(body, index_name)
    except Exception as e:
        LOG.error(encodeutils.exception_to_unicode(e))
        raise 
開發者ID:openstack,項目名稱:searchlight,代碼行數:23,代碼來源:utils.py

示例11: alias_error_cleanup

# 需要導入模塊: from oslo_utils import encodeutils [as 別名]
# 或者: from oslo_utils.encodeutils import exception_to_unicode [as 別名]
def alias_error_cleanup(indexes):
    """While trying to re-index, we ran into some error. In this case, the
       new index creation/alias updating is incorrect. We will need to clean
       up by rolling back all of the changes. ElasticSearch must stay
       uncluttered. We will delete the indexes explicitly here. ElasticSearch
       will implicitly take care of removing deleted indexes from the aliases.
    """

    es_engine = searchlight.elasticsearch.get_api()

    for index in indexes.values():
        try:
            es_engine.indices.delete(index=index, ignore=404)
        except Exception as e:
            msg = {'index': index}
            LOG.error("Index [%(index)s] clean-up failed." % msg)
            LOG.error(encodeutils.exception_to_unicode(e)) 
開發者ID:openstack,項目名稱:searchlight,代碼行數:19,代碼來源:utils.py

示例12: _basic_authenticate

# 需要導入模塊: from oslo_utils import encodeutils [as 別名]
# 或者: from oslo_utils.encodeutils import exception_to_unicode [as 別名]
def _basic_authenticate(self, auth_info, req):
        try:
            project_domain_id, project_name, user_domain_id = \
                self._get_auth_params()
            auth = password.Password(auth_url=self.auth_url,
                                     username=auth_info.username,
                                     password=auth_info.password,
                                     user_domain_id=user_domain_id,
                                     project_domain_id=project_domain_id,
                                     project_name=project_name)
            sess = session.Session(auth=auth)
            token = sess.get_token()
            project_id = str(auth.get_project_id(sess))
            roles = str(auth.get_auth_ref(sess).role_names[0])
            self._set_req_headers(req, token, project_id, roles)
        except Exception as e:
            to_unicode = encodeutils.exception_to_unicode(e)
            message = 'Authorization exception: %s' % to_unicode
            self._unauthorized(message) 
開發者ID:openstack,項目名稱:vitrage,代碼行數:21,代碼來源:basic_and_keystone_auth.py

示例13: get_vnf_package_vnfd

# 需要導入模塊: from oslo_utils import encodeutils [as 別名]
# 或者: from oslo_utils.encodeutils import exception_to_unicode [as 別名]
def get_vnf_package_vnfd(self, context, vnf_package):
        csar_path = os.path.join(CONF.vnf_package.vnf_package_csar_path,
                                 vnf_package.id)
        if not os.path.isdir(csar_path):
            location = vnf_package.location_glance_store
            try:
                zip_path = glance_store.load_csar(vnf_package.id, location)
                csar_utils.extract_csar_zip_file(zip_path, csar_path)
            except (store_exceptions.GlanceStoreException) as e:
                exc_msg = encodeutils.exception_to_unicode(e)
                msg = (_("Exception raised from glance store can be "
                         "unrecoverable if it is not related to connection"
                         " error. Error: %s.") % exc_msg)
                raise exceptions.FailedToGetVnfdData(error=msg)
        try:
            return self._read_vnfd_files(csar_path)
        except Exception as e:
            exc_msg = encodeutils.exception_to_unicode(e)
            msg = (_("Exception raised while reading csar file"
                     " Error: %s.") % exc_msg)
            raise exceptions.FailedToGetVnfdData(error=msg) 
開發者ID:openstack,項目名稱:tacker,代碼行數:23,代碼來源:conductor_server.py

示例14: load_csar_data

# 需要導入模塊: from oslo_utils import encodeutils [as 別名]
# 或者: from oslo_utils.encodeutils import exception_to_unicode [as 別名]
def load_csar_data(context, package_uuid, zip_path):

    extract_zip_path = os.path.join(CONF.vnf_package.vnf_package_csar_path,
                                    package_uuid)
    extract_csar_zip_file(zip_path, extract_zip_path)

    try:
        tosca = ToscaTemplate(zip_path, None, True)
        return _get_data_from_csar(tosca, context, package_uuid)
    except exceptions.InvalidCSAR as exp:
        with excutils.save_and_reraise_exception():
            LOG.error("Error processing CSAR file %(path)s for vnf package"
                      " %(uuid)s: Error: %(error)s. ",
                      {'path': zip_path, 'uuid': package_uuid,
                    'error': encodeutils.exception_to_unicode(exp)})
    except Exception as exp:
        with excutils.save_and_reraise_exception():
            LOG.error("Tosca parser failed for vnf package %(uuid)s: "
                      "Error: %(error)s. ", {'uuid': package_uuid,
                      'error': encodeutils.exception_to_unicode(exp)})
            exp.reraise = False
            raise exceptions.InvalidCSAR(encodeutils.exception_to_unicode
                                         (exp)) 
開發者ID:openstack,項目名稱:tacker,代碼行數:25,代碼來源:csar_utils.py

示例15: get_csar_data_iter

# 需要導入模塊: from oslo_utils import encodeutils [as 別名]
# 或者: from oslo_utils.encodeutils import exception_to_unicode [as 別名]
def get_csar_data_iter(body):
    try:
        if isinstance(body, dict):
            url = body['address_information']
            req = urllib.request.Request(url)
            if body['user_name'] is not None or body['password'] is not None:
                _add_basic_auth(req, body['user_name'], body['password'])
            data_iter = urllib.request.urlopen(req)
        else:
            data_iter = body

        return data_iter
    except Exception as e:
        error = encodeutils.exception_to_unicode(e)
        LOG.warn("Failed to open csar URL: %(url)s due to error: %(error)s",
                 {"url": url, "error": error})
        raise exceptions.VNFPackageURLInvalid(url=url) 
開發者ID:openstack,項目名稱:tacker,代碼行數:19,代碼來源:store.py


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