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


Python common.AzureException方法代碼示例

本文整理匯總了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) 
開發者ID:BobBuildTool,項目名稱:bob,代碼行數:18,代碼來源:archive.py

示例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) 
開發者ID:BobBuildTool,項目名稱:bob,代碼行數:18,代碼來源:archive.py

示例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 
開發者ID:project-koku,項目名稱:koku,代碼行數:19,代碼來源:azure_service.py

示例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 
開發者ID:project-koku,項目名稱:koku,代碼行數:18,代碼來源:azure_service.py

示例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 
開發者ID:quay,項目名稱:quay,代碼行數:25,代碼來源:azurestorage.py

示例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) 
開發者ID:Azure,項目名稱:azure-storage-python,代碼行數:25,代碼來源:test_blob_encryption.py

示例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) 
開發者ID:BobBuildTool,項目名稱:bob,代碼行數:14,代碼來源:archive.py

示例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)) 
開發者ID:BobBuildTool,項目名稱:bob,代碼行數:12,代碼來源:archive.py

示例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)) 
開發者ID:BobBuildTool,項目名稱:bob,代碼行數:11,代碼來源:archive.py

示例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) 
開發者ID:project-koku,項目名稱:koku,代碼行數:13,代碼來源:tests_provider.py

示例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) 
開發者ID:project-koku,項目名稱:koku,代碼行數:40,代碼來源:azure_service.py

示例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() 
開發者ID:project-koku,項目名稱:koku,代碼行數:5,代碼來源:test_azure_services.py

示例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 
開發者ID:CloudVE,項目名稱:cloudbridge,代碼行數:14,代碼來源:services.py

示例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 
開發者ID:CloudVE,項目名稱:cloudbridge,代碼行數:14,代碼來源:resources.py

示例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 
開發者ID:CloudVE,項目名稱:cloudbridge,代碼行數:13,代碼來源:resources.py


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