Exemple #1
0
 def put_block(self, container_name, blob_name, block, blockid, content_m_d5=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 = _get_blob_host(self.account_name, self.use_local_storage)
     request.path = '/' + str(container_name) + '/' + str(blob_name) + '?comp=block'
     request.headers = [
         ('Content-MD5', _str_or_none(content_m_d5)),
         ('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)
    def get_messages(self, queue_name, numofmessages=None, visibilitytimeout=None):
        """
        Retrieves one or more messages from the front of the queue.
        
        queue_name: name of the queue.
        numofmessages: Optional. A nonzero integer value that specifies the number of 
        		messages to retrieve from the queue, up to a maximum of 32. If fewer are
        		visible, the visible messages are returned. By default, a single message
        		is retrieved from the queue with this 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 1 second, and cannot be larger than 7 days, or larger than 2 
        		hours on REST protocol versions prior to version 2011-08-18. The visibility
        		timeout of a message can be set to a value later than the expiry time.
        """
        _validate_not_none("queue_name", queue_name)
        request = HTTPRequest()
        request.method = "GET"
        request.host = self._get_host()
        request.path = "/" + str(queue_name) + "/messages"
        request.query = [
            ("numofmessages", _str_or_none(numofmessages)),
            ("visibilitytimeout", _str_or_none(visibilitytimeout)),
        ]
        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)

        return _parse_response(response, QueueMessagesList)
Exemple #3
0
    def peek_messages(self, queue_name, numofmessages=None):
        '''
        Retrieves one or more messages from the front of the queue, but does not alter 
        the visibility of the message. 
        
        queue_name: Name of the queue.
        numofmessages:
            Optional. A nonzero integer value that specifies the number of 
            messages to peek from the queue, up to a maximum of 32. By default, 
            a single message is peeked from the queue with this operation.
        '''
        _validate_not_none('queue_name', queue_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + '/messages?peekonly=true'
        request.query = [('numofmessages', _str_or_none(numofmessages))]
        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)

        return _parse_response(response, QueueMessagesList)
Exemple #4
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'])
Exemple #5
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 = _get_table_host(self.account_name, self.use_local_storage)
        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'])
    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'])
 def create_container(self, container_name, x_ms_meta_name_values=None, x_ms_blob_public_access=None, fail_on_exist=False):
     '''
     Creates a new container under the specified account. If the container with the same name 
     already exists, the operation fails.
     
     x_ms_meta_name_values: Optional. A dict with name_value pairs to associate with the 
             container as metadata. Example:{'Category':'test'}
     x_ms_blob_public_access: Optional. Possible values include: container, blob.
     fail_on_exist: specify whether to throw an exception when the container exists.
     '''
     _validate_not_none('container_name', container_name)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/' + _str(container_name) + '?restype=container'
     request.headers = [
         ('x-ms-meta-name-values', x_ms_meta_name_values),
         ('x-ms-blob-public-access', _str_or_none(x_ms_blob_public_access))
         ]
     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)
     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
    def delete_queue(self, queue_name, fail_not_exist=False):
        '''
        Permanently deletes the specified queue.

        queue_name:
            Name of the queue.
        fail_not_exist:
            Specify whether throw exception when queue doesn't exist.
        '''
        _validate_not_none('queue_name', queue_name)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + ''
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_queue_header(
            request, self.authentication)
        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
    def peek_messages(self, queue_name, numofmessages=None):
        '''
        Retrieves one or more messages from the front of the queue, but does
        not alter the visibility of the message.

        queue_name:
            Name of the queue.
        numofmessages:
            Optional. A nonzero integer value that specifies the number of
            messages to peek from the queue, up to a maximum of 32. By default,
            a single message is peeked from the queue with this operation.
        '''
        _validate_not_none('queue_name', queue_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + '/messages?peekonly=true'
        request.query = [('numofmessages', _str_or_none(numofmessages))]
        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 _ETreeXmlToObject.parse_response(
            response, QueueMessagesList)
Exemple #10
0
    def list_queues(self,
                    prefix=None,
                    marker=None,
                    maxresults=None,
                    include=None):
        '''
        Lists all of the queues in a given storage account.
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/?comp=list'
        request.query = [('prefix', _str_or_none(prefix)),
                         ('marker', _str_or_none(marker)),
                         ('maxresults', _int_or_none(maxresults)),
                         ('include', _str_or_none(include))]
        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)

        return _parse_enum_results_list(response, QueueEnumResults, "Queues",
                                        Queue)
Exemple #11
0
    def set_properties(self, blob_service, storage_service_properties):
        """
        Override API methods to change the API version and send the right
        headers
        """
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = blob_service._get_host()
        request.path = '/?restype=service&comp=properties'
        request.query = [('timeout', _int_or_none(None))]
        request.body = _get_request_body(
            _convert_class_to_xml(storage_service_properties))
        request.path, request.query = _update_request_uri_query_local_storage(
            request, blob_service.use_local_storage)
        request.headers = self.get_request_headers(request,
                                                   blob_service.account_name,
                                                   blob_service.account_key)

        try:
            if blob_service._batchclient is not None:
                return blob_service._batchclient.insert_request_to_batch(
                    request)
            else:
                resp = blob_service._filter(request)

            if sys.version_info >= (3,) and isinstance(resp, bytes) and \
                'UTF-8':
                resp = resp.decode('UTF-8')

        except:
            raise

        return resp
Exemple #12
0
    def get_messages(self,
                     queue_name,
                     numofmessages=None,
                     visibilitytimeout=None):
        '''
        Retrieves one or more messages from the front of the queue.
        
        queue_name: name of the queue.
        numofmessages: Optional. A nonzero integer value that specifies the number of 
        		messages to retrieve from the queue, up to a maximum of 32. If fewer are
        		visible, the visible messages are returned. By default, a single message
        		is retrieved from the queue with this 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 1 second, and cannot be larger than 7 days, or larger than 2 
        		hours on REST protocol versions prior to version 2011-08-18. The visibility
        		timeout of a message can be set to a value later than the expiry time.
        '''
        _validate_not_none('queue_name', queue_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + '/messages'
        request.query = [('numofmessages', _str_or_none(numofmessages)),
                         ('visibilitytimeout', _str_or_none(visibilitytimeout))
                         ]
        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)

        return _parse_response(response, QueueMessagesList)
Exemple #13
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 = _get_blob_host(self.account_name, self.use_local_storage)
        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")
Exemple #14
0
 def create_container(self, container_name, x_ms_meta_name_values=None, x_ms_blob_public_access=None, fail_on_exist=False):
     '''
     Creates a new container under the specified account. If the container with the same name 
     already exists, the operation fails.
     
     x_ms_meta_name_values: Optional. A dict with name_value pairs to associate with the 
             container as metadata. Example:{'Category':'test'}
     x_ms_blob_public_access: Optional. Possible values include: container, blob.
     fail_on_exist: specify whether to throw an exception when the container exists.
     '''
     _validate_not_none('container_name', container_name)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = _get_blob_host(self.account_name, self.use_local_storage)
     request.path = '/' + str(container_name) + '?restype=container'
     request.headers = [
         ('x-ms-meta-name-values', x_ms_meta_name_values),
         ('x-ms-blob-public-access', _str_or_none(x_ms_blob_public_access))
         ]
     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)
     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
 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)
    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)
    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'])
    def set_queue_service_properties(self, storage_service_properties,
                                     timeout=None):
        '''
        Sets the properties of a storage account's Queue service, including
        Windows Azure Storage Analytics.

        storage_service_properties:
            StorageServiceProperties object.
        timeout:
            Optional. The timeout parameter is expressed in seconds.
        '''
        _validate_not_none('storage_service_properties',
                           storage_service_properties)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/?restype=service&comp=properties'
        request.query = [('timeout', _int_or_none(timeout))]
        request.body = _get_request_body(
            _convert_class_to_xml(storage_service_properties))
        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)
 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)
 def create_table(self, table, fail_on_exist=False):
     '''
     Creates a new table in the storage account.
     
     table: name of the table to create.
     fail_on_exist: specify whether throw exception when table exists.
     '''
     _validate_not_none('table', table)
     request = HTTPRequest()
     request.method = 'POST'
     request.host = _get_table_host(self.account_name, self.use_local_storage)
     request.path = '/Tables'
     request.body = _get_request_body(convert_table_to_xml(table))
     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_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
    def query_tables(self, table_name = None, top=None, next_table_name=None):
        '''
        Returns a list of tables under the specified account.
        
        table_name: Optional.  The specific table to query.
        top: Optional. Maximum number of tables to return.
        next_table_name:
            Optional. When top is used, the next table name is stored in 
            result.x_ms_continuation['NextTableName']
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        if table_name is not None:
            uri_part_table_name = "('" + table_name + "')"
        else:
            uri_part_table_name = ""
        request.path = '/Tables' + uri_part_table_name + ''
        request.query = [
            ('$top', _int_or_none(top)),
            ('NextTableName', _str_or_none(next_table_name))
            ]
        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_feeds(response, _convert_xml_to_table)
 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
Exemple #23
0
 def create_table(self, table, fail_on_exist=False):
     '''
     Creates a new table in the storage account.
     
     table: name of the table to create. Table name may contain only alphanumeric characters
          and cannot begin with a numeric character. It is case-insensitive and must be from 
     	 3 to 63 characters long.
     fail_on_exist: specify whether throw exception when table exists.
     '''
     _validate_not_none('table', table)
     request = HTTPRequest()
     request.method = 'POST'
     request.host = _get_table_host(self.account_name, self.use_local_storage)
     request.path = '/Tables'
     request.body = _get_request_body(convert_table_to_xml(table))
     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_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
Exemple #24
0
 def set_container_acl(self,
                       container_name,
                       signed_identifiers=None,
                       x_ms_blob_public_access=None):
     '''
     Sets the permissions for the specified container.
     
     x_ms_blob_public_access: Optional. Possible values include 'container' and 'blob'. 
     signed_identifiers: SignedIdentifers instance
     '''
     _validate_not_none('container_name', container_name)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/' + str(
         container_name) + '?restype=container&comp=acl'
     request.headers = [('x-ms-blob-public-access',
                         _str_or_none(x_ms_blob_public_access))]
     request.body = _get_request_body(
         _convert_class_to_xml(signed_identifiers))
     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)
