本文整理汇总了Python中azure.common.AzureException方法的典型用法代码示例。如果您正苦于以下问题:Python common.AzureException方法的具体用法?Python common.AzureException怎么用?Python common.AzureException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.common
的用法示例。
在下文中一共展示了common.AzureException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _openDownloadFile
# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureException [as 别名]
def _openDownloadFile(self, buildId, suffix):
from azure.common import AzureException, AzureMissingResourceHttpError
(tmpFd, tmpName) = mkstemp()
try:
os.close(tmpFd)
self.__service.get_blob_to_path(self.__container,
self.__makeBlobName(buildId, suffix), tmpName)
ret = tmpName
tmpName = None
return AzureDownloader(ret)
except AzureMissingResourceHttpError:
raise ArtifactNotFoundError()
except AzureException as e:
raise ArtifactDownloadError(str(e))
finally:
if tmpName is not None: os.unlink(tmpName)
示例2: scriptDownload
# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureException [as 别名]
def scriptDownload(args):
service, container, remoteBlob, localFile = AzureArchive.scriptGetService(args)
from azure.common import AzureException
# Download into temporary file and rename if downloaded successfully
tmpName = None
try:
(tmpFd, tmpName) = mkstemp(dir=".")
os.close(tmpFd)
service.get_blob_to_path(container, remoteBlob, tmpName)
os.rename(tmpName, localFile)
tmpName = None
except (OSError, AzureException) as e:
raise BuildError("Download failed: " + str(e))
finally:
if tmpName is not None: os.unlink(tmpName)
示例3: get_cost_export_for_key
# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureException [as 别名]
def get_cost_export_for_key(self, key, container_name):
"""Get the latest cost export file from given storage account container."""
report = None
try:
container_client = self._cloud_storage_account.get_container_client(container_name)
blob_list = container_client.list_blobs(name_starts_with=key)
except (AdalError, AzureException, ClientException) as error:
raise AzureServiceError("Failed to download cost export. Error: ", str(error))
for blob in blob_list:
if key == blob.name:
report = blob
break
if not report:
message = f"No cost report for report name {key} found in container {container_name}."
raise AzureCostReportNotFound(message)
return report
示例4: download_cost_export
# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureException [as 别名]
def download_cost_export(self, key, container_name, destination=None):
"""Download the latest cost export file from a given storage container."""
cost_export = self.get_cost_export_for_key(key, container_name)
file_path = destination
if not destination:
temp_file = NamedTemporaryFile(delete=False, suffix=".csv")
file_path = temp_file.name
try:
blob_client = self._cloud_storage_account.get_blob_client(container_name, cost_export.name)
with open(file_path, "wb") as blob_download:
blob_download.write(blob_client.download_blob().readall())
except (AdalError, AzureException, ClientException, IOError) as error:
raise AzureServiceError("Failed to download cost export. Error: ", str(error))
return file_path
示例5: get_direct_download_url
# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureException [as 别名]
def get_direct_download_url(
self, object_path, request_ip=None, expires_in=60, requires_cors=False, head=False
):
blob_name = self._blob_name_from_path(object_path)
try:
sas_token = self._blob_service.generate_blob_shared_access_signature(
self._azure_container,
blob_name,
ContainerPermissions.READ,
datetime.utcnow() + timedelta(seconds=expires_in),
)
blob_url = self._blob_service.make_blob_url(
self._azure_container, blob_name, sas_token=sas_token
)
except AzureException:
logger.exception(
"Exception when trying to get direct download for path %s", object_path
)
raise IOError("Exception when trying to get direct download")
return blob_url
示例6: test_missing_attribute_kek_unwrap
# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureException [as 别名]
def test_missing_attribute_kek_unwrap(self):
# Shared between all services in _decrypt_blob
# Arrange
self.bbs.require_encryption = True
valid_key = KeyWrapper('key1')
self.bbs.key_encryption_key = valid_key
blob_name = self._create_small_blob('block_blob')
# Act
# Note that KeyWrapper has a default value for key_id, so these Exceptions
# are not due to non_matching kids.
invalid_key_1 = lambda: None #functions are objects, so this effectively creates an empty object
invalid_key_1.get_kid = valid_key.get_kid
#No attribute unwrap_key
self.bbs.key_encryption_key = invalid_key_1
with self.assertRaises(AzureException):
self.bbs.get_blob_to_bytes(self.container_name, blob_name)
invalid_key_2 = lambda: None #functions are objects, so this effectively creates an empty object
invalid_key_2.unwrap_key = valid_key.unwrap_key
#No attribute get_kid
with self.assertRaises(AzureException):
self.bbs.get_blob_to_bytes(self.container_name, blob_name)
示例7: _openUploadFile
# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureException [as 别名]
def _openUploadFile(self, buildId, suffix):
from azure.common import AzureException
blobName = self.__makeBlobName(buildId, suffix)
try:
if self.__service.exists(self.__container, blobName):
raise ArtifactExistsError()
except AzureException as e:
raise ArtifactUploadError(str(e))
(tmpFd, tmpName) = mkstemp()
os.close(tmpFd)
return AzureUploader(self.__service, self.__container, tmpName, blobName)
示例8: scriptUpload
# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureException [as 别名]
def scriptUpload(args):
service, container, remoteBlob, localFile = AzureArchive.scriptGetService(args)
from azure.common import AzureException, AzureConflictHttpError
try:
service.create_blob_from_path(container, remoteBlob, localFile, if_none_match="*")
print("OK")
except AzureConflictHttpError:
print("skipped")
except (OSError, AzureException) as e:
raise BuildError("Upload failed: " + str(e))
示例9: __upload
# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureException [as 别名]
def __upload(self):
from azure.common import AzureException, AzureConflictHttpError
try:
self.__service.create_blob_from_path(self.__container,
self.__remoteName, self.__name, if_none_match="*")
except AzureConflictHttpError:
raise ArtifactExistsError()
except AzureException as e:
raise ArtifactUploadError(str(e))
示例10: test_cost_usage_source_is_reachable_exception
# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureException [as 别名]
def test_cost_usage_source_is_reachable_exception(self, _):
"""Test that ValidationError is raised when AzureException is raised."""
credentials = {
"subscription_id": FAKE.uuid4(),
"tenant_id": FAKE.uuid4(),
"client_id": FAKE.uuid4(),
"client_secret": FAKE.word(),
}
source_name = {"resource_group": FAKE.word(), "storage_account": FAKE.word()}
with self.assertRaises(ValidationError):
AzureProvider().cost_usage_source_is_reachable(credentials, source_name)
示例11: get_latest_cost_export_for_path
# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureException [as 别名]
def get_latest_cost_export_for_path(self, report_path, container_name):
"""Get the latest cost export file from given storage account container."""
latest_report = None
if not container_name:
message = "Unable to gather latest export as container name is not provided."
LOG.warning(message)
raise AzureCostReportNotFound(message)
try:
container_client = self._cloud_storage_account.get_container_client(container_name)
blob_list = container_client.list_blobs(name_starts_with=report_path)
for blob in blob_list:
if report_path in blob.name and not latest_report:
latest_report = blob
elif report_path in blob.name and blob.last_modified > latest_report.last_modified:
latest_report = blob
if not latest_report:
message = f"No cost report found in container {container_name} for " f"path {report_path}."
raise AzureCostReportNotFound(message)
return latest_report
except (AdalError, AzureException, ClientException) as error:
raise AzureServiceError("Failed to download cost export. Error: ", str(error))
except HttpResponseError as httpError:
if httpError.status_code == 403:
message = (
"An authorization error occurred attempting to gather latest export"
f" in container {container_name} for "
f"path {report_path}."
)
else:
message = (
"Unknown error occurred attempting to gather latest export"
f" in container {container_name} for "
f"path {report_path}."
)
error_msg = message + f" Azure Error: {httpError}."
LOG.warning(error_msg)
raise AzureCostReportNotFound(message)
示例12: throw_azure_exception
# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureException [as 别名]
def throw_azure_exception(scope):
"""Raises azure exception."""
raise AzureException()
示例13: get
# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureException [as 别名]
def get(self, key_pair_id):
try:
key_pair = self.provider.azure_client.\
get_public_key(key_pair_id)
if key_pair:
return AzureKeyPair(self.provider, key_pair)
return None
except AzureException as error:
log.debug("KeyPair %s was not found.", key_pair_id)
log.debug(error)
return None
示例14: upload
# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureException [as 别名]
def upload(self, data):
"""
Set the contents of this object to the data read from the source
string.
"""
try:
self._provider.azure_client.create_blob_from_text(
self._container.id, self.id, data)
return True
except AzureException as azureEx:
log.exception(azureEx)
return False
示例15: upload_from_file
# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureException [as 别名]
def upload_from_file(self, path):
"""
Store the contents of the file pointed by the "path" variable.
"""
try:
self._provider.azure_client.create_blob_from_file(
self._container.id, self.id, path)
return True
except AzureException as azureEx:
log.exception(azureEx)
return False