Ejemplo n.º 1
0
 def update_entity(self,
                   table_name,
                   partition_key,
                   row_key,
                   entity,
                   content_type='application/atom+xml',
                   if_match='*'):
     '''
     Updates an existing entity in a table. The Update Entity operation replaces the entire 
     entity and can be used to remove properties.
     
     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 = 'PUT'
     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)
Ejemplo n.º 2
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 create_topic(self, topic_name, topic=None, fail_on_exist=False):
        '''
        Creates a new topic. Once created, this topic resource manifest is
        immutable.

        topic_name: Name of the topic to create.
        topic: Topic object to create.
        fail_on_exist:
            Specify whether to throw an exception when the topic exists.
        '''
        _validate_not_none('topic_name', topic_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + ''
        request.body = _get_request_body(_convert_topic_to_xml(topic))
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_on_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
Ejemplo n.º 4
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'])
 def create_rule(self, topic_name, subscription_name, rule_name, rule=None, fail_on_exist=False):
     '''
     Creates a new rule. Once created, this rule's resource manifest is immutable.
     
     topic_name: the name of the topic
     subscription_name: the name of the subscription
     rule_name: name of the rule.
     fail_on_exist: specify whether to throw an exception when the rule exists.
     '''
     _validate_not_none('topic_name', topic_name)
     _validate_not_none('subscription_name', subscription_name)
     _validate_not_none('rule_name', rule_name)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self.service_namespace + SERVICE_BUS_HOST_BASE
     request.path = '/' + str(topic_name) + '/subscriptions/' + str(subscription_name) + '/rules/' + str(rule_name) + ''
     request.body = _get_request_body(convert_rule_to_xml(rule))
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
     if not fail_on_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_on_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
Ejemplo n.º 6
0
    def create_topic(self, topic_name, topic=None, fail_on_exist=False):
        '''
        Creates a new topic. Once created, this topic resource manifest is
        immutable.

        topic_name:
            Name of the topic to create.
        topic:
            Topic object to create.
        fail_on_exist:
            Specify whether to throw an exception when the topic exists.
        '''
        _validate_not_none('topic_name', topic_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + ''
        request.body = _get_request_body(_convert_topic_to_xml(topic))
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_on_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
Ejemplo n.º 7
0
 def create_rule(self, topic_name, subscription_name, rule_name, rule=None, fail_on_exist=False):
     '''
     Creates a new rule. Once created, this rule's resource manifest is immutable.
     
     topic_name: the name of the topic
     subscription_name: the name of the subscription
     rule_name: name of the rule.
     fail_on_exist: specify whether to throw an exception when the rule exists.
     '''
     _validate_not_none('topic_name', topic_name)
     _validate_not_none('subscription_name', subscription_name)
     _validate_not_none('rule_name', rule_name)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/' + str(topic_name) + '/subscriptions/' + str(subscription_name) + '/rules/' + str(rule_name) + ''
     request.body = _get_request_body(convert_rule_to_xml(rule))
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
     if not fail_on_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_on_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
Ejemplo n.º 8
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
Ejemplo n.º 9
0
 def create_queue(self, queue_name, queue=None, fail_on_exist=False):
     '''
     Creates a new queue. Once created, this queue's resource manifest is immutable. 
     
     queue: queue object to create. 
     queue_name: the name of the queue.
     fail_on_exist: specify whether to throw an exception when the 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.body = _get_request_body(convert_queue_to_xml(queue))
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
     if not fail_on_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_on_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)
Ejemplo n.º 12
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'])
Ejemplo n.º 13
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 = 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
Ejemplo n.º 14
0
 def put_block(self, container_name, blob_name, block, blockid, content_md5=None, x_ms_lease_id=None):
     '''
     Creates a new block to be committed as part of a blob.
     
     container_name: the name of the container.
     blob_name: the name of the blob
     content_md5: Optional. An MD5 hash of the block content. This hash is used to verify
     		the integrity of the blob during transport. When this header is specified, 
     		the storage service checks the hash that has arrived with the one that was sent.
     x_ms_lease_id: Required if the blob has an active lease. To perform this operation on
     		a blob with an active lease, specify the valid lease ID for this header.
     '''
     _validate_not_none('container_name', container_name)
     _validate_not_none('blob_name', blob_name)
     _validate_not_none('block', block)
     _validate_not_none('blockid', blockid)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/' + _str(container_name) + '/' + _str(blob_name) + '?comp=block'
     request.headers = [
         ('Content-MD5', _str_or_none(content_md5)),
         ('x-ms-lease-id', _str_or_none(x_ms_lease_id))
         ]
     request.query = [('blockid', base64.b64encode(_str_or_none(blockid)))]
     request.body = _get_request_body(block)
     request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
     request.headers = _update_storage_blob_header(request, self.account_name, self.account_key)
     response = self._perform_request(request)