Exemple #25
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.
        
        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 = _get_table_host(self.account_name, self.use_local_storage)
        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'])
Exemple #26
0
 def delete_container(self, container_name, fail_not_exist=False):
     '''
     Marks the specified container for deletion.
     
     fail_not_exist: specify whether to throw an exception when the container doesn't exist.
     '''
     _validate_not_none('container_name', container_name)
     request = HTTPRequest()
     request.method = 'DELETE'
     request.host = self._get_host()
     request.path = '/' + str(container_name) + '?restype=container'
     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)
     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
Exemple #27
0
 def delete_queue(self, queue_name, fail_not_exist=False):
     '''
     Permanently deletes the specified queue.
     
     queue_name: Name of the queue.
     fail_not_exist:
         Specify whether throw exception when queue doesn't exist.
     '''
     _validate_not_none('queue_name', queue_name)
     request = HTTPRequest()
     request.method = 'DELETE'
     request.host = self._get_host()
     request.path = '/' + _str(queue_name) + ''
     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)
     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
Exemple #28
0
    def list_blobs(self,
                   container_name,
                   prefix=None,
                   marker=None,
                   maxresults=None,
                   include=None):
        '''
        Returns the list of blobs under the specified container.
        '''
        _validate_not_none('container_name', container_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + str(
            container_name) + '?restype=container&comp=list'
        request.query = [('prefix', _str_or_none(prefix)),
                         ('marker', _str_or_none(marker)),
                         ('maxresults', _int_or_none(maxresults)),
                         ('include', _str_or_none(include))]
        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_enum_results_list(response, BlobEnumResults, "Blobs",
                                        Blob)
Exemple #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)
Exemple #30
0
 def set_blob_service_properties(self,
                                 storage_service_properties,
                                 timeout=None):
     '''
     Sets the properties of a storage account's Blob service, including Windows Azure 
     Storage Analytics. You can also use this operation to set the default request 
     version for all incoming requests that do not have a version specified.
     
     storage_service_properties: a StorageServiceProperties object.
     timeout: Optional. The timeout parameter is expressed in seconds. For example, the 
     		following value sets a timeout of 30 seconds for the request: timeout=30.
     '''
     _validate_not_none('storage_service_properties',
                        storage_service_properties)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/?restype=service&comp=properties'
     request.query = [('timeout', _int_or_none(timeout))]
     request.body = _get_request_body(
         _convert_class_to_xml(storage_service_properties))
     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)
    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)
