Exemplo n.º 1
0
 def create_container(self, container_name, x_ms_meta_name_values=None, x_ms_blob_public_access=None, fail_on_exist=False):
     '''
     Creates a new container under the specified account. If the container with the same name 
     already exists, the operation fails.
     
     x_ms_meta_name_values: Optional. A dict with name_value pairs to associate with the 
             container as metadata. Example:{'Category':'test'}
     x_ms_blob_public_access: Optional. Possible values include: container, blob.
     fail_on_exist: specify whether to throw an exception when the container exists.
     '''
     _validate_not_none('container_name', container_name)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = _get_blob_host(self.account_name, self.use_local_storage)
     request.path = '/' + str(container_name) + '?restype=container'
     request.headers = [
         ('x-ms-meta-name-values', x_ms_meta_name_values),
         ('x-ms-blob-public-access', _str_or_none(x_ms_blob_public_access))
         ]
     request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
     request.headers = _update_storage_blob_header(request, self.account_name, self.account_key)
     if not fail_on_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_on_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
 def 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
Exemplo n.º 3
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
 def create_container(self, container_name, x_ms_meta_name_values=None, x_ms_blob_public_access=None, fail_on_exist=False):
     '''
     Creates a new container under the specified account. If the container with the same name 
     already exists, the operation fails.
     
     x_ms_meta_name_values: Optional. A dict with name_value pairs to associate with the 
             container as metadata. Example:{'Category':'test'}
     x_ms_blob_public_access: Optional. Possible values include: container, blob.
     fail_on_exist: specify whether to throw an exception when the container exists.
     '''
     _validate_not_none('container_name', container_name)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/' + _str(container_name) + '?restype=container'
     request.headers = [
         ('x-ms-meta-name-values', x_ms_meta_name_values),
         ('x-ms-blob-public-access', _str_or_none(x_ms_blob_public_access))
         ]
     request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
     request.headers = _update_storage_blob_header(request, self.account_name, self.account_key)
     if not fail_on_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_on_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
Exemplo n.º 5
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
Exemplo n.º 6
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
 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
 def create_queue(self, queue_name, x_ms_meta_name_values=None, fail_on_exist=False):
     """
     Creates a queue under the given account.
     
     queue_name: name of the queue.
     x_ms_meta_name_values: Optional. A dict containing name-value pairs to associate 
     		with the queue as metadata.
     fail_on_exist: specify whether throw exception when queue exists.
     """
     _validate_not_none("queue_name", queue_name)
     request = HTTPRequest()
     request.method = "PUT"
     request.host = self._get_host()
     request.path = "/" + str(queue_name) + ""
     request.headers = [("x-ms-meta-name-values", x_ms_meta_name_values)]
     request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
     request.headers = _update_storage_queue_header(request, self.account_name, self.account_key)
     if not fail_on_exist:
         try:
             response = self._perform_request(request)
             if response.status == HTTP_RESPONSE_NO_CONTENT:
                 return False
             return True
         except WindowsAzureError as e:
             _dont_fail_on_exist(e)
             return False
     else:
         response = self._perform_request(request)
         if response.status == HTTP_RESPONSE_NO_CONTENT:
             raise WindowsAzureConflictError(azure._ERROR_CONFLICT)
         return True
Exemplo n.º 9
0
 def create_queue(self,
                  queue_name,
                  x_ms_meta_name_values=None,
                  fail_on_exist=False):
     '''
     Creates a queue under the given account.
     
     queue_name: name of the queue.
     x_ms_meta_name_values: Optional. A dict containing name-value pairs to associate 
     		with the queue as metadata.
     fail_on_exist: specify whether throw exception when queue exists.
     '''
     _validate_not_none('queue_name', queue_name)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = _get_queue_host(self.account_name,
                                    self.use_local_storage)
     request.path = '/' + str(queue_name) + ''
     request.headers = [('x-ms-meta-name-values', x_ms_meta_name_values)]
     request.path, request.query = _update_request_uri_query_local_storage(
         request, self.use_local_storage)
     request.headers = _update_storage_queue_header(request,
                                                    self.account_name,
                                                    self.account_key)
     if not fail_on_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_on_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
Exemplo n.º 10
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
Exemplo n.º 11
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
Exemplo n.º 12
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
    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
    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
Exemplo n.º 15
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
Exemplo n.º 16
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
 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