Ejemplo n.º 15
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.authentication)
        self._perform_request(request)
Ejemplo n.º 16
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
Ejemplo n.º 17
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
Ejemplo n.º 18
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)
Ejemplo n.º 19
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)
Ejemplo n.º 20
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)
Ejemplo n.º 21
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'])
 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
Ejemplo n.º 23
0
    def put_message(self, queue_name, message_text, visibilitytimeout=None, messagettl=None):
        '''
        Adds a new message to the back of the message queue. A visibility timeout can 
        also be specified to make the message invisible until the visibility timeout 
        expires. A message must be in a format that can be included in an XML request 
        with UTF-8 encoding. The encoded message can be up to 64KB in size for versions 
        2011-08-18 and newer, or 8KB in size for previous versions.
        
        queue_name: name of the queue.
        visibilitytimeout: Optional. If specified, the request must be made using an 
        		x-ms-version of 2011-08-18 or newer.
        messagettl: Optional. Specifies the time-to-live interval for the message, 
        		in seconds. The maximum time-to-live allowed is 7 days. If this parameter
        		is omitted, the default time-to-live is 7 days.
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('message_text', message_text)
        request = HTTPRequest()
        request.method = 'POST'
        request.host = self._get_host()
        request.path = '/' + str(queue_name) + '/messages'
        request.query = [
            ('visibilitytimeout', _str_or_none(visibilitytimeout)),
            ('messagettl', _str_or_none(messagettl))
            ]
        request.body = _get_request_body('<?xml version="1.0" encoding="utf-8"?> \
<QueueMessage> \
    <MessageText>' + xml_escape(str(message_text)) + '</MessageText> \
</QueueMessage>')
        request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
        request.headers = _update_storage_queue_header(request, self.account_name, self.account_key)
        response = self._perform_request(request)
    def create_subscription(self,
                            topic_name,
                            subscription_name,
                            subscription=None,
                            fail_on_exist=False):
        '''
        Creates a new subscription. Once created, this subscription resource
        manifest is immutable.

        topic_name: Name of the topic.
        subscription_name: Name of the subscription.
        fail_on_exist:
            Specify whether throw exception when subscription exists.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + \
            _str(topic_name) + '/subscriptions/' + _str(subscription_name) + ''
        request.body = _get_request_body(
            _convert_subscription_to_xml(subscription))
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_on_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
 def create_queue(self, queue_name, queue=None, fail_on_exist=False):
     '''
     Creates a new queue. Once created, this queue's resource manifest is 
     immutable. 
     
     queue_name: Name of the queue to create.
     queue: Queue object to create. 
     fail_on_exist:
         Specify whether to throw an exception when the 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.body = _get_request_body(_convert_queue_to_xml(queue))
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key,
                                                  self.issuer)
     if not fail_on_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_on_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
Ejemplo n.º 26
0
    def create_subscription(self, topic_name, subscription_name,
                            subscription=None, fail_on_exist=False):
        '''
        Creates a new subscription. Once created, this subscription resource
        manifest is immutable.

        topic_name:
            Name of the topic.
        subscription_name:
            Name of the subscription.
        fail_on_exist:
            Specify whether throw exception when subscription exists.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + \
            _str(topic_name) + '/subscriptions/' + _str(subscription_name) + ''
        request.body = _get_request_body(
            _convert_subscription_to_xml(subscription))
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_on_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
Ejemplo n.º 27
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
Ejemplo n.º 28
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'])
Ejemplo n.º 29
0
    def create_event_hub(self, hub_name, hub=None, fail_on_exist=False):
        '''
        Creates a new Event Hub.

        hub_name:
            Name of event hub.
        hub:
            Optional. Event hub properties. Instance of EventHub class.
        hub.message_retention_in_days:
            Number of days to retain the events for this Event Hub.
        hub.status: Status of the Event Hub (enabled or disabled).
        hub.user_metadata: User metadata.
        hub.partition_count: Number of shards on the Event Hub.
        fail_on_exist:
            Specify whether to throw an exception when the event hub exists.
        '''
        _validate_not_none('hub_name', hub_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(hub_name) + '?api-version=2014-01'
        request.body = _get_request_body(_convert_event_hub_to_xml(hub))
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_on_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
Ejemplo n.º 30
0
    def create_event_hub(self, hub_name, hub=None, fail_on_exist=False):
        '''
        Creates a new Event Hub.

        hub_name:
            Name of event hub.
        hub:
            Optional. Event hub properties. Instance of EventHub class.
        hub.message_retention_in_days:
            Number of days to retain the events for this Event Hub.
        hub.status: Status of the Event Hub (enabled or disabled).
        hub.user_metadata: User metadata.
        hub.partition_count: Number of shards on the Event Hub.
        fail_on_exist:
            Specify whether to throw an exception when the event hub exists.
        '''
        _validate_not_none('hub_name', hub_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(hub_name) + '?api-version=2014-01'
        request.body = _get_request_body(_convert_event_hub_to_xml(hub))
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_on_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
Ejemplo n.º 31
0
    def update_message(self, queue_name, message_id, message_text, popreceipt,
                       visibilitytimeout):
        '''
        Updates the visibility timeout of a message. You can also use this
        operation to update the contents of a message.

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

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

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

        return _parse_response_for_dict_filter(
            response,
            filter=['x-ms-popreceipt', 'x-ms-time-next-visible'])
Ejemplo n.º 33
0
    def put_message(self,
                    queue_name,
                    message_text,
                    visibilitytimeout=None,
                    messagettl=None):
        '''
        Adds a new message to the back of the message queue. A visibility
        timeout can also be specified to make the message invisible until the
        visibility timeout expires. A message must be in a format that can be
        included in an XML request with UTF-8 encoding. The encoded message can
        be up to 64KB in size for versions 2011-08-18 and newer, or 8KB in size
        for previous versions.

        queue_name:
            Name of the queue.
        message_text:
            Message content.
        visibilitytimeout:
            Optional. If not specified, the default value is 0. Specifies the
            new visibility timeout value, in seconds, relative to server time.
            The new value must be larger than or equal to 0, and cannot be
            larger than 7 days. The visibility timeout of a message cannot be
            set to a value later than the expiry time. visibilitytimeout
            should be set to a value smaller than the time-to-live value.
        messagettl:
            Optional. Specifies the time-to-live interval for the message, in
            seconds. The maximum time-to-live allowed is 7 days. If this
            parameter is omitted, the default time-to-live is 7 days.
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('message_text', message_text)
        request = HTTPRequest()
        request.method = 'POST'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + '/messages'
        request.query = [('visibilitytimeout',
                          _str_or_none(visibilitytimeout)),
                         ('messagettl', _str_or_none(messagettl))]
        request.body = _get_request_body(
            '<?xml version="1.0" encoding="utf-8"?> \
<QueueMessage> \
    <MessageText>' + xml_escape(_str(message_text)) + '</MessageText> \
</QueueMessage>')
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_queue_header(request,
                                                       self.account_name,
                                                       self.account_key)
        self._perform_request(request)
Ejemplo n.º 34
0
 def put_block_list(self, container_name, blob_name, block_list, content_m_d5=None, x_ms_blob_cache_control=None, x_ms_blob_content_type=None, x_ms_blob_content_encoding=None, x_ms_blob_content_language=None, x_ms_blob_content_md5=None, x_ms_meta_name_values=None, x_ms_lease_id=None):
     '''
     Writes a blob by specifying the list of block IDs that make up the blob. In order to 
     be written as part of a blob, a block must have been successfully written to the server
     in a prior Put Block (REST API) operation.
     
     container_name: the name of container.
     blob_name: the name of blob
     x_ms_meta_name_values: Optional. Dict containing name and value pairs.
     x_ms_blob_cache_control: Optional. Sets the blob's cache control. If specified, this 
     		property is stored with the blob and returned with a read request.
     x_ms_blob_content_type: Optional. Sets the blob's content type. If specified, this 
     		property is stored with the blob and returned with a read request.
     x_ms_blob_content_encoding: Optional. Sets the blob's content encoding. If specified,
     		this property is stored with the blob and returned with a read request.
     x_ms_blob_content_language: Optional. Set the blob's content language. If specified, 
     		this property is stored with the blob and returned with a read request. 
     x_ms_blob_content_md5: Optional. An MD5 hash of the blob content. Note that this hash
     		is not validated, as the hashes for the individual blocks were validated when
     		each was uploaded.
     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.
     x-ms-meta-name-values:  a dict containing name, value for metadata.
     '''
     _validate_not_none('container_name', container_name)
     _validate_not_none('blob_name', blob_name)
     _validate_not_none('block_list', block_list)
     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=blocklist'
     request.headers = [
         ('Content-MD5', _str_or_none(content_m_d5)),
         ('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-encoding', _str_or_none(x_ms_blob_content_encoding)),
         ('x-ms-blob-content-language', _str_or_none(x_ms_blob_content_language)),
         ('x-ms-blob-content-md5', _str_or_none(x_ms_blob_content_md5)),
         ('x-ms-meta-name-values', x_ms_meta_name_values),
         ('x-ms-lease-id', _str_or_none(x_ms_lease_id))
         ]
     request.body = _get_request_body(convert_block_list_to_xml(block_list))
     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)
Ejemplo n.º 35
0
 def put_block_list(self, container_name, blob_name, block_list, content_md5=None, x_ms_blob_cache_control=None, x_ms_blob_content_type=None, x_ms_blob_content_encoding=None, x_ms_blob_content_language=None, x_ms_blob_content_md5=None, x_ms_meta_name_values=None, x_ms_lease_id=None):
     '''
     Writes a blob by specifying the list of block IDs that make up the blob. In order to 
     be written as part of a blob, a block must have been successfully written to the server
     in a prior Put Block (REST API) operation.
     
     container_name: the name of container.
     blob_name: the name of blob
     x_ms_meta_name_values: Optional. Dict containing name and value pairs.
     x_ms_blob_cache_control: Optional. Sets the blob's cache control. If specified, this 
     		property is stored with the blob and returned with a read request.
     x_ms_blob_content_type: Optional. Sets the blob's content type. If specified, this 
     		property is stored with the blob and returned with a read request.
     x_ms_blob_content_encoding: Optional. Sets the blob's content encoding. If specified,
     		this property is stored with the blob and returned with a read request.
     x_ms_blob_content_language: Optional. Set the blob's content language. If specified, 
     		this property is stored with the blob and returned with a read request. 
     x_ms_blob_content_md5: Optional. An MD5 hash of the blob content. Note that this hash
     		is not validated, as the hashes for the individual blocks were validated when
     		each was uploaded.
     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.
     x-ms-meta-name-values:  a dict containing name, value for metadata.
     '''
     _validate_not_none('container_name', container_name)
     _validate_not_none('blob_name', blob_name)
     _validate_not_none('block_list', block_list)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/' + _str(container_name) + '/' + _str(blob_name) + '?comp=blocklist'
     request.headers = [
         ('Content-MD5', _str_or_none(content_md5)),
         ('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-encoding', _str_or_none(x_ms_blob_content_encoding)),
         ('x-ms-blob-content-language', _str_or_none(x_ms_blob_content_language)),
         ('x-ms-blob-content-md5', _str_or_none(x_ms_blob_content_md5)),
         ('x-ms-meta-name-values', x_ms_meta_name_values),
         ('x-ms-lease-id', _str_or_none(x_ms_lease_id))
         ]
     request.body = _get_request_body(convert_block_list_to_xml(block_list))
     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)