Exemple #32
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)
    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)
Exemple #34
0
    def list_containers(self,
                        prefix=None,
                        marker=None,
                        maxresults=None,
                        include=None):
        '''
        The List Containers operation returns a list of the containers under the specified account.
        
        prefix: Optional. Filters the results to return only containers whose names begin with
        		the specified prefix. 
        marker: Optional. A string value that identifies the portion of the list to be returned 
                with the next list operation.
        maxresults: Optional. Specifies the maximum number of containers to return. 
        include: Optional. Include this parameter to specify that the container's metadata be 
                returned as part of the response body. set this parameter to string 'metadata' to
        		get container's metadata.
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/?comp=list'
        request.query = [('prefix', _str_or_none(prefix)),
                         ('marker', _str_or_none(marker)),
                         ('maxresults', _int_or_none(maxresults)),
                         ('include', _str_or_none(include))]
        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_enum_results_list(response, ContainerEnumResults,
                                        "Containers", Container)
    def list_containers(self, prefix=None, marker=None, maxresults=None, include=None):
        '''
        The List Containers operation returns a list of the containers under the specified account.
        
        prefix: Optional. Filters the results to return only containers whose names begin with
        		the specified prefix. 
        marker: Optional. A string value that identifies the portion of the list to be returned 
                with the next list operation.
        maxresults: Optional. Specifies the maximum number of containers to return. 
        include: Optional. Include this parameter to specify that the container's metadata be 
                returned as part of the response body. set this parameter to string 'metadata' to
        		get container's metadata.
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/?comp=list'
        request.query = [
            ('prefix', _str_or_none(prefix)),
            ('marker', _str_or_none(marker)),
            ('maxresults', _int_or_none(maxresults)),
            ('include', _str_or_none(include))
            ]
        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_enum_results_list(response, ContainerEnumResults, "Containers", Container)