Exemplo n.º 18
0
 def create_table(self, table, fail_on_exist=False):
     '''
     Creates a new table in the storage account.
     
     table: name of the table to create. Table name may contain only alphanumeric characters
          and cannot begin with a numeric character. It is case-insensitive and must be from 
     	 3 to 63 characters long.
     fail_on_exist: specify whether throw exception when table exists.
     '''
     _validate_not_none('table', table)
     request = HTTPRequest()
     request.method = 'POST'
     request.host = _get_table_host(self.account_name, self.use_local_storage)
     request.path = '/Tables'
     request.body = _get_request_body(convert_table_to_xml(table))
     request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage)
     request.headers = _update_storage_table_header(request)
     if not fail_on_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_on_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
    def create_hosted_service(self, hosted_service):
        '''
        Creates a new hosted service in Windows Azure under given subscription.
        '''
        _validate_not_none('hosted_service', hosted_service)
        request = HTTPRequest()
        request.method = 'POST'
        request.host = HOSTED_SERVICE_HOST_BASE
        request.path = '/' + self.subscription_id + '/services/hostedservices'
        request.body = _convert_hosted_service_to_xml(hosted_service)
        request.headers = _update_hosted_service_header(request)

        try:
            self._perform_request(request)
            return True
        except WindowsAzureError as e:
            _dont_fail_on_exist(e)
            return False
Exemplo n.º 20
0
    def create_queue(self,
                     queue_name,
                     x_ms_meta_name_values=None,
                     fail_on_exist=False):
        '''
        Creates a queue under the given account.

        queue_name:
            name of the queue.
        x_ms_meta_name_values:
            Optional. A dict containing name-value pairs to associate with the
            queue as metadata.
        fail_on_exist:
            Specify whether throw exception when queue exists.
        '''
        _validate_not_none('queue_name', queue_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + ''
        request.headers = [('x-ms-meta-name-values', x_ms_meta_name_values)]
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_queue_header(request,
                                                       self.account_name,
                                                       self.account_key)
        if not fail_on_exist:
            try:
                response = self._perform_request(request)
                if response.status == HTTP_RESPONSE_NO_CONTENT:
                    return False
                return True
            except WindowsAzureError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            response = self._perform_request(request)
            if response.status == HTTP_RESPONSE_NO_CONTENT:
                raise WindowsAzureConflictError(
                    _ERROR_CONFLICT.format(response.message))
            return True
Exemplo n.º 21
0
    def create_queue(self, queue_name, x_ms_meta_name_values=None,
                     fail_on_exist=False):
        '''
        Creates a queue under the given account.

        queue_name:
            name of the queue.
        x_ms_meta_name_values:
            Optional. A dict containing name-value pairs to associate with the
            queue as metadata.
        fail_on_exist:
            Specify whether throw exception when queue exists.
        '''
        _validate_not_none('queue_name', queue_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + ''
        request.headers = [('x-ms-meta-name-values', x_ms_meta_name_values)]
        request.path, request.query = _update_request_uri_query_local_storage(
            request, self.use_local_storage)
        request.headers = _update_storage_queue_header(
            request, self.authentication)
        if not fail_on_exist:
            try:
                response = self._perform_request(request)
                if response.status == HTTP_RESPONSE_NO_CONTENT:
                    return False
                return True
            except WindowsAzureError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            response = self._perform_request(request)
            if response.status == HTTP_RESPONSE_NO_CONTENT:
                raise WindowsAzureConflictError(
                    _ERROR_CONFLICT.format(response.message))
            return True
    def delete_hosted_service(self, hosted_service=None,hosted_service_name=None):
        '''
        Deletes a already created hosted service.
        '''
        hosted_service_to_delete = None
        if hosted_service is not None:
            hosted_service_to_delete = hosted_service.name
        elif hosted_service_name is not None:
            hosted_service_to_delete = hosted_service_name
        else:
            raise TypeError('Both hosted_service and hosted_service_name should not be None.')

        _validate_not_none(hosted_service_to_delete, 'hosted_service_to_delete')
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = HOSTED_SERVICE_HOST_BASE
        request.path = '/' + self.subscription_id + '/services/hostedservices/' + hosted_service_to_delete
        request.headers = _update_hosted_service_header(request)
        try:
            self._perform_request(request)
            return True
        except WindowsAzureError as e:
            _dont_fail_on_exist(e)
            return False