Ejemplo n.º 36
0
 def put_page(self, container_name, blob_name, page, x_ms_range, x_ms_page_write, timeout=None, content_m_d5=None, x_ms_lease_id=None, x_ms_if_sequence_number_lte=None, x_ms_if_sequence_number_lt=None, x_ms_if_sequence_number_eq=None, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None):
     '''
     Writes a range of pages to a page blob.
     
     container_name: the name of container.
     blob_name: the name of blob
     timeout: the timeout parameter is expressed in seconds.
     x_ms_range: Required. 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_page_write: Required. You may specify one of the following options : 
     		1. update(lower case): Writes the bytes specified by the request body into the specified 
     		   range. The Range and Content-Length headers must match to perform the update.
     		2. clear(lower case): Clears the specified range and releases the space used in storage  
     		   for that range. To clear a range, set the Content-Length header to zero, and the Range
     		   header to a value that indicates the range to clear, up to maximum blob size.
     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('page', page)
     _validate_not_none('x_ms_range', x_ms_range)
     _validate_not_none('x_ms_page_write', x_ms_page_write)
     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=page'
     request.headers = [
         ('x-ms-range', _str_or_none(x_ms_range)),
         ('Content-MD5', _str_or_none(content_m_d5)),
         ('x-ms-page-write', _str_or_none(x_ms_page_write)),
         ('x-ms-lease-id', _str_or_none(x_ms_lease_id)),
         ('x-ms-if-sequence-number-lte', _str_or_none(x_ms_if_sequence_number_lte)),
         ('x-ms-if-sequence-number-lt', _str_or_none(x_ms_if_sequence_number_lt)),
         ('x-ms-if-sequence-number-eq', _str_or_none(x_ms_if_sequence_number_eq)),
         ('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))
         ]
     request.query = [('timeout', _int_or_none(timeout))]
     request.body = _get_request_body(page)
     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)
Ejemplo n.º 37
0
 def put_page(self, container_name, blob_name, page, x_ms_range, x_ms_page_write, timeout=None, content_md5=None, x_ms_lease_id=None, x_ms_if_sequence_number_lte=None, x_ms_if_sequence_number_lt=None, x_ms_if_sequence_number_eq=None, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None):
     '''
     Writes a range of pages to a page blob.
     
     container_name: the name of container.
     blob_name: the name of blob
     timeout: the timeout parameter is expressed in seconds.
     x_ms_range: Required. 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_page_write: Required. You may specify one of the following options : 
     		1. update(lower case): Writes the bytes specified by the request body into the specified 
     		   range. The Range and Content-Length headers must match to perform the update.
     		2. clear(lower case): Clears the specified range and releases the space used in storage  
     		   for that range. To clear a range, set the Content-Length header to zero, and the Range
     		   header to a value that indicates the range to clear, up to maximum blob size.
     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('page', page)
     _validate_not_none('x_ms_range', x_ms_range)
     _validate_not_none('x_ms_page_write', x_ms_page_write)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/' + _str(container_name) + '/' + _str(blob_name) + '?comp=page'
     request.headers = [
         ('x-ms-range', _str_or_none(x_ms_range)),
         ('Content-MD5', _str_or_none(content_md5)),
         ('x-ms-page-write', _str_or_none(x_ms_page_write)),
         ('x-ms-lease-id', _str_or_none(x_ms_lease_id)),
         ('x-ms-if-sequence-number-lte', _str_or_none(x_ms_if_sequence_number_lte)),
         ('x-ms-if-sequence-number-lt', _str_or_none(x_ms_if_sequence_number_lt)),
         ('x-ms-if-sequence-number-eq', _str_or_none(x_ms_if_sequence_number_eq)),
         ('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))
         ]
     request.query = [('timeout', _int_or_none(timeout))]
     request.body = _get_request_body(page)
     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)