Exemple #36
0
    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')
 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)
Exemple #38
0
 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)
    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)
Exemple #40
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'])
    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")
Exemple #42
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)
Exemple #43
0
    def query_entities(self, table_name, filter=None, select=None, top=None, next_partition_key=None, next_row_key=None):
        '''
        Get entities in a table; includes the $filter and $select options. 
        
        table_name: the table to query
        filter: a filter as described at http://msdn.microsoft.com/en-us/library/windowsazure/dd894031.aspx
        select: the property names to select from the entities
        top: the maximum number of entities to return
        '''
        _validate_not_none('table_name', table_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + str(table_name) + '()'
        request.query = [
            ('$filter', _str_or_none(filter)),
            ('$select', _str_or_none(select)),
            ('$top', _int_or_none(top)),
            ('NextPartitionKey', _str_or_none(next_partition_key)),
            ('NextRowKey', _str_or_none(next_row_key))
            ]
        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_feeds(response, _convert_xml_to_entity)
Exemple #44
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)
Exemple #45
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.
        
        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'])
Exemple #46
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)
Exemple #47
0
    def query_entities(self, table_name, filter=None, select=None, top=None, next_partition_key=None, next_row_key=None):
        '''
        Get entities in a table; includes the $filter and $select options. 
        
        table_name: the table to query
        filter: a filter as described at http://msdn.microsoft.com/en-us/library/windowsazure/dd894031.aspx
        select: the property names to select from the entities
        top: the maximum number of entities to return
        '''
        _validate_not_none('table_name', table_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = _get_table_host(self.account_name, self.use_local_storage)
        request.path = '/' + str(table_name) + '()'
        request.query = [
            ('$filter', _str_or_none(filter)),
            ('$select', _str_or_none(select)),
            ('$top', _int_or_none(top)),
            ('NextPartitionKey', _str_or_none(next_partition_key)),
            ('NextRowKey', _str_or_none(next_row_key))
            ]
        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_feeds(response, _convert_xml_to_entity)
Exemple #48
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)
Exemple #49
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.
     
     partition_key: PartitionKey of the entity.
     row_key: RowKey of the entity.
     if_match: Required. Specifies the condition for which the delete should be performed.
     		To force an unconditional delete, set If-Match to the wildcard character (*). 
     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('content_type', content_type)
     _validate_not_none('if_match', if_match)
     request = HTTPRequest()
     request.method = 'DELETE'
     request.host = _get_table_host(self.account_name, self.use_local_storage)
     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)
