当前位置: 首页>>代码示例>>Python>>正文


Python common.AzureMissingResourceHttpError方法代码示例

本文整理汇总了Python中azure.common.AzureMissingResourceHttpError方法的典型用法代码示例。如果您正苦于以下问题:Python common.AzureMissingResourceHttpError方法的具体用法?Python common.AzureMissingResourceHttpError怎么用?Python common.AzureMissingResourceHttpError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在azure.common的用法示例。


在下文中一共展示了common.AzureMissingResourceHttpError方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _openDownloadFile

# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureMissingResourceHttpError [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: test_write_blob_consistency_present

# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureMissingResourceHttpError [as 别名]
def test_write_blob_consistency_present(self, create_mock, create_blob_from_path_mock,
                                            get_blob_properties_mock):
        from azure.common import AzureMissingResourceHttpError
        # given
        items_to_write = self.get_batch()
        options = self.get_writer_config()
        options['options']['check_consistency'] = True

        get_blob_properties_mock.side_effect = AzureMissingResourceHttpError('', 404)

        # when:
        writer = AzureBlobWriter(options, meta())
        try:
            writer.write_batch(items_to_write)
            writer.flush()
        finally:
            writer.close()

        with self.assertRaisesRegexp(InconsistentWriteState, 'Missing blob'):
            writer.finish_writing() 
开发者ID:scrapinghub,项目名称:exporters,代码行数:22,代码来源:test_writers_azure.py

示例3: test_write_file_consistency_present

# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureMissingResourceHttpError [as 别名]
def test_write_file_consistency_present(self, create_mock, create_share_mock,
                                            put_file_from_path_mock, get_file_properties_mock):
        from azure.common import AzureMissingResourceHttpError
        # given
        items_to_write = self.get_batch()
        options = self.get_writer_config()
        options['options']['check_consistency'] = True

        get_file_properties_mock.side_effect = AzureMissingResourceHttpError('', 404)

        # when:
        writer = AzureFileWriter(options, meta())
        try:
            writer.write_batch(items_to_write)
            writer.flush()
        finally:
            writer.close()

        with self.assertRaisesRegexp(InconsistentWriteState, 'Missing file'):
            writer.finish_writing()

        # then:
        self.assertEqual(writer.get_metadata('items_count'), 2) 
开发者ID:scrapinghub,项目名称:exporters,代码行数:25,代码来源:test_writers_azure.py

示例4: _check_write_consistency

# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureMissingResourceHttpError [as 别名]
def _check_write_consistency(self):
        from azure.common import AzureMissingResourceHttpError
        for blob_info in self.get_metadata('blobs_written'):
            try:
                blob = self.azure_service.get_blob_properties(
                    self.read_option('container'), blob_info['blob_name'])
                blob_size = blob.properties.content_length
                blob_md5 = blob.properties.content_settings.content_md5
                if str(blob_size) != str(blob_info['size']):
                    raise InconsistentWriteState(
                        'File {} has unexpected size. (expected {} - got {})'.format(
                            blob_info['blob_name'], blob_info['size'], blob_size
                        )
                    )
                if str(blob_md5) != str(blob_info['hash']):
                    raise InconsistentWriteState(
                        'File {} has unexpected hash. (expected {} - got {})'.format(
                            blob_info['blob_name'], blob_info['hash'], blob_md5
                        )
                    )

            except AzureMissingResourceHttpError:
                raise InconsistentWriteState('Missing blob {}'.format(blob_info['blob_name']))
        self.logger.info('Consistency check passed') 
开发者ID:scrapinghub,项目名称:exporters,代码行数:26,代码来源:azure_blob_writer.py

示例5: file_delete_worker

# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureMissingResourceHttpError [as 别名]
def file_delete_worker(self):
        """Worker for deleting files. This worker is mapped to gevent threads
        for concurrency. Number of threads is configured by `self.max_workers`

        :returns: Nothing
        :rtype: None

        """

        while True:
            try:
                # file_tuple = tuple(keyspace,tablename,file)
                file_tuple = self._delete_queue.get()
                storage_key = '/'.join((self._prefix, ) + file_tuple)
                self._storage.delete_key(storage_key)
            except AzureMissingResourceHttpError as e:
                logger.error("Deletion of blob {0} failed. It's already deleted or missing.".format(storage_key))
            except Exception as e:
                logger.exception("Unexpected exception encountered")
                sys.exit(4)
            finally:
                self._delete_queue.task_done() 