Ejemplo n.º 38
0
    def update_entity(self,
                      table_name,
                      partition_key,
                      row_key,
                      entity,
                      content_type='application/atom+xml',
                      if_match='*'):
        '''
        Updates an existing entity in a table. The Update Entity operation
        replaces the entire entity and can be used to remove properties.

        table_name:
            Table name.
        partition_key:
            PartitionKey of the entity.
        row_key:
            RowKey of the entity.
        entity:
            Required. The entity object to insert. Could be a dict format or
            entity object.
        content_type:
            Required. Must be set to application/atom+xml
        if_match:
            Optional. Specifies the condition for which the merge should be
            performed. To force an unconditional merge, 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('entity', entity)
        _validate_not_none('content_type', content_type)
        request = HTTPRequest()
        request.method = 'PUT'
        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'])
Ejemplo n.º 39
0
    def update_entity(self, table_name, partition_key, row_key, entity,
                      content_type='application/atom+xml', if_match='*',use_json='True'):
        '''
        Updates an existing entity in a table. The Update Entity operation
        replaces the entire entity and can be used to remove properties.

        table_name:
            Table name.
        partition_key:
            PartitionKey of the entity.
        row_key:
            RowKey of the entity.
        entity:
            Required. The entity object to insert. Could be a dict format or
            entity object.
        content_type:
            Required. Must be set to application/atom+xml
        if_match:
            Optional. Specifies the condition for which the merge should be
            performed. To force an unconditional merge, 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('entity', entity)
        _validate_not_none('content_type', content_type)
        request = HTTPRequest()
        request.method = 'PUT'
        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))
        ]
        if not use_json:
            request.body = _get_request_body(_convert_entity_to_xml(entity))
        else:
            request.body = 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'])
