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


Python BlobService.put_block_blob_from_text方法代码示例

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


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

示例1: StateThread

# 需要导入模块: from azure.storage.blob import BlobService [as 别名]
# 或者: from azure.storage.blob.BlobService import put_block_blob_from_text [as 别名]
def StateThread():
    
    global initializeNow
    global isPrimary
    while 1:
        try:
            currentHost = socket.gethostname()
            blob_service = BlobService(account_name=azureStorageAccountName, account_key=azureStorageAccountKey)
            if (initializeNow == True):
                initializeNow = False
                print("Initializing '" + currentHost + "' as primary.")
                newContents = currentHost
                blob_service.create_container(container)
                blob_service.put_block_blob_from_text(container, blob, newContents)

            while 1:
                print("Downloading current state.")
                currentContents = blob_service.get_blob_to_text(container, blob)
                if (currentContents==currentHost):
                    isPrimary = True
                    print("isPrimary = True")
                    # we have now received status, if second thread NOT running, start
                    if (t2.isAlive() == False):
                        t2.start()
                elif (currentContents!=currentHost and currentContents.count>0):
                    isPrimary = False
                    print("isPrimary = False")
                    # we have now received status, if second thread NOT running, start
                    if (t2.isAlive() == False):
                        t2.start()
                sleep(.1)
        except Exception as e:
            print ("Error in MainStateThread: " + e)
开发者ID:mattmcloughlin,项目名称:AzureCustomLoadBalancerProbe,代码行数:35,代码来源:LoadBalancerCustomProbeForPrimaryBackup.py

示例2: upload_from_text

# 需要导入模块: from azure.storage.blob import BlobService [as 别名]
# 或者: from azure.storage.blob.BlobService import put_block_blob_from_text [as 别名]
def upload_from_text(container, content):
    filename = str(uuid.uuid4())

    blob_service = BlobService(account_name=config.AZURE_STORAGE_NAME, account_key=config.AZURE_STORAGE_KEY)
    try:
        blob_service.put_block_blob_from_text(container, filename, content)
        return generate_blob_url(container, filename)
    except:
        return ""
开发者ID:hungys,项目名称:DockerVC,代码行数:11,代码来源:azure_storage.py

示例3: _getUrlForTestFile

# 需要导入模块: from azure.storage.blob import BlobService [as 别名]
# 或者: from azure.storage.blob.BlobService import put_block_blob_from_text [as 别名]
 def _getUrlForTestFile(cls, size=None):
     from toil.jobStores.azureJobStore import _fetchAzureAccountKey
     fileName = 'testfile_%s' % uuid.uuid4()
     containerName = cls._externalStore()
     url = 'wasb://%[email protected]%s.blob.core.windows.net/%s' % (containerName, cls.accountName, fileName)
     if size is None:
         return url
     blobService = BlobService(account_key=_fetchAzureAccountKey(cls.accountName),
                               account_name=cls.accountName)
     content = os.urandom(size)
     blobService.put_block_blob_from_text(containerName, fileName, content)
     return url, hashlib.md5(content).hexdigest()
开发者ID:guillermo-carrasco,项目名称:toil,代码行数:14,代码来源:jobStoreTest.py

示例4: azure_storage_writer

# 需要导入模块: from azure.storage.blob import BlobService [as 别名]
# 或者: from azure.storage.blob.BlobService import put_block_blob_from_text [as 别名]
class azure_storage_writer (object):
    """storage operation wrapper, desiged for writing logs to storage"""

    def __init__(self, account_name, account_key, container, prefix):
        self._blob = BlobService(account_name=account_name, account_key=account_key)
        self._cur_path = None
        self._buf = io.StringIO()
        self._prefix = prefix
        self._container = container
        self._blob.create_container(container)
        self._logger = create_timed_rotating_log()

    def write_log(self, entity):
        path = self._get_path(entity[0])
        if (self._cur_path == None):
            self._cur_path = path
        elif(self._cur_path != path):
            self._dump_buf_to_storage()
            self._buf.close()
            self._buf = io.StringIO()
            self._cur_path = path
        self._buf.write(entity[1])
        self._buf.write("\n")

    def close(self):
        if (self._cur_path != None):
            self._dump_buf_to_storage()
            self._buf.close()

    def _dump_buf_to_storage(self):
        self._logger.info("Begin dump to azure blob")
        loop = 0;
        while True:
            try:
                self._blob.put_block_blob_from_text(self._container,self._cur_path, self._buf.getvalue())
                break
            except AzureHttpError as e:
                self._logger.warn("Hit an AzureHttpError " + str(e))
                self._logger.warn("Retry times: {0}".format(loop))
                loop = loop + 1
                if loop >= 3:
                    raise e
            except Exception as e:
                self._logger.warn("Hit an Exception " + str(e))
                raise e
        self._logger.info("Dump to azure blob succeeded.")

    def _get_path(self, timestamp):
        #timestamp = int(timestamp)
        d = datetime.fromtimestamp(int(timestamp))
        part = str.format("logs-part-{}.txt", d.minute // 5)
        path_str = d.strftime('%Y-%m-%d/%H')
        return str.format("{}/{}/{}", self._prefix, path_str, part)
开发者ID:hwind,项目名称:hwindCode,代码行数:55,代码来源:btcc_trade_collector.py

示例5: _prepareTestFile

# 需要导入模块: from azure.storage.blob import BlobService [as 别名]
# 或者: from azure.storage.blob.BlobService import put_block_blob_from_text [as 别名]
    def _prepareTestFile(self, containerName, size=None):
        from toil.jobStores.azureJobStore import _fetchAzureAccountKey
        from azure.storage.blob import BlobService

        fileName = 'testfile_%s' % uuid.uuid4()
        url = 'wasb://%[email protected]%s.blob.core.windows.net/%s' % (containerName, self.accountName, fileName)
        if size is None:
            return url
        blobService = BlobService(account_key=_fetchAzureAccountKey(self.accountName),
                                  account_name=self.accountName)
        content = os.urandom(size)
        blobService.put_block_blob_from_text(containerName, fileName, content)
        return url, hashlib.md5(content).hexdigest()
开发者ID:python-toolbox,项目名称:fork_toil,代码行数:15,代码来源:jobStoreTest.py

示例6: print

# 需要导入模块: from azure.storage.blob import BlobService [as 别名]
# 或者: from azure.storage.blob.BlobService import put_block_blob_from_text [as 别名]
from azure.storage.blob import BlobService
import socket
import sys
 
azureStorageAccountName = "removed"
azureStorageAccountKey = "removed"
container = "ilbcp1"
blob = "currentprimary.dat"
retryCount = 0
while 1:
    # keep main thread running
    try:
        print ("Started.")
        currentHost = socket.gethostname()
        print ("Setting as primary...")
        blob_service = BlobService(account_name=azureStorageAccountName, account_key=azureStorageAccountKey)
        newContents = currentHost
        blob_service.create_container(container)
        blob_service.put_block_blob_from_text(container, blob, newContents)
        print ("Done.")
        sys.exit()
    except Exception as e:
        print("Exception!") # e ?
        retryCount = retryCount + 1
        if retryCount>5:
            print ("Permanently failed.")
            sys.exit()
开发者ID:mattmcloughlin,项目名称:AzureCustomLoadBalancerProbe,代码行数:29,代码来源:LoadBalancerCustomProbeForPrimaryBackup_MakePrimary.py


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