本文整理汇总了Python中azure.storage.CloudStorageAccount.create_block_blob_service方法的典型用法代码示例。如果您正苦于以下问题:Python CloudStorageAccount.create_block_blob_service方法的具体用法?Python CloudStorageAccount.create_block_blob_service怎么用?Python CloudStorageAccount.create_block_blob_service使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.storage.CloudStorageAccount
的用法示例。
在下文中一共展示了CloudStorageAccount.create_block_blob_service方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_service_no_key
# 需要导入模块: from azure.storage import CloudStorageAccount [as 别名]
# 或者: from azure.storage.CloudStorageAccount import create_block_blob_service [as 别名]
def test_create_service_no_key(self):
# Arrange
# Act
bad_account = CloudStorageAccount('', '')
with self.assertRaises(ValueError):
service = bad_account.create_block_blob_service()
示例2: emulator
# 需要导入模块: from azure.storage import CloudStorageAccount [as 别名]
# 或者: from azure.storage.CloudStorageAccount import create_block_blob_service [as 别名]
def emulator(self):
# With account
account = CloudStorageAccount(is_emulated=True)
client = account.create_block_blob_service()
# Directly
client = BlockBlobService(is_emulated=True)
示例3: sas_auth
# 需要导入模块: from azure.storage import CloudStorageAccount [as 别名]
# 或者: from azure.storage.CloudStorageAccount import create_block_blob_service [as 别名]
def sas_auth(self):
# With account
account = CloudStorageAccount(account_name="<account_name>", sas_token="<sas_token>")
client = account.create_block_blob_service()
# Directly
client = BlockBlobService(account_name="<account_name>", sas_token="<sas_token>")
示例4: key_auth
# 需要导入模块: from azure.storage import CloudStorageAccount [as 别名]
# 或者: from azure.storage.CloudStorageAccount import create_block_blob_service [as 别名]
def key_auth(self):
# With account
account = CloudStorageAccount(account_name="<account_name>", account_key="<account_key>")
client = account.create_block_blob_service()
# Directly
client = BlockBlobService(account_name="<account_name>", account_key="<account_key>")
示例5: test_create_account_sas_and_key
# 需要导入模块: from azure.storage import CloudStorageAccount [as 别名]
# 或者: from azure.storage.CloudStorageAccount import create_block_blob_service [as 别名]
def test_create_account_sas_and_key(self):
# Arrange
# Act
account = CloudStorageAccount(self.account_name, self.account_key, self.sas_token)
service = account.create_block_blob_service()
# Assert
self.validate_service(service, BlockBlobService)
示例6: public
# 需要导入模块: from azure.storage import CloudStorageAccount [as 别名]
# 或者: from azure.storage.CloudStorageAccount import create_block_blob_service [as 别名]
def public(self):
# This applies to the blob services only
# Public access must be enabled on the container or requests will fail
# With account
account = CloudStorageAccount(account_name="<account_name>")
client = account.create_block_blob_service()
# Directly
client = BlockBlobService(account_name="<account_name>")
示例7: test_create_account_emulated
# 需要导入模块: from azure.storage import CloudStorageAccount [as 别名]
# 或者: from azure.storage.CloudStorageAccount import create_block_blob_service [as 别名]
def test_create_account_emulated(self):
# Arrange
# Act
account = CloudStorageAccount(is_emulated=True)
service = account.create_block_blob_service()
# Assert
self.assertIsNotNone(service)
self.assertEqual(service.account_name, 'devstoreaccount1')
self.assertIsNotNone(service.account_key)
示例8: test_create_account_sas
# 需要导入模块: from azure.storage import CloudStorageAccount [as 别名]
# 或者: from azure.storage.CloudStorageAccount import create_block_blob_service [as 别名]
def test_create_account_sas(self):
# Arrange
# Act
sas_account = CloudStorageAccount(self.account_name, sas_token=self.sas_token)
service = sas_account.create_block_blob_service()
# Assert
self.assertIsNotNone(service)
self.assertEqual(service.account_name, self.account_name)
self.assertIsNone(service.account_key)
self.assertEqual(service.sas_token, self.sas_token)
示例9: str
# 需要导入模块: from azure.storage import CloudStorageAccount [as 别名]
# 或者: from azure.storage.CloudStorageAccount import create_block_blob_service [as 别名]
new_css = '.flair-' + str(position) + '{background-position: 0 -' + str(
height * position) + 'px}'
r.set_stylesheet(subreddit, css + new_css)
def log(message):
table_service.insert_entity('logs',
{'PartitionKey': 'flair', 'RowKey': str(datetime.datetime.now()),
'text': message})
print('[*] ' + message)
storage_account = CloudStorageAccount(storage_account_name, storage_account_key)
table_service = storage_account.create_table_service()
blob_service = storage_account.create_block_blob_service()
blob_service.create_container('images', public_access='container')
table_service.create_table('flair')
table_service.create_table('logs')
r = praw.Reddit(user_agent)
r.login(username, password)
r.config.decode_html_entities = True
while True:
for message in (m for m in r.get_unread(limit=None)):
log('received mesage from ' + message.author.name)
try:
file, text = get_flair_info(message)
if file in [blob.name for blob in list(blob_service.list_blobs('images'))]:
示例10: Passthrough
# 需要导入模块: from azure.storage import CloudStorageAccount [as 别名]
# 或者: from azure.storage.CloudStorageAccount import create_block_blob_service [as 别名]
class Passthrough(Operations):
def __init__(self, root):
self.root = root
print root
try:
import config as config
except:
raise ValueError('Please specify configuration settings in config.py.')
if config.IS_EMULATED:
self.account = CloudStorageAccount(is_emulated=True)
else:
# Note that account key and sas should not both be included
account_name = config.STORAGE_ACCOUNT_NAME
account_key = config.STORAGE_ACCOUNT_KEY
sas = config.SAS
self.account = CloudStorageAccount(account_name=account_name,
account_key=account_key,
sas_token=sas)
self.service = self.account.create_block_blob_service()
def _full_path(self, partial):
if partial.startswith("/"):
partial = partial[1:]
path = os.path.join(self.root, partial)
return path
def _get_container_reference(self, prefix='container'):
return '{}{}'.format(prefix, str(uuid.uuid4()).replace('-', ''))
def access(self, path, mode):
if debug:
print "access"
full_path = self._full_path(path)
#if not os.access(full_path, mode):
# pass#raise FuseOSError(errno.EACCES)
return 0
def chmod(self, path, mode):
pass
def chown(self, path, uid, gid):
pass
def getattr(self, path, fh=None):
if debug:
print "getattr " + path
isFolder = False
if len(path.split('/')) == 2:
isFolder = True
"""link_data = {
"st_ctime" : 1456615173,
"st_mtime" : 1456615173,
"st_nlink" : 2,
"st_mode" : 16893,
"st_size" : 2,
"st_gid" : 1000,
"st_uid" : 1000,
"st_atime" : time(),
}"""
folder_data = {
"st_ctime" : 1456615173,
"st_mtime" : 1456615173,
"st_nlink" : 2,
# "st_mode" : 16893,
"st_mode" : 16895,
"st_size" : 2,
"st_gid" : 1000,
"st_uid" : 1000,
"st_atime" : time(),
}
full_path = self._full_path(path)
try:
st = os.lstat(full_path)
print st
rdata = dict((key, getattr(st, key)) for key in ('st_atime', 'st_ctime', 'st_gid', 'st_mode', 'st_mtime', 'st_nlink', 'st_size', 'st_uid'))
except:
pass
#if os.path.isfile == True:
# return
if isFolder:
for container in list(self.service.list_containers()):
if container.name == path[1:]:
return folder_data
else:
"""import config as config
account_name = config.STORAGE_ACCOUNT_NAME
account_key = config.STORAGE_ACCOUNT_KEY"""
containername = path.split('/')[1]
filename = path.split('/')[2]
"""block_blob_service = BlockBlobService(account_name, account_key)
if os.path.isfile(full_path) == False:
fileSize = 1
#.........这里部分代码省略.........
示例11: AzureBlobObjectStore
# 需要导入模块: from azure.storage import CloudStorageAccount [as 别名]
# 或者: from azure.storage.CloudStorageAccount import create_block_blob_service [as 别名]
class AzureBlobObjectStore(ObjectStore):
"""
Object store that stores objects as blobs in an Azure Blob Container. A local
cache exists that is used as an intermediate location for files between
Galaxy and Azure.
"""
def __init__(self, config, config_xml):
if BlockBlobService is None:
raise Exception(NO_BLOBSERVICE_ERROR_MESSAGE)
super(AzureBlobObjectStore, self).__init__(config)
self.staging_path = self.config.file_path
self.transfer_progress = 0
self._parse_config_xml(config_xml)
self._configure_connection()
self.container_lease = self._get_container_lease()
# Clean cache only if value is set in galaxy.ini
if self.cache_size != -1:
# Convert GBs to bytes for comparison
self.cache_size = self.cache_size * 1073741824
# Helper for interruptable sleep
self.sleeper = Sleeper()
self.cache_monitor_thread = threading.Thread(target=self.__cache_monitor)
self.cache_monitor_thread.start()
log.info("Cache cleaner manager started")
###################
# Private Methods #
###################
# config_xml is an ElementTree object.
def _parse_config_xml(self, config_xml):
try:
auth_xml = config_xml.find('auth')
self.account_name = auth_xml.get('account_name')
self.account_key = auth_xml.get('account_key')
container_xml = config_xml.find('container')
self.container_name = container_xml.get('name')
self.max_chunk_size = int(container_xml.get('max_chunk_size', 250)) # currently unused
cache_xml = config_xml.find('cache')
self.cache_size = float(cache_xml.get('size', -1))
self.staging_path = cache_xml.get('path', self.config.object_store_cache_path)
for d_xml in config_xml.findall('extra_dir'):
self.extra_dirs[d_xml.get('type')] = d_xml.get('path')
log.debug("Object cache dir: %s", self.staging_path)
log.debug(" job work dir: %s", self.extra_dirs['job_work'])
except Exception:
# Toss it back up after logging, we can't continue loading at this point.
log.exception("Malformed ObjectStore Configuration XML -- unable to continue")
raise
def _configure_connection(self):
log.debug("Configuring Connection")
self.account = CloudStorageAccount(self.account_name, self.account_key)
self.service = self.account.create_block_blob_service()
def _get_container_lease(self):
""" Sometimes a handle to a container is not established right away so try
it a few times. Raise error is connection is not established. """
for i in range(5):
try:
self.service.break_container_lease(self.container_name)
container_lease = self.service.acquire_container_lease(self.container_name)
log.debug("Using azure blob store with container '%s'", self.container_name)
return container_lease
except AzureHttpError:
try:
log.debug("container not found, creating azure blob store container with name '%s'", self.container_name)
self.service.create_container(self.container_name)
container_lease = self.service.acquire_container_lease(self.container_name)
return container_lease
except AzureHttpError:
log.exception("Could not get container '%s', attempt %s/5", self.container_name, i + 1)
time.sleep(2)
# All the attempts have been exhausted and connection was not established,
# raise error
raise AzureHttpError
def _construct_path(self, obj, base_dir=None, dir_only=None, extra_dir=None, extra_dir_at_root=False, alt_name=None, obj_dir=False, **kwargs):
# extra_dir should never be constructed from provided data but just
# make sure there are no shenannigans afoot
if extra_dir and extra_dir != os.path.normpath(extra_dir):
log.warning('extra_dir is not normalized: %s', extra_dir)
raise ObjectInvalid("The requested object is invalid")
# ensure that any parent directory references in alt_name would not
# result in a path not contained in the directory path constructed here
if alt_name:
if not safe_relpath(alt_name):
log.warning('alt_name would locate path outside dir: %s', alt_name)
raise ObjectInvalid("The requested object is invalid")
# alt_name can contain parent directory references, but S3 will not
# follow them, so if they are valid we normalize them out
alt_name = os.path.normpath(alt_name)
rel_path = os.path.join(*directory_hash_id(obj.id))
#.........这里部分代码省略.........
示例12: CloudStorageAccount
# 需要导入模块: from azure.storage import CloudStorageAccount [as 别名]
# 或者: from azure.storage.CloudStorageAccount import create_block_blob_service [as 别名]
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from azure.storage import CloudStorageAccount
import config
account_name = config.STORAGE_ACCOUNT_NAME
account_key = config.STORAGE_ACCOUNT_KEY
account = CloudStorageAccount(account_name = account_name,
account_key = account_key)
service = account.create_block_blob_service()
# The last time a backup was dropped into the folder, it was named 'splunketccfg.tar'.
# This is (almost) always the one to restore.
container_name = 'backups'
restore_file_name = 'splunketccfg.tar'
OUTPUT_FILE = 'splunketccfg.tar'
exists = service.exists(container_name, restore_file_name)
if exists:
service.get_blob_to_path(container_name, restore_file_name, OUTPUT_FILE)
else:
print('Backup file does not exist')
示例13: SampleTest
# 需要导入模块: from azure.storage import CloudStorageAccount [as 别名]
# 或者: from azure.storage.CloudStorageAccount import create_block_blob_service [as 别名]
class SampleTest():
def __init__(self):
try:
import config as config
except:
raise ValueError('Please specify configuration settings in config.py.')
if config.IS_EMULATED:
self.account = CloudStorageAccount(is_emulated=True)
else:
# Note that account key and sas should not both be included
account_name = config.STORAGE_ACCOUNT_NAME
account_key = config.STORAGE_ACCOUNT_KEY
sas = config.SAS
self.account = CloudStorageAccount(account_name=account_name,
account_key=account_key,
sas_token=sas)
self.service = self.account.create_block_blob_service()
def test_container_samples(self):
container = ContainerSamples(self.account)
container.run_all_samples()
def test_block_blob_samples(self):
blob = BlockBlobSamples(self.account)
blob.run_all_samples()
def test_append_blob_samples(self):
blob = AppendBlobSamples(self.account)
blob.run_all_samples()
def test_page_blob_samples(self):
blob = PageBlobSamples(self.account)
blob.run_all_samples()
def list_containers(self):
self.service = self.account.create_block_blob_service()
containers = list(self.service.list_containers())
print('All containers in your account:')
for container in containers:
print(container.name)
def list_all_blobs_in_all_containers(self):
#self.service = self.account.create_block_blob_service()
containers = list(self.service.list_containers())
print('Full list:')
for container in containers:
print(container.name+':')
blobs = list(self.service.list_blobs(container.name))
for blob in blobs:
print(blob.name)
print('')
def test_get_put_blob(self):
import config as config
account_name = config.STORAGE_ACCOUNT_NAME
account_key = config.STORAGE_ACCOUNT_KEY
block_blob_service = BlockBlobService(account_name, account_key)
block_blob_service.create_blob_from_path(
'cont2',
'sunset.png',
'sunset.png',)
block_blob_service.get_blob_to_path('cont2', 'sunset.png', 'out-sunset.png')
示例14: StorageAccountTest
# 需要导入模块: from azure.storage import CloudStorageAccount [as 别名]
# 或者: from azure.storage.CloudStorageAccount import create_block_blob_service [as 别名]
class StorageAccountTest(StorageTestCase):
def setUp(self):
super(StorageAccountTest, self).setUp()
self.account_name = self.settings.STORAGE_ACCOUNT_NAME
self.account_key = self.settings.STORAGE_ACCOUNT_KEY
self.sas_token = '?sv=2015-04-05&st=2015-04-29T22%3A18%3A26Z&se=2015-04-30T02%3A23%3A26Z&sr=b&sp=rw&sip=168.1.5.60-168.1.5.70&spr=https&sig=Z%2FRHIX5Xcg0Mq2rqI3OlWTjEg2tYkboXr1P9ZUXDtkk%3D'
self.account = CloudStorageAccount(self.account_name, self.account_key)
#--Helpers-----------------------------------------------------------------
def validate_service(self, service, type):
self.assertIsNotNone(service)
self.assertIsInstance(service, type)
self.assertEqual(service.account_name, self.account_name)
self.assertEqual(service.account_key, self.account_key)
#--Test cases --------------------------------------------------------
def test_create_block_blob_service(self):
# Arrange
# Act
service = self.account.create_block_blob_service()
# Assert
self.validate_service(service, BlockBlobService)
def test_create_page_blob_service(self):
# Arrange
# Act
service = self.account.create_page_blob_service()
# Assert
self.validate_service(service, PageBlobService)
def test_create_append_blob_service(self):
# Arrange
# Act
service = self.account.create_append_blob_service()
# Assert
self.validate_service(service, AppendBlobService)
def test_create_table_service(self):
# Arrange
# Act
service = self.account.create_table_service()
# Assert
self.validate_service(service, TableService)
def test_create_queue_service(self):
# Arrange
# Act
service = self.account.create_queue_service()
# Assert
self.validate_service(service, QueueService)
def test_create_file_service(self):
# Arrange
# Act
service = self.account.create_file_service()
# Assert
self.validate_service(service, FileService)
def test_create_service_no_key(self):
# Arrange
# Act
bad_account = CloudStorageAccount('', '')
with self.assertRaises(ValueError):
service = bad_account.create_block_blob_service()
# Assert
def test_create_account_sas(self):
# Arrange
# Act
sas_account = CloudStorageAccount(self.account_name, sas_token=self.sas_token)
service = sas_account.create_block_blob_service()
# Assert
self.assertIsNotNone(service)
self.assertEqual(service.account_name, self.account_name)
self.assertIsNone(service.account_key)
self.assertEqual(service.sas_token, self.sas_token)
def test_create_account_sas_and_key(self):
# Arrange
# Act
account = CloudStorageAccount(self.account_name, self.account_key, self.sas_token)
service = account.create_block_blob_service()
#.........这里部分代码省略.........
示例15: _get_service
# 需要导入模块: from azure.storage import CloudStorageAccount [as 别名]
# 或者: from azure.storage.CloudStorageAccount import create_block_blob_service [as 别名]
def _get_service():
account_name = config.STORAGE_ACCOUNT_NAME
account_key = config.STORAGE_ACCOUNT_KEY
account = CloudStorageAccount(account_name = account_name, account_key = account_key)
service = account.create_block_blob_service()
return service