开发者ID:helpshift,项目名称:scyllabackup,代码行数:24,代码来源:snapshot.py

示例6: get_vm_in_cosmos_db

# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureMissingResourceHttpError [as 别名]
def get_vm_in_cosmos_db(self, spoke, vm_hostname):

        try:
            db_vm_info = self.table_service.get_entity(self.vmss_table_name,
                                                       spoke, vm_hostname)
        except AzureMissingResourceHttpError:
            self.logger.info("New VM %s found in spoke %s" % (vm_hostname, spoke))
            return None
        except Exception as e:
            self.logger.error("Querying for %s failed" % vm_hostname)
            return None
        else:
            # IF possible update status TODO
            self.logger.debug("VM %s is available in VMSS, Pan and DB" % (vm_hostname))

        return db_vm_info

    # 'name'       : global_device['@name'],
    # 'hostname'   : global_device['hostname'],
    # 'serial'     : global_device['serial'],
    # 'ip-address' : global_device['ip-address'],
    # 'connected'  : global_device['connected'],
    # 'deactivated': global_device['deactivated'] 
开发者ID:PaloAltoNetworks,项目名称:pan-fca,代码行数:25,代码来源:monitor.py

示例7: create_container

# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureMissingResourceHttpError [as 别名]
def create_container(self, container_name):
        """
        Create a new container on Azure if it does not exist.

        :param container_name: the name of the container
        """
        try:
            return self._connection.create_container(container_name)
        except AzureMissingResourceHttpError:
            raise AzureBlobStorageHelperError('The specified container does not exist.') 
开发者ID:HealthCatalyst,项目名称:healthcareai-py,代码行数:12,代码来源:azure_blob_storage_helper.py

示例8: put

# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureMissingResourceHttpError [as 别名]
def put(self, source_path, blob_name, callback=None):
        """Upload a file or directory from `source_path` to azure blob `blob_name`.

        Upload progress can be traced by an optional callback.
        """
        upload_done = Event()

        def progress_callback(current, total):
            if callback:
                callback(current, total)
            if current >= total:
                upload_done.set()

        # Attempt to make backup if an existing version is already available
        try:
            x_ms_copy_source = "https://{}.blob.core.windows.net/{}/{}".format(
                self._account_name,
                self._container_name,
                blob_name
            )
            self._service.copy_blob(
                container_name=self._container_name,
                blob_name=blob_name + ".backup",
                x_ms_copy_source=x_ms_copy_source
            )
        except AzureMissingResourceHttpError:
            pass

        with tempfile.TemporaryDirectory() as td:
            arcpath = os.path.join(td, "archive.zip")
            make_archive(source_path, arcpath)
            self._service.put_block_blob_from_path(
                container_name=self._container_name,
                blob_name=blob_name,
                file_path=arcpath,
                max_connections=4,
                progress_callback=progress_callback,
                max_retries=10)
            upload_done.wait() 
开发者ID:AdamStelmaszczyk,项目名称:learning2run,代码行数:41,代码来源:azure_utils.py

示例9: exists

# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureMissingResourceHttpError [as 别名]
def exists(self, blob_name):
        """Returns true if `blob_name` exists in container."""
        try:
            self._service.get_blob_properties(
                blob_name=blob_name,
                container_name=self._container_name
            )
            return True
        except AzureMissingResourceHttpError:
            return False 
开发者ID:AdamStelmaszczyk,项目名称:learning2run,代码行数:12,代码来源:azure_utils.py

示例10: get

# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureMissingResourceHttpError [as 别名]
def get(self, dest_path, blob_name, callback=None):
        """Download a file or directory to `dest_path` to azure blob `blob_name`.

        Warning! If directory is downloaded the `dest_path` is the parent directory.

        Upload progress can be traced by an optional callback.
        """
        download_done = Event()

        def progress_callback(current, total):
            if callback:
                callback(current, total)
            if current >= total:
                download_done.set()

        with tempfile.TemporaryDirectory() as td:
            arcpath = os.path.join(td, "archive.zip")
            for backup_blob_name in [blob_name, blob_name + '.backup']:
                try:
                    blob_size = self._service.get_blob_properties(
                        blob_name=backup_blob_name,
                        container_name=self._container_name
                    )['content-length']
                    if int(blob_size) > 0:
                        self._service.get_blob_to_path(
                            container_name=self._container_name,
                            blob_name=backup_blob_name,
                            file_path=arcpath,
                            max_connections=4,
                            progress_callback=progress_callback,
                            max_retries=10)
                        unpack_archive(arcpath, dest_path)
                        download_done.wait()
                        return True
                except AzureMissingResourceHttpError:
                    pass
        return False 
开发者ID:yenchenlin,项目名称:rl-attack-detection,代码行数:39,代码来源:azure_utils.py

示例11: _check_write_consistency

# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureMissingResourceHttpError [as 别名]
def _check_write_consistency(self):
        from azure.common import AzureMissingResourceHttpError
        for file_info in self.get_metadata('files_written'):
            try:
                afile = self.azure_service.get_file_properties(
                    self.share, file_info['filebase_path'], file_info['file_name'])
                file_size = afile.properties.content_length
                if str(file_size) != str(file_info['size']):
                    raise InconsistentWriteState(
                        'File {} has unexpected size. (expected {} - got {})'.format(
                            file_info['file_name'], file_info['size'], file_size)
                    )
            except AzureMissingResourceHttpError:
                raise InconsistentWriteState('Missing file {}'.format(file_info['file_name']))
        self.logger.info('Consistency check passed') 
开发者ID:scrapinghub,项目名称:exporters,代码行数:17,代码来源:azure_file_writer.py

示例12: delete

# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureMissingResourceHttpError [as 别名]
def delete(self, name):
        try:
            self.service.delete_blob(
                container_name=self.azure_container,
                blob_name=self._get_valid_path(name),
                timeout=self.timeout)
        except AzureMissingResourceHttpError:
            pass 
开发者ID:jschneier,项目名称:django-storages,代码行数:10,代码来源:azure_storage.py

示例13: get

# 需要导入模块: from azure import common [as 别名]
# 或者: from azure.common import AzureMissingResourceHttpError [as 别名]
def get(self, dest_path, blob_name, callback=None):
        """Download a file or directory to `dest_path` to azure blob `blob_name`.

        Warning! If directory is downloaded the `dest_path` is the parent directory.

        Upload progress can be traced by an optional callback.
        """
        download_done = Event()

        def progress_callback(current, total):
            if callback:
                callback(current, total)
            if current >= total:
                download_done.set()

        with tempfile.TemporaryDirectory() as td:
            arcpath = os.path.join(td, "archive.zip")
            for backup_blob_name in [blob_name, blob_name + '.backup']:
                try:
                    properties = self._service.get_blob_properties(
                        blob_name=backup_blob_name,
                        container_name=self._container_name
                    )
                    if hasattr(properties, 'properties'):
                        # Annoyingly, Azure has changed the API and this now returns a blob
                        # instead of it's properties with up-to-date azure package.
                        blob_size = properties.properties.content_length
                    else:
                        blob_size = properties['content-length']
                    if int(blob_size) > 0:
                        self._service.get_blob_to_path(
                            container_name=self._container_name,
                            blob_name=backup_blob_name,
                            file_path=arcpath,
                            max_connections=4,
                            progress_callback=progress_callback)
                        unpack_archive(arcpath, dest_path)
                        download_done.wait()
                        return True
                except AzureMissingResourceHttpError:
                    pass
        return False 
开发者ID:AdamStelmaszczyk,项目名称:learning2run,代码行数:44,代码来源:azure_utils.py


注:本文中的azure.common.AzureMissingResourceHttpError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。