OpenStack Swift Python client binding.
OpenStack Swift client library used internally
Bases: object
Convenience class to make requests that will also retry the request
Requests will have an X-Auth-Token header whose value is either the preauthtoken or a token obtained from the auth service using the user credentials provided as args to the constructor. If os_options includes a service_username then requests will also have an X-Service-Token header whose value is a token obtained from the auth service using the service credentials. In this case the request url will be set to the storage_url obtained from the auth service for the service user, unless this is overridden by a preauthurl.
Parameters: |
|
---|
Wrapper for copy_object()
Wrapper for delete_container()
Wrapper for delete_object()
Wrapper for get_account()
Wrapper for get_container()
Wrapper for get_object()
Wrapper for head_account()
Wrapper for head_container()
Wrapper for head_object()
Wrapper for post_account()
Wrapper for post_container()
Wrapper for post_object()
Wrapper for put_container()
Wrapper for put_object()
Bases: object
Make an HTTPConnection or HTTPSConnection
Parameters: |
|
---|---|
Raises ClientException: | |
Unable to handle protocol scheme |
Adapt requests response to httplib interface
Use python-requests files upload
Parameters: |
|
---|
Encode url and header, then call requests.request
A list of sensitive headers to redact in logs. Note that when extending this list, the header names must be added in all lower case.
Copy object
Parameters: |
|
---|---|
Raises ClientException: | |
HTTP COPY request failed |
Delete a container
Parameters: |
|
---|---|
Raises ClientException: | |
HTTP DELETE request failed |
Delete object
Parameters: |
|
---|---|
Raises ClientException: | |
HTTP DELETE request failed |
Only encode metadata headers keys
Get a listing of containers for the account.
Parameters: |
|
---|---|
Returns: | a tuple of (response headers, a list of containers) The response headers will be a dict and all header names will be lowercase. |
Raises ClientException: | |
HTTP GET request failed |
Get authentication/authorization credentials.
Parameters: |
|
---|---|
Returns: | a tuple, (storage_url, token) |
N.B. if the optional os_options parameter includes a non-empty ‘object_storage_url’ key it will override the the default storage url returned by the auth service.
The snet parameter is used for Rackspace’s ServiceNet internal network implementation. In this function, it simply adds snet- to the beginning of the host name for the returned storage URL. With Rackspace Cloud Files, use of this network path causes no bandwidth charges but requires the client to be running on Rackspace’s ServiceNet network.
Authenticate against a keystone server.
We are using the keystoneclient library for authentication.
Get cluster capability infos.
Parameters: | http_conn – a tuple of (parsed url, HTTPConnection object) |
---|---|
Returns: | a dict containing the cluster capabilities |
Raises ClientException: | |
HTTP Capabilities GET failed |
Get a listing of objects for the container.
Parameters: |
|
---|---|
Returns: | a tuple of (response headers, a list of objects) The response headers will be a dict and all header names will be lowercase. |
Raises ClientException: | |
HTTP GET request failed |
Get an object
Parameters: |
|
---|---|
Returns: | a tuple of (response headers, the object’s contents) The response headers will be a dict and all header names will be lowercase. |
Raises ClientException: | |
HTTP GET request failed |
Get account stats.
Parameters: |
|
---|---|
Returns: | a dict containing the response’s headers (all header names will be lowercase) |
Raises ClientException: | |
HTTP HEAD request failed |
Get container stats.
Parameters: |
|
---|---|
Returns: | a dict containing the response’s headers (all header names will be lowercase) |
Raises ClientException: | |
HTTP HEAD request failed |
Get object info
Parameters: |
|
---|---|
Returns: | a dict containing the response’s headers (all header names will be lowercase) |
Raises ClientException: | |
HTTP HEAD request failed |
Returns: | tuple of (parsed url, connection object) |
---|
Default behaviour is to redact header values known to contain secrets, such as X-Auth-Key and X-Auth-Token. Up to the first 16 chars may be revealed.
To disable, set the value of redact_sensitive_headers to False.
When header redaction is enabled, reveal_sensitive_prefix configures the maximum length of any sensitive header data sent to the logs. If the header is less than twice this length, only int(len(value)/2) chars will be logged; if it is less than 15 chars long, even less will be logged.
Update an account’s metadata.
Parameters: |
|
---|---|
Raises ClientException: | |
HTTP POST request failed |
|
Returns: | resp_headers, body |
Update a container’s metadata.
Parameters: |
|
---|---|
Raises ClientException: | |
HTTP POST request failed |
Update object metadata
Parameters: |
|
---|---|
Raises ClientException: | |
HTTP POST request failed |
Create a container
Parameters: |
|
---|---|
Raises ClientException: | |
HTTP PUT request failed |
Put an object
Parameters: |
|
---|---|
Returns: | etag |
Raises ClientException: | |
HTTP PUT request failed |
Patched version of urllib.quote that encodes utf8 strings before quoting. On Python 3, call directly urllib.parse.quote().
Only show up to logger_settings[‘reveal_sensitive_prefix’] characters from a sensitive header.
Parameters: |
|
---|---|
Returns: | Safe header value |
Redact header values that can contain sensitive information that should not be logged.
Parameters: | headers – Either a dict or an iterable of two-element tuples |
---|---|
Returns: | Safe dictionary of headers with sensitive information removed |
store information about an operation into a dict
Parameters: |
|
---|
Bases: six.Iterator
Bases: object
Class for specifying an object copy, allowing the destination/headers/metadata/fresh_metadata to be specified separately for each individual object. destination and fresh_metadata should be set in options
Bases: exceptions.Exception
Bases: object
Class for specifying an object post, allowing the headers/metadata to be specified separately for each individual object.
Bases: object
Service for performing swift operations
List the cluster capabilities.
Parameters: | url – Proxy URL of the cluster to retrieve capabilities. |
---|---|
Returns: | A dictionary containing the capabilities of the cluster. |
Raises : | ClientException |
Copy operations on a list of objects in a container. Destination containers will be created.
Parameters: |
|
---|---|
Returns: | A generator returning the results of copying the given list of objects. |
Raises : | SwiftError |
Delete operations on an account, optional container and optional list of objects.
Parameters: |
|
---|---|
Returns: | A generator for returning the results of the delete operations. Each result yielded from the generator is either a ‘delete_container’, ‘delete_object’, ‘delete_segment’, or ‘bulk_delete’ dictionary containing the results of an individual delete operation. |
Raises : | ClientException |
Raises : | SwiftError |
Download operations on an account, optional container and optional list of objects.
Parameters: |
|
---|---|
Returns: | A generator for returning the results of the download operations. Each result yielded from the generator is a ‘download_object’ dictionary containing the results of an individual file download. |
Raises : | ClientException |
Raises : | SwiftError |
List operations on an account, container.
Parameters: |
|
---|---|
Returns: | A generator for returning the results of the list operation on an account or container. Each result yielded from the generator is either a ‘list_account_part’ or ‘list_container_part’, containing part of the listing. |
Post operations on an account, container or list of objects
Parameters: |
|
---|---|
Returns: | Either a single result dictionary in the case of a post to a container/account, or an iterator for returning the results of posts to a list of objects. |
Raises : | SwiftError |
Get account stats, container stats or information about a list of objects in a container.
Parameters: |
|
---|---|
Returns: | Either a single dictionary containing stats about an account or container, or an iterator for returning the results of the stat operations on a list of objects. |
Raises : | SwiftError |
Upload a list of objects to a given container.
Parameters: |
|
---|---|
Returns: | A generator for returning the results of the uploads. |
Raises : | SwiftError |
Raises : | ClientException |
Bases: object
Class for specifying an object upload, allowing the object source, name and options to be specified separately for each individual object.
Return a connection building it from the options.
Splits ‘Key: Value’ strings and returns them as a dictionary.
Parameters: |
|
---|
Bases: exceptions.Exception
Bases: concurrent.futures.thread.ThreadPoolExecutor
A wrapper class to maintain a pool of connections alongside the thread pool. We start by creating a priority queue of connections, and each job submitted takes one of those connections (initialising if necessary) and passes it as the first arg to the executed function.
At the end of execution that connection is returned to the queue.
By using a PriorityQueue we avoid creating more connections than required. We will only create as many connections as are required concurrently.
Bases: object
One object to manage context for multi-threading. This should make bin/swift less error-prone and allow us to test this code.
Parameters: |
|
---|
Bases: object
One object to manage and provide helper functions for output.
This object is a context manager and returns itself into the context. When entering the context, two printing threads are created (see below) and they are waited on and cleaned up when exiting the context.
Also, thread-safe printing to two streams is provided. The print_msg() method will print to the supplied print_stream (defaults to sys.stdout) and the error() method will print to the supplied error_stream (defaults to sys.stderr). Both of these printing methods will format the given string with any supplied *args (a la printf). On Python 2, Unicode messages are encoded to utf8.
The attribute self.error_count is incremented once per error message printed, so an application can tell if any worker threads encountered exceptions or otherwise called error() on this instance. The swift command-line tool uses this to exit non-zero if any error strings were printed.
Parameters: |
|
---|
On Python 2, Unicode messages are encoded to utf8.
Miscellaneous utility functions for use with Swift.
Bases: object
Wrap a filelike object with a maximum length.
Fix for https://github.com/kennethreitz/requests/issues/1648. It is recommended to use this class only on files opened in binary mode.
Parameters: |
|
---|
Bases: object
Wrap a filelike object and act as an iterator.
It is recommended to use this class only on files opened in binary mode. Due to the Unicode changes in Python 3, files are now opened using an encoding not suitable for use with the md5 class and because of this hit the exception on every call to next. This could cause problems, especially with large files and small chunk sizes.
Parameters: |
|
---|
Returns True if the value is either True or a string in TRUE_VALUES. Returns False otherwise. This function comes from swift.common.utils.config_true_value()
Generates a temporary URL that gives unauthenticated access to the Swift object.
Parameters: |
|
---|---|
Raises : | ValueError if seconds is not a positive integer |
Raises : | TypeError if seconds is not an integer |
Returns: | the path portion of a temporary URL |
convert a number > 1024 to printable format, either in 4 char -h format as with ls -lh or return as 12 char right justified string
Reports a timestamp and full traceback for a given exception.
Returns: | Full traceback and timestamp. |
---|