Ejemplo n.º 40
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)
Ejemplo n.º 41
0
    def put_message(self, queue_name, message_text, visibilitytimeout=None,
                    messagettl=None):
        '''
        Adds a new message to the back of the message queue. A visibility
        timeout can also be specified to make the message invisible until the
        visibility timeout expires. A message must be in a format that can be
        included in an XML request with UTF-8 encoding. The encoded message can
        be up to 64KB in size for versions 2011-08-18 and newer, or 8KB in size
        for previous versions.

        queue_name:
            Name of the queue.
        message_text:
            Message content.
        visibilitytimeout:
            Optional. If not specified, the default value is 0. Specifies the
            new visibility timeout value, in seconds, relative to server time.
            The new value must be larger than or equal to 0, and cannot be
            larger than 7 days. The visibility timeout of a message cannot be
            set to a value later than the expiry time. visibilitytimeout
            should be set to a value smaller than the time-to-live value.
        messagettl:
            Optional. Specifies the time-to-live interval for the message, in
            seconds. The maximum time-to-live allowed is 7 days. If this
            parameter is omitted, the default time-to-live is 7 days.
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('message_text', message_text)
        request = HTTPRequest()
        request.method = 'POST'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + '/messages'
        request.query = [
            ('visibilitytimeout', _str_or_none(visibilitytimeout)),
            ('messagettl', _str_or_none(messagettl))
        ]
        request.body = _get_request_body(
            '<?xml version="1.0" encoding="utf-8"?> \
<QueueMessage> \
    <MessageText>' + xml_escape(_str(message_text)) + '</MessageText> \
</QueueMessage>')
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_queue_header(
            request, self.authentication)
        self._perform_request(request)
Ejemplo n.º 42
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 = self._get_host()
        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)
Ejemplo n.º 43
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)
 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: a 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)
Ejemplo n.º 45
0
 def send_queue_message(self, queue_name, message=None):
     '''
     Sends a message into the specified queue. The limit to the number of messages 
     which may be present in the topic is governed by the message size the 
     MaxTopicSizeInMegaBytes. If this message will cause the queue to exceed its 
     quota, a quota exceeded error is returned and the message will be rejected.
     
     queue_name: name of the queue
     message: the Message object containing message body and properties.
     '''
     _validate_not_none('queue_name', queue_name)
     request = HTTPRequest()
     request.method = 'POST'
     request.host = self._get_host()
     request.path = '/' + str(queue_name) + '/messages'
     request.headers = message.add_headers(request)
     request.body = _get_request_body(message.body)
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
     response = self._perform_request(request)
 def send_queue_message(self, queue_name, message=None):
     '''
     Sends a message into the specified queue. The limit to the number of messages 
     which may be present in the topic is governed by the message size the 
     MaxTopicSizeInMegaBytes. If this message will cause the queue to exceed its 
     quota, a quota exceeded error is returned and the message will be rejected.
     
     queue_name: name of the queue
     message: the Message object containing message body and properties.
     '''
     _validate_not_none('queue_name', queue_name)
     request = HTTPRequest()
     request.method = 'POST'
     request.host = self.service_namespace + SERVICE_BUS_HOST_BASE
     request.path = '/' + str(queue_name) + '/messages'
     request.headers = message.add_headers(request)
     request.body = _get_request_body(message.body)
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
     response = self._perform_request(request)
Ejemplo n.º 47
0
 def send_event(self, hub_name, message, device_id=None,
                broker_properties=None):
     '''
     Sends a new message event to an Event Hub.
     '''
     _validate_not_none('hub_name', hub_name)
     request = HTTPRequest()
     request.method = 'POST'
     request.host = self._get_host()
     if device_id:
         request.path = '/{0}/publishers/{1}/messages?api-version=2014-01'.format(hub_name, device_id)
     else:
         request.path = '/{0}/messages?api-version=2014-01'.format(hub_name)
     if broker_properties:
         request.headers.append(
             ('BrokerProperties', str(broker_properties)))
     request.body = _get_request_body(message)
     request.path, request.query = _update_request_uri_query(request)
     request.headers = self._update_service_bus_header(request)
     self._perform_request(request)
Ejemplo n.º 48
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)
Ejemplo n.º 49
0
 def send_event(self, hub_name, message, device_id=None,
                broker_properties=None):
     '''
     Sends a new message event to an Event Hub.
     '''
     _validate_not_none('hub_name', hub_name)
     request = HTTPRequest()
     request.method = 'POST'
     request.host = self._get_host()
     if device_id:
         request.path = '/{0}/publishers/{1}/messages?api-version=2014-01'.format(hub_name, device_id)
     else:
         request.path = '/{0}/messages?api-version=2014-01'.format(hub_name)
     if broker_properties:
         request.headers.append(
             ('BrokerProperties', str(broker_properties)))
     request.body = _get_request_body(message)
     request.path, request.query = _update_request_uri_query(request)
     request.headers = self._update_service_bus_header(request)
     self._perform_request(request)
Ejemplo n.º 50
0
 def send_topic_message(self, topic_name, message=None):
     '''
     Enqueues a message into the specified topic. The limit to the number 
     of messages which may be present in the topic is governed by the 
     message size in MaxTopicSizeInBytes. If this message causes the topic 
     to exceed its quota, a quota exceeded error is returned and the 
     message will be rejected.
     
     topic_name: Name of the topic.
     message: Message object containing message body and properties.
     '''
     _validate_not_none('topic_name', topic_name)
     request = HTTPRequest()
     request.method = 'POST'
     request.host = self._get_host()
     request.path = '/' + _str(topic_name) + '/messages'
     request.headers = message.add_headers(request)
     request.body = _get_request_body(message.body)
     request.path, request.query = _update_request_uri_query(request)
     request.headers = self._update_service_bus_header(request)
     response = self._perform_request(request)
Ejemplo n.º 51
0
    def set_table_acl(self, table_name, signed_identifiers=None):
        '''
        Sets stored access policies for the table that may be used with
        Shared Access Signatures.

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

        return _parse_response_for_dict_filter(response, filter=["x-ms-popreceipt", "x-ms-time-next-visible"])
