本文整理汇总了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
示例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
示例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)
示例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
示例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)
示例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
示例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()
示例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()
示例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'
示例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
示例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))
示例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)
示例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)
示例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))
示例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)