コード例 #1
0
    def get_blob(self, container_name, blob_name, snapshot=None, x_ms_range=None, x_ms_lease_id=None, x_ms_range_get_content_md5=None):
        '''
        Reads or downloads a blob from the system, including its metadata and properties. 
        
        container_name: the name of container to get the blob
        blob_name: the name of blob
        x_ms_range: Optional. Return only the bytes of the blob in the specified range.
        '''
        _validate_not_none('container_name', container_name)
        _validate_not_none('blob_name', blob_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(container_name) + '/' + _str(blob_name) + ''
        request.headers = [
            ('x-ms-range', _str_or_none(x_ms_range)),
            ('x-ms-lease-id', _str_or_none(x_ms_lease_id)),
            ('x-ms-range-get-content-md5', _str_or_none(x_ms_range_get_content_md5))
            ]
        request.query = [('snapshot', _str_or_none(snapshot))]
        request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
        request.headers = _update_storage_blob_header(request, self.account_name, self.account_key)
        response = self._perform_request(request)

        return _create_blob_result(response)
コード例 #2
0
    def merge_entity(self, table_name, partition_key, row_key, entity, content_type='application/atom+xml', if_match='*'):
        '''
        Updates an existing entity by updating the entity's properties. This operation does 
        not replace the existing entity as the Update Entity operation does.
        
        entity: Required. The entity object to insert. Can be a dict format or entity object.
        partition_key: PartitionKey of the entity.
        row_key: RowKey of the entity.
        Content-Type: this is required and has to be set to application/atom+xml
        '''
        _validate_not_none('table_name', table_name)
        _validate_not_none('partition_key', partition_key)
        _validate_not_none('row_key', row_key)
        _validate_not_none('entity', entity)
        _validate_not_none('content_type', content_type)
        request = HTTPRequest()
        request.method = 'MERGE'
        request.host = self._get_host()
        request.path = '/' + _str(table_name) + '(PartitionKey=\'' + _str(partition_key) + '\',RowKey=\'' + _str(row_key) + '\')'
        request.headers = [
            ('Content-Type', _str_or_none(content_type)),
            ('If-Match', _str_or_none(if_match))
            ]
        request.body = _get_request_body(convert_entity_to_xml(entity))
        request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
        request.headers = _update_storage_table_header(request)
        response = self._perform_request(request)

        return _parse_response_for_dict_filter(response, filter=['etag'])
コード例 #3
0
ファイル: blobservice.py プロジェクト: jacalata/optimization
 def set_blob_metadata(self,
                       container_name,
                       blob_name,
                       x_ms_meta_name_values=None,
                       x_ms_lease_id=None):
     '''
     Sets user-defined metadata for the specified blob as one or more name-value pairs.
     
     container_name: the name of container containing the blob
     blob_name: the name of blob
     x_ms_meta_name_values: Dict containing name and value pairs.
     '''
     _validate_not_none('container_name', container_name)
     _validate_not_none('blob_name', blob_name)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/' + _str(container_name) + '/' + _str(
         blob_name) + '?comp=metadata'
     request.headers = [('x-ms-meta-name-values', x_ms_meta_name_values),
                        ('x-ms-lease-id', _str_or_none(x_ms_lease_id))]
     request.path, request.query = _update_request_uri_query_local_storage(
         request, self.use_local_storage)
     request.headers = _update_storage_blob_header(request,
                                                   self.account_name,
                                                   self.account_key)
     response = self._perform_request(request)