Ejemplo n.º 53
0
 def put_blob(self, container_name, blob_name, blob, x_ms_blob_type, content_encoding=None, content_language=None, content_m_d5=None, cache_control=None, x_ms_blob_content_type=None, x_ms_blob_content_encoding=None, x_ms_blob_content_language=None, x_ms_blob_content_md5=None, x_ms_blob_cache_control=None, x_ms_meta_name_values=None, x_ms_lease_id=None, x_ms_blob_content_length=None, x_ms_blob_sequence_number=None):
     '''
     Creates a new block blob or page blob, or updates the content of an existing block blob. 
     
     container_name: the name of container to put the blob
     blob_name: the name of blob
     x_ms_blob_type: Required. Could be BlockBlob or PageBlob
     x_ms_meta_name_values: A dict containing name, value for metadata.
     x_ms_lease_id: Required if the blob has an active lease.
     blob: the content of blob.
     '''
     _validate_not_none('container_name', container_name)
     _validate_not_none('blob_name', blob_name)
     _validate_not_none('blob', blob)
     _validate_not_none('x_ms_blob_type', x_ms_blob_type)
     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) + ''
     request.headers = [
         ('x-ms-blob-type', _str_or_none(x_ms_blob_type)),
         ('Content-Encoding', _str_or_none(content_encoding)),
         ('Content-Language', _str_or_none(content_language)),
         ('Content-MD5', _str_or_none(content_m_d5)),
         ('Cache-Control', _str_or_none(cache_control)),
         ('x-ms-blob-content-type', _str_or_none(x_ms_blob_content_type)),
         ('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-blob-content-md5', _str_or_none(x_ms_blob_content_md5)),
         ('x-ms-blob-cache-control', _str_or_none(x_ms_blob_cache_control)),
         ('x-ms-meta-name-values', x_ms_meta_name_values),
         ('x-ms-lease-id', _str_or_none(x_ms_lease_id)),
         ('x-ms-blob-content-length', _str_or_none(x_ms_blob_content_length)),
         ('x-ms-blob-sequence-number', _str_or_none(x_ms_blob_sequence_number))
         ]
     request.body = _get_request_body(blob)
     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)