Exemple #50
0
    def set_properties(self, blob_service, storage_service_properties):
        """
        Override API methods to change the API version and send the right
        headers
        """
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = blob_service._get_host()
        request.path = '/?restype=service&comp=properties'
        request.query = [('timeout', _int_or_none(None))]
        request.body = _get_request_body(
            _convert_class_to_xml(storage_service_properties))
        request.path, request.query = _update_request_uri_query_local_storage(
            request, blob_service.use_local_storage)
        request.headers = self.get_request_headers(
            request, blob_service.account_name, blob_service.account_key)

        try:
            if blob_service._batchclient is not None:
                return blob_service._batchclient.insert_request_to_batch(request)
            else:
                resp = blob_service._filter(request)

            if sys.version_info >= (3,) and isinstance(resp, bytes) and \
                'UTF-8':
                resp = resp.decode('UTF-8')

        except:
            raise

        return resp
 def create_queue(self, queue_name, x_ms_meta_name_values=None, fail_on_exist=False):
     """
     Creates a queue under the given account.
     
     queue_name: name of the queue.
     x_ms_meta_name_values: Optional. A dict containing name-value pairs to associate 
     		with the queue as metadata.
     fail_on_exist: specify whether throw exception when queue exists.
     """
     _validate_not_none("queue_name", queue_name)
     request = HTTPRequest()
     request.method = "PUT"
     request.host = self._get_host()
     request.path = "/" + str(queue_name) + ""
     request.headers = [("x-ms-meta-name-values", x_ms_meta_name_values)]
     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)
     if not fail_on_exist:
         try:
             response = self._perform_request(request)
             if response.status == HTTP_RESPONSE_NO_CONTENT:
                 return False
             return True
         except WindowsAzureError as e:
             _dont_fail_on_exist(e)
             return False
     else:
         response = self._perform_request(request)
         if response.status == HTTP_RESPONSE_NO_CONTENT:
             raise WindowsAzureConflictError(azure._ERROR_CONFLICT)
         return True
Exemple #52
0
 def set_queue_service_properties(self,
                                  storage_service_properties,
                                  timeout=None):
     '''
     Sets the properties of a storage account's Queue service, including Windows Azure 
     Storage Analytics.
     
     storage_service_properties: StorageServiceProperties object.
     timeout: Optional. The timeout parameter is expressed in seconds.
     '''
     _validate_not_none('storage_service_properties',
                        storage_service_properties)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/?restype=service&comp=properties'
     request.query = [('timeout', _int_or_none(timeout))]
     request.body = _get_request_body(
         _convert_class_to_xml(storage_service_properties))
     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)
    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)
    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)
    def query_entities(self, table_name, filter=None, select=None, top=None, next_partition_key=None, next_row_key=None):
        """
        Get entities in a table; includes the $filter and $select options.

        table_name: Table to query.
        filter:
            Optional. Filter as described at
            http://msdn.microsoft.com/en-us/library/windowsazure/dd894031.aspx
        select: Optional. Property names to select from the entities.
        top: Optional. Maximum number of entities to return.
        next_partition_key:
            Optional. When top is used, the next partition key is stored in
            result.x_ms_continuation['NextPartitionKey']
        next_row_key:
            Optional. When top is used, the next partition key is stored in
            result.x_ms_continuation['NextRowKey']
        """
        _validate_not_none('table_name', table_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(table_name) + '()'
        request.query = [
            ('$filter', _str_or_none(filter)),
            ('$select', _str_or_none(select)),
            ('$top', _int_or_none(top)),
            ('NextPartitionKey', _str_or_none(next_partition_key)),
            ('NextRowKey', _str_or_none(next_row_key))
        ]
        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_feeds(response, _convert_xml_to_entity)
 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
    def create_table(self, table, fail_on_exist=False):
        '''
        Creates a new table in the storage account.

        table:
            Name of the table to create. Table name may contain only
            alphanumeric characters and cannot begin with a numeric character.
            It is case-insensitive and must be from 3 to 63 characters long.
        fail_on_exist:
            Specify whether throw exception when table exists.
        '''
        _validate_not_none('table', table)
        request = HTTPRequest()
        request.method = 'POST'
        request.host = self._get_host()
        request.path = '/Tables'
        request.body = _get_request_body(_convert_table_to_xml(table))
        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_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
    def query_tables(self, table_name=None, top=None, next_table_name=None):
        '''
        Returns a list of tables under the specified account.

        table_name:
            Optional.  The specific table to query.
        top:
            Optional. Maximum number of tables to return.
        next_table_name:
            Optional. When top is used, the next table name is stored in
            result.x_ms_continuation['NextTableName']
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        if table_name is not None:
            uri_part_table_name = "('" + table_name + "')"
        else:
            uri_part_table_name = ""
        request.path = '/Tables' + uri_part_table_name + ''
        request.query = [('$top', _int_or_none(top)),
                         ('NextTableName', _str_or_none(next_table_name))]
        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 _ETreeXmlToObject.convert_response_to_feeds(
            response, _convert_etree_element_to_table)
 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)
 def clear_messages(self, queue_name):
     """
     Deletes all messages from the specified queue.
     
     queue_name: name of the queue.
     """
     _validate_not_none("queue_name", queue_name)
     request = HTTPRequest()
     request.method = "DELETE"
     request.host = self._get_host()
     request.path = "/" + str(queue_name) + "/messages"
     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)