def _storage_error_handler(http_error): ''' Simple error handler for storage service. Will add more specific cases ''' if http_error.status == 409: raise WindowsAzureConflictError(azure._ERROR_CONFLICT) elif http_error.status == 404: raise WindowsAzureMissingResourceError(azure._ERROR_NOT_FOUND) else: raise WindowsAzureError(azure._ERROR_UNKNOWN % http_error.message)
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