Ejemplo n.º 54
0
    def set_table_acl(self, table_name, signed_identifiers=None):
        '''
        Sets stored access policies for the table that may be used with
        Shared Access Signatures.

        table_name:
            Name of existing table.
        signed_identifiers:
            SignedIdentifers instance
        '''
        _validate_not_none('table_name', table_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(table_name) + '?comp=acl'
        request.body = _get_request_body(
            _convert_signed_identifiers_to_xml(signed_identifiers))
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_table_header(request,
                                                       content_type=None)
        self._perform_request(request)
Ejemplo n.º 55
0
 def put_blob(self, container_name, blob_name, blob, x_ms_blob_type, content_encoding=None, content_language=None, content_md5=None, cache_control=None, x_ms_blob_content_type=None, x_ms_blob_content_encoding=None, x_ms_blob_content_language=None, x_ms_blob_content_md5=None, x_ms_blob_cache_control=None, x_ms_meta_name_values=None, x_ms_lease_id=None, x_ms_blob_content_length=None, x_ms_blob_sequence_number=None):
     '''
     Creates a new block blob or page blob, or updates the content of an existing block blob. 
     
     container_name: the name of container to put the blob
     blob_name: the name of blob
     x_ms_blob_type: Required. Could be BlockBlob or PageBlob
     x_ms_meta_name_values: A dict containing name, value for metadata.
     x_ms_lease_id: Required if the blob has an active lease.
     blob: the content of blob.
     '''
     _validate_not_none('container_name', container_name)
     _validate_not_none('blob_name', blob_name)
     _validate_not_none('blob', blob)
     _validate_not_none('x_ms_blob_type', x_ms_blob_type)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/' + _str(container_name) + '/' + _str(blob_name) + ''
     request.headers = [
         ('x-ms-blob-type', _str_or_none(x_ms_blob_type)),
         ('Content-Encoding', _str_or_none(content_encoding)),
         ('Content-Language', _str_or_none(content_language)),
         ('Content-MD5', _str_or_none(content_md5)),
         ('Cache-Control', _str_or_none(cache_control)),
         ('x-ms-blob-content-type', _str_or_none(x_ms_blob_content_type)),
         ('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-blob-content-md5', _str_or_none(x_ms_blob_content_md5)),
         ('x-ms-blob-cache-control', _str_or_none(x_ms_blob_cache_control)),
         ('x-ms-meta-name-values', x_ms_meta_name_values),
         ('x-ms-lease-id', _str_or_none(x_ms_lease_id)),
         ('x-ms-blob-content-length', _str_or_none(x_ms_blob_content_length)),
         ('x-ms-blob-sequence-number', _str_or_none(x_ms_blob_sequence_number))
         ]
     request.body = _get_request_body(blob)
     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)
