Example #1
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)
Example #2
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.
     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
Example #3
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'])
Example #4
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)
Example #5
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)
Example #6
0
 def insert_or_merge_entity(self,
                            table_name,
                            partition_key,
                            row_key,
                            entity,
                            content_type='application/atom+xml',
                            if_match='*'):
     '''
     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)),
                        ('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)
Example #7
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'])
Example #8
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)
Example #9
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: the 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 = _get_table_host(self.account_name,
                                       self.use_local_storage)
        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)
Example #10
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 = _get_table_host(self.account_name,
                                    self.use_local_storage)
     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 e:
             _dont_fail_not_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
Example #11
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
 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
Example #13
0
    def get_table_service_properties(self):
        '''
        Gets the properties of a storage account's Table service, including Windows Azure
        Storage Analytics.
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = _get_table_host(self.account_name, self.use_local_storage)
        request.path = '/?restype=service&comp=properties'
        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(response, StorageServiceProperties)
Example #14
0
    def get_table_service_properties(self):
        '''
        Gets the properties of a storage account's Table service, including Windows Azure
        Storage Analytics.
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = _get_table_host(self.account_name,
                                       self.use_local_storage)
        request.path = '/?restype=service&comp=properties'
        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(response, StorageServiceProperties)
Example #15
0
    def set_table_service_properties(self, storage_service_properties):
        '''
        Sets the properties of a storage account's Table Service, including Windows Azure Storage Analytics.
        
        storage_service_properties: a StorageServiceProperties object.
        '''
        _validate_not_none('storage_service_properties', storage_service_properties)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = _get_table_host(self.account_name, self.use_local_storage)
        request.path = '/?restype=service&comp=properties'
        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_table_header(request)
        response = self._perform_request(request)

        return _parse_response_for_dict(response)
 def insert_entity(self, table_name, entity, content_type='application/atom+xml'):
     '''
     Inserts a new entity into a table.
     
     entity: Required. The entity object to insert. Could be a dict format or entity object.
     Content-Type: this is required and has to 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 = _get_table_host(self.account_name, self.use_local_storage)
     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)
Example #17
0
    def set_table_service_properties(self, storage_service_properties):
        '''
        Sets the properties of a storage account's Table Service, including Windows Azure Storage Analytics.
        
        storage_service_properties: a StorageServiceProperties object.
        '''
        _validate_not_none('storage_service_properties',
                           storage_service_properties)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = _get_table_host(self.account_name,
                                       self.use_local_storage)
        request.path = '/?restype=service&comp=properties'
        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_table_header(request)
        response = self._perform_request(request)

        return _parse_response_for_dict(response)
    def query_tables(self, table_name = None, top=None):
        '''
        Returns a list of tables under the specified account.
        
        table_name: optional, the specific table to query
        top: the maximum number of tables to return
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = _get_table_host(self.account_name, self.use_local_storage)
        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))]
        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)
Example #19
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: the 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 = _get_table_host(self.account_name, self.use_local_storage)
        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)
Example #20
0
    def query_tables(self, table_name=None, top=None):
        '''
        Returns a list of tables under the specified account.
        
        table_name: optional, the specific table to query
        top: the maximum number of tables to return
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = _get_table_host(self.account_name,
                                       self.use_local_storage)
        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))]
        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)
Example #21
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 = _get_table_host(self.account_name, self.use_local_storage)
     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 e:
             _dont_fail_not_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
Example #22
0
    def query_entities(self, table_name, filter=None, select=None, top=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))]
        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)
Example #23
0
 def insert_entity(self,
                   table_name,
                   entity,
                   content_type='application/atom+xml'):
     '''
     Inserts a new entity into a table.
     
     entity: Required. The entity object to insert. Could be a dict format or entity object.
     Content-Type: this is required and has to 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 = _get_table_host(self.account_name,
                                    self.use_local_storage)
     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)