本文整理匯總了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)
示例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()
示例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)
示例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')
示例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()
示例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']
示例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.')
示例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()
示例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
示例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
示例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')
示例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
示例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