Ejemplo n.º 56
0
    def perform_put(self, path, body, x_ms_version=None):
        '''
        Performs a PUT request and returns the response.

        path:
            Path to the resource.
            Ex: '/<subscription-id>/services/hostedservices/<service-name>'
        body:
            Body for the PUT request.
        x_ms_version:
            If specified, this is used for the x-ms-version header.
            Otherwise, self.x_ms_version is used.
        '''
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self.host
        request.path = path
        request.body = _get_request_body(body)
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_management_header(request, x_ms_version)
        response = self._perform_request(request)

        return response
Ejemplo n.º 57
0
    def update_event_hub(self, hub_name, hub=None):
        '''
        Updates an Event Hub.

        hub_name:
            Name of event hub.
        hub:
            Optional. Event hub properties. Instance of EventHub class.
        hub.message_retention_in_days:
            Number of days to retain the events for this Event Hub.
        '''
        _validate_not_none('hub_name', hub_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(hub_name) + '?api-version=2014-01'
        request.body = _get_request_body(_convert_event_hub_to_xml(hub))
        request.path, request.query = _update_request_uri_query(request)
        request.headers.append(('If-Match', '*'))
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _convert_response_to_event_hub(response)
Ejemplo n.º 58
0
    def update_event_hub(self, hub_name, hub=None):
        '''
        Updates an Event Hub.

        hub_name:
            Name of event hub.
        hub:
            Optional. Event hub properties. Instance of EventHub class.
        hub.message_retention_in_days:
            Number of days to retain the events for this Event Hub.
        '''
        _validate_not_none('hub_name', hub_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(hub_name) + '?api-version=2014-01'
        request.body = _get_request_body(_convert_event_hub_to_xml(hub))
        request.path, request.query = _update_request_uri_query(request)
        request.headers.append(('If-Match', '*'))
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _convert_response_to_event_hub(response)
class _ServiceManagementClient(object):
    def __init__(self,
                 subscription_id=None,
                 cert_file=None,
                 host=MANAGEMENT_HOST):
        self.requestid = None
        self.subscription_id = subscription_id
        self.cert_file = cert_file
        self.host = host

        if not self.cert_file:
            if os.environ.has_key(AZURE_MANAGEMENT_CERTFILE):
                self.cert_file = os.environ[AZURE_MANAGEMENT_CERTFILE]

        if not self.subscription_id:
            if os.environ.has_key(AZURE_MANAGEMENT_SUBSCRIPTIONID):
                self.subscription_id = os.environ[
                    AZURE_MANAGEMENT_SUBSCRIPTIONID]

        if not self.cert_file or not self.subscription_id:
            raise WindowsAzureError(
                'You need to provide subscription id and certificate file')

        self._httpclient = _HTTPClient(service_instance=self,
                                       cert_file=self.cert_file)
        self._filter = self._httpclient.perform_request

    def with_filter(self, filter):
        '''Returns a new service which will process requests with the
        specified filter.  Filtering operations can include logging, automatic
        retrying, etc...  The filter is a lambda which receives the HTTPRequest
        and another lambda.  The filter can perform any pre-processing on the
        request, pass it off to the next lambda, and then perform any post-processing
        on the response.'''
        res = ServiceManagementService(self.subscription_id, self.cert_file)
        old_filter = self._filter

        def new_filter(request):
            return filter(request, old_filter)

        res._filter = new_filter
        return res

    def set_proxy(self, host, port, user=None, password=None):
        '''
        Sets the proxy server host and port for the HTTP CONNECT Tunnelling.

        host: Address of the proxy. Ex: '192.168.0.100'
        port: Port of the proxy. Ex: 6000
        user: User for proxy authorization.
        password: Password for proxy authorization.
        '''
        self._httpclient.set_proxy(host, port, user, password)

    #--Helper functions --------------------------------------------------
    def _perform_request(self, request):
        try:
            resp = self._filter(request)
        except HTTPError as e:
            return _management_error_handler(e)

        return resp

    def _perform_get(self, path, response_type):
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self.host
        request.path = path
        request.path, request.query = _update_request_uri_query(request)
        request.headers = _update_management_header(request)
        response = self._perform_request(request)

        if response_type is not None:
            return _parse_response(response, response_type)

        return response

    def _perform_put(self, path, body, async=False):
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self.host
        request.path = path
        request.body = _get_request_body(body)
        request.path, request.query = _update_request_uri_query(request)
        request.headers = _update_management_header(request)
        response = self._perform_request(request)

        if async:
            return _parse_response_for_async_op(response)

        return None