コード例 #4
0
ファイル: blobservice.py プロジェクト: jacalata/optimization
    def get_blob(self,
                 container_name,
                 blob_name,
                 snapshot=None,
                 x_ms_range=None,
                 x_ms_lease_id=None,
                 x_ms_range_get_content_md5=None):
        '''
        Reads or downloads a blob from the system, including its metadata and properties. 
        
        container_name: the name of container to get the blob
        blob_name: the name of blob
        x_ms_range: Optional. Return only the bytes of the blob in the specified range.
        '''
        _validate_not_none('container_name', container_name)
        _validate_not_none('blob_name', blob_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(container_name) + '/' + _str(blob_name) + ''
        request.headers = [('x-ms-range', _str_or_none(x_ms_range)),
                           ('x-ms-lease-id', _str_or_none(x_ms_lease_id)),
                           ('x-ms-range-get-content-md5',
                            _str_or_none(x_ms_range_get_content_md5))]
        request.query = [('snapshot', _str_or_none(snapshot))]
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_blob_header(request,
                                                      self.account_name,
                                                      self.account_key)
        response = self._perform_request(request)

        return _create_blob_result(response)
コード例 #5
0
ファイル: blobservice.py プロジェクト: jacalata/optimization
    def get_blob_metadata(self,
                          container_name,
                          blob_name,
                          snapshot=None,
                          x_ms_lease_id=None):
        '''
        Returns all user-defined metadata for the specified blob or snapshot.
        
        container_name: the name of container containing the blob.
        blob_name: the name of blob to get metadata.
        '''
        _validate_not_none('container_name', container_name)
        _validate_not_none('blob_name', blob_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(container_name) + '/' + _str(
            blob_name) + '?comp=metadata'
        request.headers = [('x-ms-lease-id', _str_or_none(x_ms_lease_id))]
        request.query = [('snapshot', _str_or_none(snapshot))]
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_blob_header(request,
                                                      self.account_name,
                                                      self.account_key)
        response = self._perform_request(request)

        return _parse_response_for_dict_prefix(response, prefix='x-ms-meta')
コード例 #6
0
 def delete_entity(self,
                   table_name,
                   partition_key,
                   row_key,
                   content_type='application/atom+xml',
                   if_match='*'):
     '''
     Deletes an existing entity in a table.
     
     table_name: Table name.
     partition_key: PartitionKey of the entity.
     row_key: RowKey of the entity.
     content_type: Required. Must be set to application/atom+xml
     if_match:
         Optional. Specifies the condition for which the delete should be 
         performed. To force an unconditional delete, set to the wildcard 
         character (*). 
     '''
     _validate_not_none('table_name', table_name)
     _validate_not_none('partition_key', partition_key)
     _validate_not_none('row_key', row_key)
     _validate_not_none('content_type', content_type)
     _validate_not_none('if_match', if_match)
     request = HTTPRequest()
     request.method = 'DELETE'
     request.host = self._get_host()
     request.path = '/' + _str(table_name) + '(PartitionKey=\'' + _str(
         partition_key) + '\',RowKey=\'' + _str(row_key) + '\')'
     request.headers = [('Content-Type', _str_or_none(content_type)),
                        ('If-Match', _str_or_none(if_match))]
     request.path, request.query = _update_request_uri_query_local_storage(
         request, self.use_local_storage)
     request.headers = _update_storage_table_header(request)
     response = self._perform_request(request)
コード例 #7
0
    def put_message(self, queue_name, message_text, visibilitytimeout=None, messagettl=None):
        '''
        Adds a new message to the back of the message queue. A visibility timeout can 
        also be specified to make the message invisible until the visibility timeout 
        expires. A message must be in a format that can be included in an XML request 
        with UTF-8 encoding. The encoded message can be up to 64KB in size for versions 
        2011-08-18 and newer, or 8KB in size for previous versions.
        
        queue_name: name of the queue.
        visibilitytimeout: Optional. If specified, the request must be made using an 
        		x-ms-version of 2011-08-18 or newer.
        messagettl: Optional. Specifies the time-to-live interval for the message, 
        		in seconds. The maximum time-to-live allowed is 7 days. If this parameter
        		is omitted, the default time-to-live is 7 days.
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('message_text', message_text)
        request = HTTPRequest()
        request.method = 'POST'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + '/messages'
        request.query = [
            ('visibilitytimeout', _str_or_none(visibilitytimeout)),
            ('messagettl', _str_or_none(messagettl))
            ]
        request.body = _get_request_body('<?xml version="1.0" encoding="utf-8"?> \
<QueueMessage> \
    <MessageText>' + xml_escape(_str(message_text)) + '</MessageText> \
</QueueMessage>')
        request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
        request.headers = _update_storage_queue_header(request, self.account_name, self.account_key)
        response = self._perform_request(request)
コード例 #8
0
 def delete_rule(self, topic_name, subscription_name, rule_name, fail_not_exist=False):
     '''
     Deletes an existing rule.
     
     topic_name: Name of the topic.
     subscription_name: Name of the subscription.
     rule_name:
         Name of the rule to delete.  DEFAULT_RULE_NAME=$Default. 
         Use DEFAULT_RULE_NAME to delete default rule for the subscription.
     fail_not_exist:
         Specify whether throw exception when rule doesn't exist.
     '''
     _validate_not_none('topic_name', topic_name)
     _validate_not_none('subscription_name', subscription_name)
     _validate_not_none('rule_name', rule_name)
     request = HTTPRequest()
     request.method = 'DELETE'
     request.host = self._get_host()
     request.path = '/' + _str(topic_name) + '/subscriptions/' + _str(subscription_name) + '/rules/' + _str(rule_name) + ''
     request.path, request.query = _update_request_uri_query(request)
     request.headers = self._update_service_bus_header(request)
     if not fail_not_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_not_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
コード例 #9
0
    def peek_lock_subscription_message(self, topic_name, subscription_name, timeout='60'):
        '''
        This operation is used to atomically retrieve and lock a message for 
        processing. The message is guaranteed not to be delivered to other 
        receivers during the lock duration period specified in buffer 
        description. Once the lock expires, the message will be available to 
        other receivers (on the same subscription only) during the lock 
        duration period specified in the topic description. Once the lock 
        expires, the message will be available to other receivers. In order to 
        complete processing of the message, the receiver should issue a delete 
        command with the lock ID received from this operation. To abandon 
        processing of the message and unlock it for other receivers, an Unlock 
        Message command should be issued, or the lock duration period can 
        expire.
        
        topic_name: Name of the topic.
        subscription_name: Name of the subscription.
        timeout: Optional. The timeout parameter is expressed in seconds.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'POST'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + '/subscriptions/' + _str(subscription_name) + '/messages/head'
        request.query = [('timeout', _int_or_none(timeout))]
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _create_message(response, self)
コード例 #10
0
ファイル: tableservice.py プロジェクト: jacalata/optimization
    def insert_or_merge_entity(self,
                               table_name,
                               partition_key,
                               row_key,
                               entity,
                               content_type='application/atom+xml'):
        '''
        Merges an existing entity or inserts a new entity if it does not exist in the table. 
        Because this operation can insert or update an entity, it is also known as an "upsert"
        operation.
        
        entity: Required. The entity object to insert. Could be a dict format or entity object.
        partition_key: PartitionKey of the entity.
        row_key: RowKey of the entity.
        Content-Type: this is required and has to be set to application/atom+xml
        '''
        _validate_not_none('table_name', table_name)
        _validate_not_none('partition_key', partition_key)
        _validate_not_none('row_key', row_key)
        _validate_not_none('entity', entity)
        _validate_not_none('content_type', content_type)
        request = HTTPRequest()
        request.method = 'MERGE'
        request.host = self._get_host()
        request.path = '/' + _str(table_name) + '(PartitionKey=\'' + _str(
            partition_key) + '\',RowKey=\'' + _str(row_key) + '\')'
        request.headers = [('Content-Type', _str_or_none(content_type))]
        request.body = _get_request_body(convert_entity_to_xml(entity))
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_table_header(request)
        response = self._perform_request(request)

        return _parse_response_for_dict_filter(response, filter=['etag'])
コード例 #11
0
ファイル: tableservice.py プロジェクト: jacalata/optimization
    def merge_entity(self,
                     table_name,
                     partition_key,
                     row_key,
                     entity,
                     content_type='application/atom+xml',
                     if_match='*'):
        '''
        Updates an existing entity by updating the entity's properties. This operation does 
        not replace the existing entity as the Update Entity operation does.
        
        entity: Required. The entity object to insert. Can be a dict format or entity object.
        partition_key: PartitionKey of the entity.
        row_key: RowKey of the entity.
        Content-Type: this is required and has to be set to application/atom+xml
        '''
        _validate_not_none('table_name', table_name)
        _validate_not_none('partition_key', partition_key)
        _validate_not_none('row_key', row_key)
        _validate_not_none('entity', entity)
        _validate_not_none('content_type', content_type)
        request = HTTPRequest()
        request.method = 'MERGE'
        request.host = self._get_host()
        request.path = '/' + _str(table_name) + '(PartitionKey=\'' + _str(
            partition_key) + '\',RowKey=\'' + _str(row_key) + '\')'
        request.headers = [('Content-Type', _str_or_none(content_type)),
                           ('If-Match', _str_or_none(if_match))]
        request.body = _get_request_body(convert_entity_to_xml(entity))
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_table_header(request)
        response = self._perform_request(request)

        return _parse_response_for_dict_filter(response, filter=['etag'])
コード例 #12
0
    def get_entity(self, table_name, partition_key, row_key, select=''):
        '''
        Get an entity in a table; includes the $select options.

        partition_key:
            PartitionKey of the entity.
        row_key:
            RowKey of the entity.
        select:
            Property names to select.
        '''
        _validate_not_none('table_name', table_name)
        _validate_not_none('partition_key', partition_key)
        _validate_not_none('row_key', row_key)
        _validate_not_none('select', select)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(table_name) + \
            '(PartitionKey=\'' + _str(partition_key) + \
            '\',RowKey=\'' + \
            _str(row_key) + '\')?$select=' + \
            _str(select) + ''
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_table_header(request)
        response = self._perform_request(request)

        return _convert_response_to_entity(response)
コード例 #13
0
ファイル: blobservice.py プロジェクト: jacalata/optimization
    def lease_blob(self,
                   container_name,
                   blob_name,
                   x_ms_lease_action,
                   x_ms_lease_id=None):
        '''
        Establishes and manages a one-minute lock on a blob for write operations.
        
        container_name: the name of container.
        blob_name: the name of blob
        x_ms_lease_id: Any GUID format string
        x_ms_lease_action: Required. Possible values: acquire|renew|release|break
        '''
        _validate_not_none('container_name', container_name)
        _validate_not_none('blob_name', blob_name)
        _validate_not_none('x_ms_lease_action', x_ms_lease_action)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(container_name) + '/' + _str(
            blob_name) + '?comp=lease'
        request.headers = [('x-ms-lease-id', _str_or_none(x_ms_lease_id)),
                           ('x-ms-lease-action',
                            _str_or_none(x_ms_lease_action))]
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_blob_header(request,
                                                      self.account_name,
                                                      self.account_key)
        response = self._perform_request(request)

        return _parse_response_for_dict_filter(response,
                                               filter=['x-ms-lease-id'])
コード例 #14
0
    def delete_rule(self, topic_name, subscription_name, rule_name,
                    fail_not_exist=False):
        '''
        Deletes an existing rule.

        topic_name: Name of the topic.
        subscription_name: Name of the subscription.
        rule_name:
            Name of the rule to delete.  DEFAULT_RULE_NAME=$Default.
            Use DEFAULT_RULE_NAME to delete default rule for the subscription.
        fail_not_exist:
            Specify whether throw exception when rule doesn't exist.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        _validate_not_none('rule_name', rule_name)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + '/subscriptions/' + \
            _str(subscription_name) + \
            '/rules/' + _str(rule_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_not_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_not_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
コード例 #15
0
    def delete_queue_message(self, queue_name, sequence_number, lock_token):
        '''
        Completes processing on a locked message and delete it from the queue.
        This operation should only be called after processing a previously
        locked message is successful to maintain At-Least-Once delivery
        assurances.

        queue_name: Name of the queue.
        sequence_number:
            The sequence number of the message to be deleted as returned in
            BrokerProperties['SequenceNumber'] by the Peek Message operation.
        lock_token:
            The ID of the lock as returned by the Peek Message operation in
            BrokerProperties['LockToken']
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('sequence_number', sequence_number)
        _validate_not_none('lock_token', lock_token)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + \
                       '/messages/' + _str(sequence_number) + \
                       '/' + _str(lock_token) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        self._perform_request(request)
コード例 #16
0
ファイル: tableservice.py プロジェクト: wryi/RCMS
    def get_entity(self, table_name, partition_key, row_key, select=''):
        '''
        Get an entity in a table; includes the $select options.

        partition_key: PartitionKey of the entity.
        row_key: RowKey of the entity.
        select: Property names to select.
        '''
        _validate_not_none('table_name', table_name)
        _validate_not_none('partition_key', partition_key)
        _validate_not_none('row_key', row_key)
        _validate_not_none('select', select)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(table_name) + \
            '(PartitionKey=\'' + _str(partition_key) + \
            '\',RowKey=\'' + \
            _str(row_key) + '\')?$select=' + \
            _str(select) + ''
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_table_header(request)
        response = self._perform_request(request)

        return _convert_response_to_entity(response)
コード例 #17
0
    def delete_queue_message(self, queue_name, sequence_number, lock_token):
        '''
        Completes processing on a locked message and delete it from the queue.
        This operation should only be called after processing a previously
        locked message is successful to maintain At-Least-Once delivery
        assurances.

        queue_name:
            Name of the queue.
        sequence_number:
            The sequence number of the message to be deleted as returned in
            BrokerProperties['SequenceNumber'] by the Peek Message operation.
        lock_token:
            The ID of the lock as returned by the Peek Message operation in
            BrokerProperties['LockToken']
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('sequence_number', sequence_number)
        _validate_not_none('lock_token', lock_token)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + \
                       '/messages/' + _str(sequence_number) + \
                       '/' + _str(lock_token) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        self._perform_request(request)
コード例 #18
0
    def delete_message(self, queue_name, message_id, popreceipt):
        '''
        Deletes the specified message.

        queue_name:
            Name of the queue.
        message_id:
            Message to delete.
        popreceipt:
            Required. A valid pop receipt value returned from an earlier call
            to the Get Messages or Update Message operation.
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('message_id', message_id)
        _validate_not_none('popreceipt', popreceipt)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + \
            _str(queue_name) + '/messages/' + _str(message_id) + ''
        request.query = [('popreceipt', _str_or_none(popreceipt))]
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_queue_header(
            request, self.authentication)
        self._perform_request(request)
コード例 #19
0
ファイル: blobservice.py プロジェクト: jacalata/optimization
    def get_block_list(self,
                       container_name,
                       blob_name,
                       snapshot=None,
                       blocklisttype=None,
                       x_ms_lease_id=None):
        '''
        Retrieves the list of blocks that have been uploaded as part of a block blob.
        
        container_name: the name of container.
        blob_name: the name of blob
        snapshot: Optional. Datetime to determine the time to retrieve the blocks.
        blocklisttype: Specifies whether to return the list of committed blocks, the 
        		list of uncommitted blocks, or both lists together. Valid values are 
        		committed, uncommitted, or all.
        '''
        _validate_not_none('container_name', container_name)
        _validate_not_none('blob_name', blob_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(container_name) + '/' + _str(
            blob_name) + '?comp=blocklist'
        request.headers = [('x-ms-lease-id', _str_or_none(x_ms_lease_id))]
        request.query = [('snapshot', _str_or_none(snapshot)),
                         ('blocklisttype', _str_or_none(blocklisttype))]
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_blob_header(request,
                                                      self.account_name,
                                                      self.account_key)
        response = self._perform_request(request)

        return convert_response_to_block_list(response)
コード例 #20
0
    def unlock_queue_message(self, queue_name, sequence_number, lock_token):
        '''
        Unlocks a message for processing by other receivers on a given
        subscription. This operation deletes the lock object, causing the
        message to be unlocked. A message must have first been locked by a
        receiver before this operation is called.

        queue_name:
            Name of the queue.
        sequence_number:
            The sequence number of the message to be unlocked as returned in
            BrokerProperties['SequenceNumber'] by the Peek Message operation.
        lock_token:
            The ID of the lock as returned by the Peek Message operation in
            BrokerProperties['LockToken']
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('sequence_number', sequence_number)
        _validate_not_none('lock_token', lock_token)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + \
                       '/messages/' + _str(sequence_number) + \
                       '/' + _str(lock_token) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        self._perform_request(request)
コード例 #21
0
 def create_rule(self, topic_name, subscription_name, rule_name, rule=None, fail_on_exist=False):
     '''
     Creates a new rule. Once created, this rule's resource manifest is immutable.
     
     topic_name: the name of the topic
     subscription_name: the name of the subscription
     rule_name: name of the rule.
     fail_on_exist: specify whether to throw an exception when the rule exists.
     '''
     _validate_not_none('topic_name', topic_name)
     _validate_not_none('subscription_name', subscription_name)
     _validate_not_none('rule_name', rule_name)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/' + _str(topic_name) + '/subscriptions/' + _str(subscription_name) + '/rules/' + _str(rule_name) + ''
     request.body = _get_request_body(convert_rule_to_xml(rule))
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
     if not fail_on_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_on_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
コード例 #22
0
    def lease_blob(self, container_name, blob_name, x_ms_lease_action, x_ms_lease_id=None):
        '''
        Establishes and manages a one-minute lock on a blob for write operations.
        
        container_name: the name of container.
        blob_name: the name of blob
        x_ms_lease_id: Any GUID format string
        x_ms_lease_action: Required. Possible values: acquire|renew|release|break
        '''
        _validate_not_none('container_name', container_name)
        _validate_not_none('blob_name', blob_name)
        _validate_not_none('x_ms_lease_action', x_ms_lease_action)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(container_name) + '/' + _str(blob_name) + '?comp=lease'
        request.headers = [
            ('x-ms-lease-id', _str_or_none(x_ms_lease_id)),
            ('x-ms-lease-action', _str_or_none(x_ms_lease_action))
            ]
        request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
        request.headers = _update_storage_blob_header(request, self.account_name, self.account_key)
        response = self._perform_request(request)

        return _parse_response_for_dict_filter(response, filter=['x-ms-lease-id'])
コード例 #23
0
 def _get_cloud_services_path(self, cloud_service_id, resource=None, name=None):
     path = '/' + self.subscription_id + '/cloudservices/' + cloud_service_id
     if resource is not None:
         path += '/resources/' + _str(resource)
     if name is not None:
         path += '/' + _str(name)
     return path
コード例 #24
0
    def snapshot_blob(self, container_name, blob_name, x_ms_meta_name_values=None, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None, x_ms_lease_id=None):
        '''
        Creates a read-only snapshot of a blob.
        
        container_name: the name of container.
        blob_name: the name of blob
        x_ms_meta_name_values: Optional. Dict containing name and value pairs.
        if_modified_since: Optional. Datetime string.
        if_unmodified_since: DateTime string.
        if_match: Optional. snapshot the blob only if its ETag value matches the value specified. 
        if_none_match: Optional. An ETag value
        x_ms_lease_id: Optional. If this header is specified, the operation will be performed 
                  only if both of the following conditions are met. 
        			1. The blob's lease is currently active
        			2. The lease ID specified in the request matches that of the blob.
        '''
        _validate_not_none('container_name', container_name)
        _validate_not_none('blob_name', blob_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(container_name) + '/' + _str(blob_name) + '?comp=snapshot'
        request.headers = [
            ('x-ms-meta-name-values', x_ms_meta_name_values),
            ('If-Modified-Since', _str_or_none(if_modified_since)),
            ('If-Unmodified-Since', _str_or_none(if_unmodified_since)),
            ('If-Match', _str_or_none(if_match)),
            ('If-None-Match', _str_or_none(if_none_match)),
            ('x-ms-lease-id', _str_or_none(x_ms_lease_id))
            ]
        request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
        request.headers = _update_storage_blob_header(request, self.account_name, self.account_key)
        response = self._perform_request(request)

        return _parse_response_for_dict_filter(response, filter=['x-ms-snapshot', 'etag', 'last-modified'])
コード例 #25
0
 def set_blob_properties(self, container_name, blob_name, x_ms_blob_cache_control=None, x_ms_blob_content_type=None, x_ms_blob_content_md5=None, x_ms_blob_content_encoding=None, x_ms_blob_content_language=None, x_ms_lease_id=None):
     '''
     Sets system properties on the blob.
     
     x_ms_blob_cache_control: Optional. Modifies the cache control string for the blob. 
     x_ms_blob_content_type: Optional. Sets the blob's content type. 
     x_ms_blob_content_md5: Optional. Sets the blob's MD5 hash.
     x_ms_blob_content_encoding: Optional. Sets the blob's content encoding.
     x_ms_blob_content_language: Optional. Sets the blob's content language.
     x_ms_lease_id: Required if the blob has an active lease.
     '''
     _validate_not_none('container_name', container_name)
     _validate_not_none('blob_name', blob_name)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/' + _str(container_name) + '/' + _str(blob_name) + '?comp=properties'
     request.headers = [
         ('x-ms-blob-cache-control', _str_or_none(x_ms_blob_cache_control)),
         ('x-ms-blob-content-type', _str_or_none(x_ms_blob_content_type)),
         ('x-ms-blob-content-md5', _str_or_none(x_ms_blob_content_md5)),
         ('x-ms-blob-content-encoding', _str_or_none(x_ms_blob_content_encoding)),
         ('x-ms-blob-content-language', _str_or_none(x_ms_blob_content_language)),
         ('x-ms-lease-id', _str_or_none(x_ms_lease_id))
         ]
     request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
     request.headers = _update_storage_blob_header(request, self.account_name, self.account_key)
     response = self._perform_request(request)
コード例 #26
0
ファイル: blobservice.py プロジェクト: jacalata/optimization
 def delete_blob(self,
                 container_name,
                 blob_name,
                 snapshot=None,
                 x_ms_lease_id=None):
     '''
     Marks the specified blob or snapshot for deletion. The blob is later deleted 
     during garbage collection.
     
     To mark a specific snapshot for deletion provide the date/time of the snapshot via
     the snapshot parameter.
     
     container_name: the name of container.
     blob_name: the name of blob
     x_ms_lease_id: Optional. If this header is specified, the operation will be performed 
     		only if both of the following conditions are met. 
     		1. The blob's lease is currently active
     		2. The lease ID specified in the request matches that of the blob.
     '''
     _validate_not_none('container_name', container_name)
     _validate_not_none('blob_name', blob_name)
     request = HTTPRequest()
     request.method = 'DELETE'
     request.host = self._get_host()
     request.path = '/' + _str(container_name) + '/' + _str(blob_name) + ''
     request.headers = [('x-ms-lease-id', _str_or_none(x_ms_lease_id))]
     request.query = [('snapshot', _str_or_none(snapshot))]
     request.path, request.query = _update_request_uri_query_local_storage(
         request, self.use_local_storage)
     request.headers = _update_storage_blob_header(request,
                                                   self.account_name,
                                                   self.account_key)
     response = self._perform_request(request)
コード例 #27
0
    def get_rule(self, topic_name, subscription_name, rule_name):
        '''
        Retrieves the description for the specified rule.

        topic_name:
            Name of the topic.
        subscription_name:
            Name of the subscription.
        rule_name:
            Name of the rule.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        _validate_not_none('rule_name', rule_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + '/subscriptions/' + \
            _str(subscription_name) + \
            '/rules/' + _str(rule_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _convert_response_to_rule(response)
コード例 #28
0
    def read_delete_subscription_message(self, topic_name, subscription_name,
                                         timeout='60'):
        '''
        Read and delete a message from a subscription as an atomic operation.
        This operation should be used when a best-effort guarantee is
        sufficient for an application; that is, using this operation it is
        possible for messages to be lost if processing fails.

        topic_name:
            Name of the topic.
        subscription_name:
            Name of the subscription.
        timeout:
            Optional. The timeout parameter is expressed in seconds.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + \
                       '/subscriptions/' + _str(subscription_name) + \
                       '/messages/head'
        request.query = [('timeout', _int_or_none(timeout))]
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _create_message(response, self)
コード例 #29
0
 def delete_message(self, queue_name, message_id, popreceipt):
     '''
     Deletes the specified message.
     
     queue_name: Name of the queue.
     message_id: Message to delete.
     popreceipt:
         Required. A valid pop receipt value returned from an earlier call 
         to the Get Messages or Update Message operation.
     '''
     _validate_not_none('queue_name', queue_name)
     _validate_not_none('message_id', message_id)
     _validate_not_none('popreceipt', popreceipt)
     request = HTTPRequest()
     request.method = 'DELETE'
     request.host = self._get_host()
     request.path = '/' + _str(queue_name) + '/messages/' + _str(
         message_id) + ''
     request.query = [('popreceipt', _str_or_none(popreceipt))]
     request.path, request.query = _update_request_uri_query_local_storage(
         request, self.use_local_storage)
     request.headers = _update_storage_queue_header(request,
                                                    self.account_name,
                                                    self.account_key)
     response = self._perform_request(request)
コード例 #30
0
    def peek_lock_subscription_message(self, topic_name, subscription_name,
                                       timeout='60'):
        '''
        This operation is used to atomically retrieve and lock a message for
        processing. The message is guaranteed not to be delivered to other
        receivers during the lock duration period specified in buffer
        description. Once the lock expires, the message will be available to
        other receivers (on the same subscription only) during the lock
        duration period specified in the topic description. Once the lock
        expires, the message will be available to other receivers. In order to
        complete processing of the message, the receiver should issue a delete
        command with the lock ID received from this operation. To abandon
        processing of the message and unlock it for other receivers, an Unlock
        Message command should be issued, or the lock duration period can
        expire.

        topic_name: Name of the topic.
        subscription_name: Name of the subscription.
        timeout: Optional. The timeout parameter is expressed in seconds.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'POST'
        request.host = self._get_host()
        request.path = '/' + \
            _str(topic_name) + '/subscriptions/' + \
            _str(subscription_name) + '/messages/head'
        request.query = [('timeout', _int_or_none(timeout))]
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _create_message(response, self)
コード例 #31
0
    def get_rule(self, topic_name, subscription_name, rule_name):
        '''
        Retrieves the description for the specified rule.

        topic_name:
            Name of the topic.
        subscription_name:
            Name of the subscription.
        rule_name:
            Name of the rule.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        _validate_not_none('rule_name', rule_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + '/subscriptions/' + \
            _str(subscription_name) + \
            '/rules/' + _str(rule_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _convert_response_to_rule(response)
コード例 #32
0
    def unlock_queue_message(self, queue_name, sequence_number, lock_token):
        '''
        Unlocks a message for processing by other receivers on a given
        subscription. This operation deletes the lock object, causing the
        message to be unlocked. A message must have first been locked by a
        receiver before this operation is called.

        queue_name: Name of the queue.
        sequence_number:
            The sequence number of the message to be unlocked as returned in
            BrokerProperties['SequenceNumber'] by the Peek Message operation.
        lock_token:
            The ID of the lock as returned by the Peek Message operation in
            BrokerProperties['LockToken']
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('sequence_number', sequence_number)
        _validate_not_none('lock_token', lock_token)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + \
                       '/messages/' + _str(sequence_number) + \
                       '/' + _str(lock_token) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        self._perform_request(request)
コード例 #33
0
    def delete_subscription(self, topic_name, subscription_name,
                            fail_not_exist=False):
        '''
        Deletes an existing subscription.

        topic_name:
            Name of the topic.
        subscription_name:
            Name of the subscription to delete.
        fail_not_exist:
            Specify whether to throw an exception when the subscription
            doesn't exist.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + \
            _str(topic_name) + '/subscriptions/' + _str(subscription_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_not_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_not_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
コード例 #34
0
    def read_delete_subscription_message(self,
                                         topic_name,
                                         subscription_name,
                                         timeout='60'):
        '''
        Read and delete a message from a subscription as an atomic operation.
        This operation should be used when a best-effort guarantee is
        sufficient for an application; that is, using this operation it is
        possible for messages to be lost if processing fails.

        topic_name: Name of the topic.
        subscription_name: Name of the subscription.
        timeout: Optional. The timeout parameter is expressed in seconds.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + \
                       '/subscriptions/' + _str(subscription_name) + \
                       '/messages/head'
        request.query = [('timeout', _int_or_none(timeout))]
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _create_message(response, self)
コード例 #35
0
 def delete_blob(self, container_name, blob_name, snapshot=None, x_ms_lease_id=None):
     '''
     Marks the specified blob or snapshot for deletion. The blob is later deleted 
     during garbage collection.
     
     To mark a specific snapshot for deletion provide the date/time of the snapshot via
     the snapshot parameter.
     
     container_name: the name of container.
     blob_name: the name of blob
     x_ms_lease_id: Optional. If this header is specified, the operation will be performed 
     		only if both of the following conditions are met. 
     		1. The blob's lease is currently active
     		2. The lease ID specified in the request matches that of the blob.
     '''
     _validate_not_none('container_name', container_name)
     _validate_not_none('blob_name', blob_name)
     request = HTTPRequest()
     request.method = 'DELETE'
     request.host = self._get_host()
     request.path = '/' + _str(container_name) + '/' + _str(blob_name) + ''
     request.headers = [('x-ms-lease-id', _str_or_none(x_ms_lease_id))]
     request.query = [('snapshot', _str_or_none(snapshot))]
     request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
     request.headers = _update_storage_blob_header(request, self.account_name, self.account_key)
     response = self._perform_request(request)
コード例 #36
0
    def create_subscription(self,
                            topic_name,
                            subscription_name,
                            subscription=None,
                            fail_on_exist=False):
        '''
        Creates a new subscription. Once created, this subscription resource
        manifest is immutable.

        topic_name: Name of the topic.
        subscription_name: Name of the subscription.
        fail_on_exist:
            Specify whether throw exception when subscription exists.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + \
            _str(topic_name) + '/subscriptions/' + _str(subscription_name) + ''
        request.body = _get_request_body(
            _convert_subscription_to_xml(subscription))
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_on_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
コード例 #37
0
    def delete_subscription(self,
                            topic_name,
                            subscription_name,
                            fail_not_exist=False):
        '''
        Deletes an existing subscription.

        topic_name: Name of the topic.
        subscription_name: Name of the subscription to delete.
        fail_not_exist:
            Specify whether to throw an exception when the subscription
            doesn't exist.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + \
            _str(topic_name) + '/subscriptions/' + _str(subscription_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_not_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_not_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
コード例 #38
0
    def insert_or_merge_entity(self, table_name, partition_key, row_key, entity, content_type='application/atom+xml'):
        '''
        Merges an existing entity or inserts a new entity if it does not exist 
        in the table. Because this operation can insert or update an entity, 
        it is also known as an "upsert" operation.
        
        table_name: Table name.
        partition_key: PartitionKey of the entity.
        row_key: RowKey of the entity.
        entity: 
            Required. The entity object to insert. Could be a dict format or 
            entity object.
        content_type: Required. Must be set to application/atom+xml
        '''
        _validate_not_none('table_name', table_name)
        _validate_not_none('partition_key', partition_key)
        _validate_not_none('row_key', row_key)
        _validate_not_none('entity', entity)
        _validate_not_none('content_type', content_type)
        request = HTTPRequest()
        request.method = 'MERGE'
        request.host = self._get_host()
        request.path = '/' + _str(table_name) + '(PartitionKey=\'' + _str(partition_key) + '\',RowKey=\'' + _str(row_key) + '\')'
        request.headers = [('Content-Type', _str_or_none(content_type))]
        request.body = _get_request_body(_convert_entity_to_xml(entity))
        request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
        request.headers = _update_storage_table_header(request)
        response = self._perform_request(request)

        return _parse_response_for_dict_filter(response, filter=['etag'])
コード例 #39
0
    def create_subscription(self, topic_name, subscription_name,
                            subscription=None, fail_on_exist=False):
        '''
        Creates a new subscription. Once created, this subscription resource
        manifest is immutable.

        topic_name:
            Name of the topic.
        subscription_name:
            Name of the subscription.
        fail_on_exist:
            Specify whether throw exception when subscription exists.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + \
            _str(topic_name) + '/subscriptions/' + _str(subscription_name) + ''
        request.body = _get_request_body(
            _convert_subscription_to_xml(subscription))
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_on_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
コード例 #40
0
 def delete_entity(self, table_name, partition_key, row_key, content_type='application/atom+xml', if_match='*'):
     '''
     Deletes an existing entity in a table.
     
     table_name: Table name.
     partition_key: PartitionKey of the entity.
     row_key: RowKey of the entity.
     content_type: Required. Must be set to application/atom+xml
     if_match:
         Optional. Specifies the condition for which the delete should be 
         performed. To force an unconditional delete, set to the wildcard 
         character (*). 
     '''
     _validate_not_none('table_name', table_name)
     _validate_not_none('partition_key', partition_key)
     _validate_not_none('row_key', row_key)
     _validate_not_none('content_type', content_type)
     _validate_not_none('if_match', if_match)
     request = HTTPRequest()
     request.method = 'DELETE'
     request.host = self._get_host()
     request.path = '/' + _str(table_name) + '(PartitionKey=\'' + _str(partition_key) + '\',RowKey=\'' + _str(row_key) + '\')'
     request.headers = [
         ('Content-Type', _str_or_none(content_type)),
         ('If-Match', _str_or_none(if_match))
         ]
     request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
     request.headers = _update_storage_table_header(request)
     response = self._perform_request(request)
コード例 #41
0
    def get_page_ranges(self, container_name, blob_name, snapshot=None, range=None, x_ms_range=None, x_ms_lease_id=None):
        '''
        Retrieves the page ranges for a blob.
        
        container_name: the name of container.
        blob_name: the name of blob
        _ms_range: Optional. Specifies the range of bytes to be written as a page. Both the start
        		and end of the range must be specified. Must be in format: bytes=startByte-endByte.
        		Given that pages must be aligned with 512-byte boundaries, the start offset must be
        		a modulus of 512 and the end offset must be a modulus of 512-1. Examples of valid
        		byte ranges are 0-511, 512-1023, etc.
        x_ms_lease_id: Required if the blob has an active lease. To perform this operation on a blob
        		 with an active lease, specify the valid lease ID for this header.
        '''
        _validate_not_none('container_name', container_name)
        _validate_not_none('blob_name', blob_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(container_name) + '/' + _str(blob_name) + '?comp=pagelist'
        request.headers = [
            ('Range', _str_or_none(range)),
            ('x-ms-range', _str_or_none(x_ms_range)),
            ('x-ms-lease-id', _str_or_none(x_ms_lease_id))
            ]
        request.query = [('snapshot', _str_or_none(snapshot))]
        request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
        request.headers = _update_storage_blob_header(request, self.account_name, self.account_key)
        response = self._perform_request(request)

        return _parse_simple_list(response, PageList, PageRange, "page_ranges")
コード例 #42
0
    def get_block_list(self, container_name, blob_name, snapshot=None, blocklisttype=None, x_ms_lease_id=None):
        '''
        Retrieves the list of blocks that have been uploaded as part of a block blob.
        
        container_name: the name of container.
        blob_name: the name of blob
        snapshot: Optional. Datetime to determine the time to retrieve the blocks.
        blocklisttype: Specifies whether to return the list of committed blocks, the 
        		list of uncommitted blocks, or both lists together. Valid values are 
        		committed, uncommitted, or all.
        '''
        _validate_not_none('container_name', container_name)
        _validate_not_none('blob_name', blob_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(container_name) + '/' + _str(blob_name) + '?comp=blocklist'
        request.headers = [('x-ms-lease-id', _str_or_none(x_ms_lease_id))]
        request.query = [
            ('snapshot', _str_or_none(snapshot)),
            ('blocklisttype', _str_or_none(blocklisttype))
            ]
        request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
        request.headers = _update_storage_blob_header(request, self.account_name, self.account_key)
        response = self._perform_request(request)

        return convert_response_to_block_list(response)
コード例 #43
0
 def put_block(self, container_name, blob_name, block, blockid, content_md5=None, x_ms_lease_id=None):
     '''
     Creates a new block to be committed as part of a blob.
     
     container_name: the name of the container.
     blob_name: the name of the blob
     content_md5: Optional. An MD5 hash of the block content. This hash is used to verify
     		the integrity of the blob during transport. When this header is specified, 
     		the storage service checks the hash that has arrived with the one that was sent.
     x_ms_lease_id: Required if the blob has an active lease. To perform this operation on
     		a blob with an active lease, specify the valid lease ID for this header.
     '''
     _validate_not_none('container_name', container_name)
     _validate_not_none('blob_name', blob_name)
     _validate_not_none('block', block)
     _validate_not_none('blockid', blockid)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/' + _str(container_name) + '/' + _str(blob_name) + '?comp=block'
     request.headers = [
         ('Content-MD5', _str_or_none(content_md5)),
         ('x-ms-lease-id', _str_or_none(x_ms_lease_id))
         ]
     request.query = [('blockid', base64.b64encode(_str_or_none(blockid)))]
     request.body = _get_request_body(block)
     request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
     request.headers = _update_storage_blob_header(request, self.account_name, self.account_key)
     response = self._perform_request(request)
コード例 #44
0
 def _get_get_metrics_rollup_relay_path(self, namespace_name, queue_name, metric):
     return "".join([
         self._get_path('services/serviceBus/Namespaces/', namespace_name),
         '/Relays/',
         _str(queue_name),
         '/Metrics/',
         _str(metric),
         '/Rollups',
     ])
コード例 #45
0
 def _get_get_metrics_data_relay_path(self, namespace_name, queue_name,
                                      metric, rollup, filter_expr):
     return "".join([
         self._get_path('services/serviceBus/Namespaces/', namespace_name),
         '/Relays/',
         _str(queue_name), '/Metrics/',
         _str(metric), '/Rollups/',
         _str(rollup), '/Values?', filter_expr
     ])
コード例 #46
0
 def _get_get_metrics_rollup_hub_path(self, namespace_name, queue_name, metric):
     return "".join([
         self._get_path('services/serviceBus/Namespaces/', namespace_name),
         '/NotificationHubs/',
         _str(queue_name),
         '/Metrics/',
         _str(metric),
         '/Rollups',
     ])
コード例 #47
0
 def _get_cloud_services_path(self,
                              cloud_service_id,
                              resource=None,
                              name=None):
     path = '/' + self.subscription_id + '/cloudservices/' + cloud_service_id
     if resource is not None:
         path += '/resources/' + _str(resource)
     if name is not None:
         path += '/' + _str(name)
     return path
コード例 #48
0
 def _get_get_metrics_rollup_relay_path(self, namespace_name, queue_name,
                                        metric):
     return "".join([
         self._get_path('services/serviceBus/Namespaces/', namespace_name),
         '/Relays/',
         _str(queue_name),
         '/Metrics/',
         _str(metric),
         '/Rollups',
     ])
コード例 #49
0
 def _get_get_metrics_rollup_hub_path(self, namespace_name, queue_name,
                                      metric):
     return "".join([
         self._get_path('services/serviceBus/Namespaces/', namespace_name),
         '/NotificationHubs/',
         _str(queue_name),
         '/Metrics/',
         _str(metric),
         '/Rollups',
     ])
コード例 #50
0
 def _get_get_metrics_rollup_topic_path(self, namespace_name, queue_name, metric):
     return "".join(
         [
             self._get_path("services/serviceBus/Namespaces/", namespace_name),
             "/Topics/",
             _str(queue_name),
             "/Metrics/",
             _str(metric),
             "/Rollups",
         ]
     )
コード例 #51
0
 def _get_get_metrics_data_relay_path(self, namespace_name, queue_name, metric, rollup, filter_expr):
     return "".join([
         self._get_path('services/serviceBus/Namespaces/', namespace_name),
         '/Relays/',
         _str(queue_name),
         '/Metrics/',
         _str(metric),
         '/Rollups/',
         _str(rollup),
         '/Values?',
         filter_expr
     ])
コード例 #52
0
 def extended_properties_dict_to_xml_fragment(extended_properties):
     xml = ''
     if extended_properties is not None and len(extended_properties) > 0:
         xml += '<ExtendedProperties>'
         for key, val in extended_properties.items():
             xml += ''.join([
                 '<ExtendedProperty>', '<Name>',
                 _str(key), '</Name>', '<Value>',
                 _str(val), '</Value>', '</ExtendedProperty>'
             ])
         xml += '</ExtendedProperties>'
     return xml
コード例 #53
0
    def update_message(self, queue_name, message_id, message_text, popreceipt,
                       visibilitytimeout):
        '''
        Updates the visibility timeout of a message. You can also use this
        operation to update the contents of a message.

        queue_name:
            Name of the queue.
        message_id:
            Message to update.
        message_text:
            Content of message.
        popreceipt:
            Required. A valid pop receipt value returned from an earlier call
            to the Get Messages or Update Message operation.
        visibilitytimeout:
            Required. Specifies the new visibility timeout value, in seconds,
            relative to server time. The new value must be larger than or equal
            to 0, and cannot be larger than 7 days. The visibility timeout of a
            message cannot be set to a value later than the expiry time. A
            message can be updated until it has been deleted or has expired.
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('message_id', message_id)
        _validate_not_none('message_text', message_text)
        _validate_not_none('popreceipt', popreceipt)
        _validate_not_none('visibilitytimeout', visibilitytimeout)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + \
            _str(queue_name) + '/messages/' + _str(message_id) + ''
        request.query = [
            ('popreceipt', _str_or_none(popreceipt)),
            ('visibilitytimeout', _str_or_none(visibilitytimeout))
        ]
        request.body = _get_request_body(
            '<?xml version="1.0" encoding="utf-8"?> \
<QueueMessage> \
    <MessageText>' + xml_escape(_str(message_text)) + '</MessageText> \
</QueueMessage>')
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_queue_header(
            request, self.authentication)
        response = self._perform_request(request)

        return _parse_response_for_dict_filter(
            response,
            filter=['x-ms-popreceipt', 'x-ms-time-next-visible'])
コード例 #54
0
    def update_message(self, queue_name, message_id, message_text, popreceipt,
                       visibilitytimeout):
        '''
        Updates the visibility timeout of a message. You can also use this
        operation to update the contents of a message.

        queue_name:
            Name of the queue.
        message_id:
            Message to update.
        message_text:
            Content of message.
        popreceipt:
            Required. A valid pop receipt value returned from an earlier call
            to the Get Messages or Update Message operation.
        visibilitytimeout:
            Required. Specifies the new visibility timeout value, in seconds,
            relative to server time. The new value must be larger than or equal
            to 0, and cannot be larger than 7 days. The visibility timeout of a
            message cannot be set to a value later than the expiry time. A
            message can be updated until it has been deleted or has expired.
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('message_id', message_id)
        _validate_not_none('message_text', message_text)
        _validate_not_none('popreceipt', popreceipt)
        _validate_not_none('visibilitytimeout', visibilitytimeout)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + \
            _str(queue_name) + '/messages/' + _str(message_id) + ''
        request.query = [
            ('popreceipt', _str_or_none(popreceipt)),
            ('visibilitytimeout', _str_or_none(visibilitytimeout))
        ]
        request.body = _get_request_body(
            '<?xml version="1.0" encoding="utf-8"?> \
<QueueMessage> \
    <MessageText>' + xml_escape(_str(message_text)) + '</MessageText> \
</QueueMessage>')
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_queue_header(
            request, self.authentication)
        response = self._perform_request(request)

        return _parse_response_for_dict_filter(
            response,
            filter=['x-ms-popreceipt', 'x-ms-time-next-visible'])
コード例 #55
0
 def copy_blob(self, container_name, blob_name, x_ms_copy_source, x_ms_meta_name_values=None, x_ms_source_if_modified_since=None, x_ms_source_if_unmodified_since=None, x_ms_source_if_match=None, x_ms_source_if_none_match=None, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None, x_ms_lease_id=None, x_ms_source_lease_id=None):
     '''
     Copies a blob to a destination within the storage account. 
     
     container_name: the name of container.
     blob_name: the name of blob
     x_ms_copy_source: the blob to be copied. Should be absolute path format.
     x_ms_meta_name_values: Optional. Dict containing name and value pairs.
     x_ms_source_if_modified_since: Optional. An ETag value. Specify this conditional 
     		header to copy the source blob only if its ETag matches the value specified.
     x_ms_source_if_unmodified_since: Optional. An ETag value. Specify this conditional 
     		header to copy the blob only if its ETag does not match the value specified.
     x_ms_source_if_match: Optional. A DateTime value. Specify this conditional header to copy
     		the blob only if the source blob has been modified since the specified date/time.
     x_ms_source_if_none_match: Optional. An ETag value. Specify this conditional header to 
     		copy the source blob only if its ETag matches the value specified.
     if_modified_since: Optional. Datetime string.
     if_unmodified_since: DateTime string.
     if_match: Optional. snapshot the blob only if its ETag value matches the value specified. 
     if_none_match: Optional. An ETag value
     x_ms_lease_id: Optional. If this header is specified, the operation will be performed 
     		only if both of the following conditions are met. 
     		1. The blob's lease is currently active
     		2. The lease ID specified in the request matches that of the blob.
     x-ms-meta-name-values:  a dict containing name, value for metadata.
     '''
     _validate_not_none('container_name', container_name)
     _validate_not_none('blob_name', blob_name)
     _validate_not_none('x_ms_copy_source', x_ms_copy_source)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/' + _str(container_name) + '/' + _str(blob_name) + ''
     request.headers = [
         ('x-ms-copy-source', _str_or_none(x_ms_copy_source)),
         ('x-ms-meta-name-values', x_ms_meta_name_values),
         ('x-ms-source-if-modified-since', _str_or_none(x_ms_source_if_modified_since)),
         ('x-ms-source-if-unmodified-since', _str_or_none(x_ms_source_if_unmodified_since)),
         ('x-ms-source-if-match', _str_or_none(x_ms_source_if_match)),
         ('x-ms-source-if-none-match', _str_or_none(x_ms_source_if_none_match)),
         ('If-Modified-Since', _str_or_none(if_modified_since)),
         ('If-Unmodified-Since', _str_or_none(if_unmodified_since)),
         ('If-Match', _str_or_none(if_match)),
         ('If-None-Match', _str_or_none(if_none_match)),
         ('x-ms-lease-id', _str_or_none(x_ms_lease_id)),
         ('x-ms-source-lease-id', _str_or_none(x_ms_source_lease_id))
         ]
     request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
     request.headers = _update_storage_blob_header(request, self.account_name, self.account_key)
     response = self._perform_request(request)
コード例 #56
0
    def put_message(self,
                    queue_name,
                    message_text,
                    visibilitytimeout=None,
                    messagettl=None):
        '''
        Adds a new message to the back of the message queue. A visibility
        timeout can also be specified to make the message invisible until the
        visibility timeout expires. A message must be in a format that can be
        included in an XML request with UTF-8 encoding. The encoded message can
        be up to 64KB in size for versions 2011-08-18 and newer, or 8KB in size
        for previous versions.

        queue_name:
            Name of the queue.
        message_text:
            Message content.
        visibilitytimeout:
            Optional. If not specified, the default value is 0. Specifies the
            new visibility timeout value, in seconds, relative to server time.
            The new value must be larger than or equal to 0, and cannot be
            larger than 7 days. The visibility timeout of a message cannot be
            set to a value later than the expiry time. visibilitytimeout
            should be set to a value smaller than the time-to-live value.
        messagettl:
            Optional. Specifies the time-to-live interval for the message, in
            seconds. The maximum time-to-live allowed is 7 days. If this
            parameter is omitted, the default time-to-live is 7 days.
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('message_text', message_text)
        request = HTTPRequest()
        request.method = 'POST'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + '/messages'
        request.query = [('visibilitytimeout',
                          _str_or_none(visibilitytimeout)),
                         ('messagettl', _str_or_none(messagettl))]
        request.body = _get_request_body(
            '<?xml version="1.0" encoding="utf-8"?> \
<QueueMessage> \
    <MessageText>' + xml_escape(_str(message_text)) + '</MessageText> \
</QueueMessage>')
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_queue_header(request,
                                                       self.account_name,
                                                       self.account_key)
        self._perform_request(request)
コード例 #57
0
ファイル: blobservice.py プロジェクト: jacalata/optimization
    def snapshot_blob(self,
                      container_name,
                      blob_name,
                      x_ms_meta_name_values=None,
                      if_modified_since=None,
                      if_unmodified_since=None,
                      if_match=None,
                      if_none_match=None,
                      x_ms_lease_id=None):
        '''
        Creates a read-only snapshot of a blob.
        
        container_name: the name of container.
        blob_name: the name of blob
        x_ms_meta_name_values: Optional. Dict containing name and value pairs.
        if_modified_since: Optional. Datetime string.
        if_unmodified_since: DateTime string.
        if_match: Optional. snapshot the blob only if its ETag value matches the value specified. 
        if_none_match: Optional. An ETag value
        x_ms_lease_id: Optional. If this header is specified, the operation will be performed 
                  only if both of the following conditions are met. 
        			1. The blob's lease is currently active
        			2. The lease ID specified in the request matches that of the blob.
        '''
        _validate_not_none('container_name', container_name)
        _validate_not_none('blob_name', blob_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(container_name) + '/' + _str(
            blob_name) + '?comp=snapshot'
        request.headers = [
            ('x-ms-meta-name-values', x_ms_meta_name_values),
            ('If-Modified-Since', _str_or_none(if_modified_since)),
            ('If-Unmodified-Since', _str_or_none(if_unmodified_since)),
            ('If-Match', _str_or_none(if_match)),
            ('If-None-Match', _str_or_none(if_none_match)),
            ('x-ms-lease-id', _str_or_none(x_ms_lease_id))
        ]
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_blob_header(request,
                                                      self.account_name,
                                                      self.account_key)
        response = self._perform_request(request)

        return _parse_response_for_dict_filter(
            response, filter=['x-ms-snapshot', 'etag', 'last-modified'])
コード例 #58
0
    def insert_entity(self,
                      table_name,
                      entity,
                      content_type='application/atom+xml'):
        '''
        Inserts a new entity into a table.

        table_name:
            Table name.
        entity:
            Required. The entity object to insert. Could be a dict format or
            entity object.
        content_type:
            Required. Must be set to application/atom+xml
        '''
        _validate_not_none('table_name', table_name)
        _validate_not_none('entity', entity)
        _validate_not_none('content_type', content_type)
        request = HTTPRequest()
        request.method = 'POST'
        request.host = self._get_host()
        request.path = '/' + _str(table_name) + ''
        request.headers = [('Content-Type', _str_or_none(content_type))]
        request.body = _get_request_body(_convert_entity_to_xml(entity))
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_table_header(request)
        response = self._perform_request(request)

        return _convert_response_to_entity(response)
コード例 #59
0
 def delete_table(self, table_name, fail_not_exist=False):
     '''
     table_name:
         Name of the table to delete.
     fail_not_exist:
         Specify whether throw exception when table doesn't exist.
     '''
     _validate_not_none('table_name', table_name)
     request = HTTPRequest()
     request.method = 'DELETE'
     request.host = self._get_host()
     request.path = '/Tables(\'' + _str(table_name) + '\')'
     request.path, request.query = _update_request_uri_query_local_storage(
         request, self.use_local_storage)
     request.headers = _update_storage_table_header(request)
     if not fail_not_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as ex:
             _dont_fail_not_exist(ex)
             return False
     else:
         self._perform_request(request)
         return True
コード例 #60
0
    def delete_topic(self, topic_name, fail_not_exist=False):
        '''
        Deletes an existing topic. This operation will also remove all
        associated state including associated subscriptions.

        topic_name: Name of the topic to delete.
        fail_not_exist:
            Specify whether throw exception when topic doesn't exist.
        '''
        _validate_not_none('topic_name', topic_name)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_not_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_not_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True