pyrax
Python Bindings for the Rackspace Cloud
|
Public Member Functions | |
def | get |
Returns a Container matching the specified container name. | |
def | create |
Creates a new container, and returns a Container object that represents that contianer. | |
def | delete |
Deletes the specified container. | |
def | fetch_cdn_data |
Returns a dict containing the CDN information for the specified container. | |
def | get_account_headers |
Return the headers for the account. | |
def | get_headers |
Return the headers for the specified container. | |
def | get_account_metadata |
Returns a dictionary containing metadata about the account. | |
def | set_account_metadata |
Accepts a dictionary of metadata key/value pairs and updates the account metadata with them. | |
def | delete_account_metadata |
Removes all metadata matching the specified prefix from the account. | |
def | get_metadata |
Returns a dictionary containing the metadata for the 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 | delete_metadata |
Removes all of the container's metadata. | |
def | get_cdn_metadata |
Returns a dictionary containing the CDN metadata for the container. | |
def | set_cdn_metadata |
Accepts a dictionary of metadata key/value pairs and updates the specified container metadata with them. | |
def | get_temp_url |
Given a storage object in a container, returns a URL that can be used to access that object. | |
def | list_containers_info |
Returns a list of info on Containers. | |
def | list_public_containers |
Returns a list of the names of all CDN-enabled containers. | |
def | make_public |
Enables CDN access for the specified container, and optionally sets the TTL for the container. | |
def | make_private |
Disables CDN access to a container. | |
def | get_cdn_log_retention |
Returns the status of the setting for CDN log retention for the specified container. | |
def | set_cdn_log_retention |
Enables or disables whether CDN access logs for the specified container are collected and stored on Cloud Files. | |
def | get_container_streaming_uri |
Returns the URI for streaming content, or None if CDN is not enabled. | |
def | get_container_ios_uri |
Returns the iOS URI, or None if CDN is not enabled. | |
def | set_web_index_page |
Sets the header indicating the index page in a container when creating a static website. | |
def | set_web_error_page |
Sets the header indicating the error page in a container when creating a static website. | |
def | purge_cdn_object |
Removes a CDN-enabled object from public access before the TTL expires. | |
def | list_objects |
Return a list of StorageObjects representing the objects in this container. | |
def | list_object_names |
Return a list of then names of the objects in this container. | |
def | object_listing_iterator |
Returns an iterator that can be used to access the objects within this container. | |
def | list_subdirs |
Returns a list of StorageObjects representing the pseudo-subdirectories in the specified container. | |
def | get_object |
Returns a StorageObject representing the requested object. | |
def | create_object |
Creates or replaces a storage object in the specified container. | |
def | fetch_object |
Fetches the object from storage. | |
def | fetch_partial |
Returns the first 'size' bytes of an object. | |
def | download_object |
Fetches the object from storage, and writes it to the specified directory. | |
def | delete_object |
Deletes the object from the specified 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 | delete_object_in_seconds |
Sets the object in the specified container to be deleted after the specified number of seconds. | |
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 change_object_content_type | ( | self, | |
container, | |||
obj, | |||
new_ctype, | |||
guess = False |
|||
) |
Copies object to itself, but applies a new content-type.
The guess feature requires the 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, | |
container, | |||
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.
Returns the etag of the newly-copied object.
You can optionally change the content_type of the object by supplying that in the 'content_type' parameter.
def create | ( | self, | |
name, | |||
metadata = None , |
|||
prefix = None , |
|||
args, | |||
kwargs | |||
) |
Creates a new container, and returns a Container object that represents that contianer.
If a container by the same name already exists, no exception is raised; instead, a reference to that existing container is returned.
def create_object | ( | self, | |
container, | |||
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 the specified container.
Returns a StorageObject reference will be returned, unless the 'return_none' parameter is True.
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.
def delete | ( | self, | |
container, | |||
del_objects = False |
|||
) |
Deletes the specified 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_account_metadata | ( | self, | |
prefix = None |
|||
) |
Removes all metadata matching the specified prefix from the account.
By default, the standard account metadata prefix ('X-Account-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 delete_metadata | ( | self, | |
container, | |||
prefix = None |
|||
) |
Removes all of the container's metadata.
By default, all metadata beginning with the standard container metadata prefix ('X-Container-Meta-') is removed. If you wish to remove all metadata beginning with a different prefix, you must specify that prefix.
def delete_object | ( | self, | |
container, | |||
obj | |||
) |
Deletes the object from the specified 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, | |
cont, | |||
obj, | |||
seconds, | |||
extra_info = None |
|||
) |
Sets the object in the specified 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_object | ( | self, | |
container, | |||
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 fetch_cdn_data | ( | self, | |
container | |||
) |
Returns a dict containing the CDN information for the specified container.
If the container is not CDN-enabled, returns an empty dict.
def fetch_object | ( | self, | |
container, | |||
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_partial | ( | self, | |
container, | |||
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 get | ( | self, | |
container | |||
) |
Returns a Container matching the specified container name.
If no such container exists, a NoSuchContainer exception is raised.
Reimplemented from BaseManager.
def get_account_headers | ( | self | ) |
Return the headers for the account.
This includes all the headers, not just the account-specific headers. The calling program is responsible for only using the ones that it needs.
def get_account_metadata | ( | self, | |
prefix = None |
|||
) |
Returns a dictionary containing metadata about the account.
def get_cdn_log_retention | ( | self, | |
container | |||
) |
Returns the status of the setting for CDN log retention for the specified container.
def get_cdn_metadata | ( | self, | |
container | |||
) |
Returns a dictionary containing the CDN metadata for the container.
If the container does not exist, a NotFound exception is raised. If the container exists, but is not CDN-enabled, a NotCDNEnabled exception is raised.
def get_container_ios_uri | ( | self, | |
container | |||
) |
Returns the iOS URI, or None if CDN is not enabled.
def get_container_streaming_uri | ( | self, | |
container | |||
) |
Returns the URI for streaming content, or None if CDN is not enabled.
def get_headers | ( | self, | |
container | |||
) |
Return the headers for the specified container.
def get_metadata | ( | self, | |
container, | |||
prefix = None |
|||
) |
Returns a dictionary containing the metadata for the container.
def get_object | ( | self, | |
container, | |||
obj | |||
) |
Returns a StorageObject representing the requested object.
def get_object_metadata | ( | self, | |
container, | |||
obj | |||
) |
Returns the metadata for the specified object as a dict.
def get_temp_url | ( | self, | |
container, | |||
obj, | |||
seconds, | |||
method = "GET" , |
|||
key = None , |
|||
cached = True |
|||
) |
Given a storage object in a 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 list_containers_info | ( | self, | |
limit = None , |
|||
marker = None |
|||
) |
Returns a list of info on Containers.
For each container, a dict containing the following keys is returned:
name - the name of the container count - the number of objects in the container bytes - the total bytes in the container
def list_object_names | ( | self, | |
container, | |||
marker = None , |
|||
limit = None , |
|||
prefix = None , |
|||
delimiter = None , |
|||
end_marker = None , |
|||
full_listing = False |
|||
) |
Return a list of then names of the objects in this container.
You can use the marker, end_marker, and limit params to handle pagination, and the prefix and delimiter params to filter the objects returned. By default only the first 10,000 objects are returned; if you need to access more than that, set the 'full_listing' parameter to True.
def list_objects | ( | self, | |
container, | |||
limit = None , |
|||
marker = None , |
|||
prefix = None , |
|||
delimiter = None , |
|||
end_marker = None , |
|||
full_listing = False |
|||
) |
Return a list of StorageObjects representing the objects in this container.
You can use the marker, end_marker, and limit params to handle pagination, and the prefix and delimiter params to filter the objects returned. By default only the first 10,000 objects are returned; if you need to access more than that, set the 'full_listing' parameter to True.
def list_public_containers | ( | self | ) |
Returns a list of the names of all CDN-enabled containers.
def list_subdirs | ( | self, | |
container, | |||
marker = None , |
|||
limit = None , |
|||
prefix = None , |
|||
delimiter = None , |
|||
full_listing = False |
|||
) |
Returns a list of StorageObjects representing the pseudo-subdirectories in the specified container.
You can use the marker and limit params to handle pagination, and the prefix param to filter the objects returned. The 'delimiter' parameter is ignored, as the only meaningful value is '/'.
def make_private | ( | self, | |
container | |||
) |
Disables CDN access to a container.
It may still appear public until its TTL expires.
def make_public | ( | self, | |
container, | |||
ttl = None |
|||
) |
Enables CDN access for the specified container, and optionally sets the TTL for the container.
def move_object | ( | self, | |
container, | |||
obj, | |||
new_container, | |||
new_obj_name = None , |
|||
new_reference = False , |
|||
content_type = 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.
def object_listing_iterator | ( | self, | |
container, | |||
prefix = None |
|||
) |
Returns an iterator that can be used to access the objects within this container.
They can be optionally limited by a prefix.
def purge_cdn_object | ( | self, | |
container, | |||
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_metadata_key | ( | self, | |
container, | |||
key | |||
) |
Removes the specified key from the container's metadata.
If the key does not exist in the metadata, nothing is done.
def set_account_metadata | ( | self, | |
metadata, | |||
clear = False , |
|||
prefix = None |
|||
) |
Accepts a dictionary of metadata key/value pairs and updates the account 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 account's metadata.
By default, the standard account metadata prefix ('X-Account-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_cdn_log_retention | ( | self, | |
container, | |||
enabled | |||
) |
Enables or disables whether CDN access logs for the specified container are collected and stored on Cloud Files.
def set_cdn_metadata | ( | self, | |
container, | |||
metadata | |||
) |
Accepts a dictionary of metadata key/value pairs and updates the specified container metadata with them.
NOTE: arbitrary metadata headers are not allowed. The only metadata you can update are: X-Log-Retention, X-CDN-enabled, and X-TTL.
def set_metadata | ( | self, | |
container, | |||
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.
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, | |
container, | |||
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.
'extra_info; is an optional dictionary which will be populated with 'status', 'reason', and 'headers' keys from the underlying swiftclient call.
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, | |
container, | |||
page | |||
) |
Sets the header indicating the error page in a 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, | |
container, | |||
page | |||
) |
Sets the header indicating the index page in a container when creating a static website.
Note: the container must be CDN-enabled for this to have any effect.