pyrax
Python Bindings for the Rackspace Cloud
|
Public Member Functions | |
def | __init__ |
def | __repr__ |
def | id |
Since a container's name serves as its ID, this will allow both to be used. | |
def | get_metadata |
Returns a dictionary containing the metadata for this container. | |
def | set_metadata |
Accepts a dictionary of metadata key/value pairs and updates the specified container metadata with them. | |
def | remove_metadata_key |
Removes the specified key from the container's metadata. | |
def | set_web_index_page |
Sets the header indicating the index page in this container when creating a static website. | |
def | set_web_error_page |
Sets the header indicating the error page in this container when creating a static website. | |
def | make_public |
Enables CDN access for this container, and optionally sets the TTL. | |
def | make_private |
Disables CDN access to this container. | |
def | purge_cdn_object |
Removes a CDN-enabled object from public access before the TTL expires. | |
def | get_object |
Returns a StorageObject matching the specified item. | |
def | list |
List the objects in this container, using the parameters to control the number and content of objects. | |
def | list_all |
List all the objects in this container, optionally filtered by an initial prefix. | |
def | list_object_names |
Returns a list of the names of all the objects in this container. | |
def | find |
Finds a single object with attributes matching ``**kwargs``. | |
def | findall |
Finds all objects with attributes matching ``**kwargs``. | |
def | create |
Creates or replaces a storage object in this container. | |
def | store_object |
Creates a new object in this container, and populates it with the given data. | |
def | upload_file |
Uploads the specified file to this container. | |
def | fetch |
Fetches the object from storage. | |
def | fetch_object |
Alias for self.fetch(); included for backwards compatibility. | |
def | fetch_partial |
Returns the first 'size' bytes of an object. | |
def | download |
Fetches the object from storage, and writes it to the specified directory. | |
def | download_object |
Alias for self.download(); included for backwards compatibility. | |
def | delete |
Deletes this Container. | |
def | delete_object |
Deletes the object from this container. | |
def | delete_object_in_seconds |
Sets the object in this container to be deleted after the specified number of seconds. | |
def | delete_all_objects |
Deletes all objects from this container. | |
def | copy_object |
Copies the object to the new container, optionally giving it a new name. | |
def | move_object |
Works just like copy_object, except that the source object is deleted after a successful copy. | |
def | change_object_content_type |
Copies object to itself, but applies a new content-type. | |
def | get_temp_url |
Given a storage object in this container, returns a URL that can be used to access that object. | |
def | get_object_metadata |
Returns the metadata for the specified object as a dict. | |
def | set_object_metadata |
Accepts a dictionary of metadata key/value pairs and updates the specified object metadata with them. | |
def | list_subdirs |
Return a list of the namesrepresenting the pseudo-subdirectories in this container. | |
def | remove_from_cache |
Not used anymore. | |
Public Attributes | |
object_manager | |
get_objects | |
get_object_names | |
Properties | |
cdn_enabled = property(_get_cdn_enabled, _set_cdn_enabled) | |
cdn_log_retention = property(_get_cdn_log_retention, _set_cdn_log_retention) | |
cdn_uri = property(_get_cdn_uri, _set_cdn_uri) | |
cdn_ttl = property(_get_cdn_ttl, _set_cdn_ttl) | |
cdn_ssl_uri = property(_get_cdn_ssl_uri, _set_cdn_ssl_uri) | |
cdn_streaming_uri = property(_get_cdn_streaming_uri, _set_cdn_streaming_uri) | |
cdn_ios_uri = property(_get_cdn_ios_uri, _set_cdn_ios_uri) |
def __init__ | ( | self, | |
args, | |||
kwargs | |||
) |
Reimplemented in FakeContainer.
def __repr__ | ( | self | ) |
Reimplemented from BaseResource.
def change_object_content_type | ( | self, | |
obj, | |||
new_ctype, | |||
guess = False |
|||
) |
Copies object to itself, but applies a new content-type.
The guess feature requires this container to be CDN-enabled. If not, then the content-type must be supplied. If using guess with a CDN-enabled container, new_ctype can be set to None. Failure during the put will result in an exception.
def copy_object | ( | self, | |
obj, | |||
new_container, | |||
new_obj_name = None , |
|||
content_type = None |
|||
) |
Copies the object to the new container, optionally giving it a new name.
If you copy to the same container, you must supply a different name.
def create | ( | self, | |
file_or_path = None , |
|||
data = None , |
|||
obj_name = None , |
|||
content_type = None , |
|||
etag = None , |
|||
content_encoding = None , |
|||
content_length = None , |
|||
ttl = None , |
|||
chunked = False , |
|||
metadata = None , |
|||
chunk_size = None , |
|||
headers = None , |
|||
return_none = False |
|||
) |
Creates or replaces a storage object in this container.
The content of the object can either be a stream of bytes (`data`), or a file on disk (`file_or_path`). The disk file can be either an open file-like object, or an absolute path to the file on disk.
When creating object from a data stream, you must specify the name of the object to be created in the container via the `obj_name` parameter. When working with a file, though, if no `obj_name` value is specified, the file`s name will be used.
You may optionally set the `content_type` and `content_encoding` parameters; pyrax will create the appropriate headers when the object is stored. If no `content_type` is specified, the object storage system will make an intelligent guess based on the content of the object.
If the size of the file is known, it can be passed as `content_length`.
If you wish for the object to be temporary, specify the time it should be stored in seconds in the `ttl` parameter. If this is specified, the object will be deleted after that number of seconds.
If you wish to store a stream of data (i.e., where you don't know the total size in advance), set the `chunked` parameter to True, and omit the `content_length` and `etag` parameters. This allows the data to be streamed to the object in the container without having to be written to disk first.
def delete | ( | self, | |
del_objects = False |
|||
) |
Deletes this Container.
If the container contains objects, the command will fail unless 'del_objects' is passed as True. In that case, each object will be deleted first, and then the container.
def delete_all_objects | ( | self, | |
async = False |
|||
) |
Deletes all objects from this container.
By default the call will block until all objects have been deleted. By passing True for the 'async' parameter, this method will not block, and instead return an object that can be used to follow the progress of the deletion. When deletion is complete the bulk deletion object's 'results' attribute will be populated with the information returned from the API call. In synchronous mode this is the value that is returned when the call completes. It is a dictionary with the following keys:
deleted - the number of objects deleted not_found - the number of objects not found status - the HTTP return status code. '200 OK' indicates success errors - a list of any errors returned by the bulk delete call
def delete_object | ( | self, | |
obj | |||
) |
Deletes the object from this container.
The 'obj' parameter can either be the name of the object, or a StorageObject representing the object to be deleted.
def delete_object_in_seconds | ( | self, | |
obj, | |||
seconds, | |||
extra_info = None |
|||
) |
Sets the object in this container to be deleted after the specified number of seconds.
The 'extra_info' parameter is included for backwards compatibility. It is no longer used at all, and will not be modified with swiftclient info, since swiftclient is not used any more.
def download | ( | self, | |
obj, | |||
directory, | |||
structure = True |
|||
) |
Fetches the object from storage, and writes it to the specified directory.
The directory must exist before calling this method.
If the object name represents a nested folder structure, such as "foo/bar/baz.txt", that folder structure will be created in the target directory by default. If you do not want the nested folders to be created, pass `structure=False` in the parameters.
def download_object | ( | self, | |
obj_name, | |||
directory, | |||
structure = True |
|||
) |
Alias for self.download(); included for backwards compatibility.
def fetch | ( | self, | |
obj, | |||
include_meta = False , |
|||
chunk_size = None , |
|||
size = None , |
|||
extra_info = None |
|||
) |
Fetches the object from storage.
If 'include_meta' is False, only the bytes representing the stored object are returned.
Note: if 'chunk_size' is defined, you must fully read the object's contents before making another request.
If 'size' is specified, only the first 'size' bytes of the object will be returned. If the object if smaller than 'size', the entire object is returned.
When 'include_meta' is True, what is returned from this method is a 2-tuple: Element 0: a dictionary containing metadata about the file. Element 1: a stream of bytes representing the object's contents.
The 'extra_info' parameter is included for backwards compatibility. It is no longer used at all, and will not be modified with swiftclient info, since swiftclient is not used any more.
def fetch_object | ( | self, | |
obj_name, | |||
include_meta = False , |
|||
chunk_size = None |
|||
) |
Alias for self.fetch(); included for backwards compatibility.
def fetch_partial | ( | self, | |
obj, | |||
size | |||
) |
Returns the first 'size' bytes of an object.
If the object is smaller than the specified 'size' value, the entire object is returned.
def find | ( | self, | |
kwargs | |||
) |
Finds a single object with attributes matching ``**kwargs``.
This isn't very efficient: it loads the entire list then filters on the Python side.
def findall | ( | self, | |
kwargs | |||
) |
Finds all objects with attributes matching ``**kwargs``.
This isn't very efficient: it loads the entire list then filters on the Python side.
def get_metadata | ( | self, | |
prefix = None |
|||
) |
Returns a dictionary containing the metadata for this container.
def get_object | ( | self, | |
item | |||
) |
Returns a StorageObject matching the specified item.
If no such object exists, a NotFound exception is raised. If 'item' is not a string, that item is returned unchanged.
def get_object_metadata | ( | self, | |
obj | |||
) |
Returns the metadata for the specified object as a dict.
def get_temp_url | ( | self, | |
obj, | |||
seconds, | |||
method = "GET" , |
|||
key = None , |
|||
cached = True |
|||
) |
Given a storage object in this container, returns a URL that can be used to access that object.
The URL will expire after `seconds` seconds.
The only methods supported are GET and PUT. Anything else will raise an `InvalidTemporaryURLMethod` exception.
If you have your Temporary URL key, you can pass it in directly and potentially save an API call to retrieve it. If you don't pass in the key, and don't wish to use any cached value, pass `cached=False`.
def id | ( | self | ) |
Since a container's name serves as its ID, this will allow both to be used.
def list | ( | self, | |
marker = None , |
|||
limit = None , |
|||
prefix = None , |
|||
delimiter = None , |
|||
end_marker = None , |
|||
full_listing = False , |
|||
return_raw = False |
|||
) |
List the objects in this container, using the parameters to control the number and content of objects.
Note that this is limited by the absolute request limits of Swift (currently 10,000 objects). If you need to list all objects in the container, use the `list_all()` method instead.
def list_all | ( | self, | |
prefix = None |
|||
) |
List all the objects in this container, optionally filtered by an initial prefix.
Returns an iterator that will yield all the objects in the container, even if the number exceeds the absolute limits of Swift.
def list_object_names | ( | self, | |
marker = None , |
|||
limit = None , |
|||
prefix = None , |
|||
delimiter = None , |
|||
end_marker = None , |
|||
full_listing = False |
|||
) |
Returns a list of the names of all the objects in this container.
The same pagination parameters apply as in self.list().
def list_subdirs | ( | self, | |
marker = None , |
|||
limit = None , |
|||
prefix = None , |
|||
delimiter = None , |
|||
full_listing = False |
|||
) |
Return a list of the namesrepresenting the pseudo-subdirectories in this container.
You can use the marker and limit params to handle pagination, and the prefix param to filter the objects returned. The delimiter param is there for backwards compatibility only, as the call requires the delimiter to be '/'.
def make_private | ( | self | ) |
Disables CDN access to this container.
It may still appear public until the TTL expires.
def make_public | ( | self, | |
ttl = None |
|||
) |
Enables CDN access for this container, and optionally sets the TTL.
def move_object | ( | self, | |
obj, | |||
new_container, | |||
new_obj_name = None , |
|||
new_reference = False , |
|||
content_type = None , |
|||
extra_info = None |
|||
) |
Works just like copy_object, except that the source object is deleted after a successful copy.
You can optionally change the content_type of the object by supplying that in the 'content_type' parameter.
NOTE: any references to the original object will no longer be valid; you will have to get a reference to the new object by passing True for the 'new_reference' parameter. When this is True, a reference to the newly moved object is returned. Otherwise, the etag for the moved object is returned.
The 'extra_info' parameter is included for backwards compatibility. It is no longer used at all, and will not be modified with swiftclient info, since swiftclient is not used any more.
def purge_cdn_object | ( | self, | |
obj, | |||
email_addresses = None |
|||
) |
Removes a CDN-enabled object from public access before the TTL expires.
Please note that there is a limit (at this time) of 25 such requests; if you need to purge more than that, you must contact support.
If one or more email_addresses are included, an email confirming the purge is sent to each address.
def remove_from_cache | ( | self, | |
obj | |||
) |
Not used anymore.
Included for backwards compatibility.
def remove_metadata_key | ( | self, | |
key, | |||
prefix = None |
|||
) |
Removes the specified key from the container's metadata.
If the key does not exist in the metadata, nothing is done.
def set_metadata | ( | self, | |
metadata, | |||
clear = False , |
|||
prefix = None |
|||
) |
Accepts a dictionary of metadata key/value pairs and updates the specified container metadata with them.
If 'clear' is True, any existing metadata is deleted and only the passed metadata is retained. Otherwise, the values passed here update the container's metadata.
The 'extra_info' parameter is included for backwards compatibility. It is no longer used at all, and will not be modified with swiftclient info, since swiftclient is not used any more.
By default, the standard container metadata prefix ('X-Container-Meta-') is prepended to the header name if it isn't present. For non-standard headers, you must include a non-None prefix, such as an empty string.
def set_object_metadata | ( | self, | |
obj, | |||
metadata, | |||
clear = False , |
|||
extra_info = None , |
|||
prefix = None |
|||
) |
Accepts a dictionary of metadata key/value pairs and updates the specified object metadata with them.
If 'clear' is True, any existing metadata is deleted and only the passed metadata is retained. Otherwise, the values passed here update the object's metadata.
The 'extra_info' parameter is included for backwards compatibility. It is no longer used at all, and will not be modified with swiftclient info, since swiftclient is not used any more.
By default, the standard object metadata prefix ('X-Object-Meta-') is prepended to the header name if it isn't present. For non-standard headers, you must include a non-None prefix, such as an empty string.
def set_web_error_page | ( | self, | |
page | |||
) |
Sets the header indicating the error page in this container when creating a static website.
Note: the container must be CDN-enabled for this to have any effect.
def set_web_index_page | ( | self, | |
page | |||
) |
Sets the header indicating the index page in this container when creating a static website.
Note: the container must be CDN-enabled for this to have any effect.
def store_object | ( | self, | |
obj_name, | |||
data, | |||
content_type = None , |
|||
etag = None , |
|||
content_encoding = None , |
|||
ttl = None , |
|||
return_none = False , |
|||
headers = None , |
|||
extra_info = None |
|||
) |
Creates a new object in this container, and populates it with the given data.
A StorageObject reference to the uploaded file will be returned, unless 'return_none' is set to True.
The 'extra_info' parameter is included for backwards compatibility. It is no longer used at all, and will not be modified with swiftclient info, since swiftclient is not used any more.
def upload_file | ( | self, | |
file_or_path, | |||
obj_name = None , |
|||
content_type = None , |
|||
etag = None , |
|||
return_none = False , |
|||
content_encoding = None , |
|||
ttl = None , |
|||
content_length = None , |
|||
headers = None |
|||
) |
Uploads the specified file to this container.
If no name is supplied, the file's name will be used. Either a file path or an open file-like object may be supplied. A StorageObject reference to the uploaded file will be returned, unless 'return_none' is set to True.
You may optionally set the `content_type` and `content_encoding` parameters; pyrax will create the appropriate headers when the object is stored.
If the size of the file is known, it can be passed as `content_length`.
If you wish for the object to be temporary, specify the time it should be stored in seconds in the `ttl` parameter. If this is specified, the object will be deleted after that number of seconds.
The 'extra_info' parameter is included for backwards compatibility. It is no longer used at all, and will not be modified with swiftclient info, since swiftclient is not used any more.
Reimplemented in FakeContainer.
cdn_enabled = property(_get_cdn_enabled, _set_cdn_enabled) [static] |
cdn_ios_uri = property(_get_cdn_ios_uri, _set_cdn_ios_uri) [static] |
cdn_log_retention = property(_get_cdn_log_retention, _set_cdn_log_retention) [static] |
cdn_ssl_uri = property(_get_cdn_ssl_uri, _set_cdn_ssl_uri) [static] |
cdn_streaming_uri = property(_get_cdn_streaming_uri, _set_cdn_streaming_uri) [static] |
cdn_ttl = property(_get_cdn_ttl, _set_cdn_ttl) [static] |
cdn_uri = property(_get_cdn_uri, _set_cdn_uri) [static] |