pyrax
Python Bindings for the Rackspace Cloud
 All Classes Namespaces Files Functions Variables Properties
Public Member Functions
StorageObjectManager Class Reference

Handles all the interactions with StorageObjects. More...

Inheritance diagram for StorageObjectManager:
BaseManager FakeStorageObjectManager

List of all members.

Public Member Functions

def name
 The URI base is the same as the container name.
def container
def list
def get
 Gets the information about the specified object.
def create
 Creates or replaces a storage object in this container.
def fetch
 Fetches the object from storage.
def fetch_partial
 Returns the first 'size' bytes of an object.
def delete
 Deletes the object if it exists; raises NoSuchObject exception if it does not exist.
def delete_all_objects
 Deletes all objects from this container.
def download
 Fetches the object from storage, and writes it to the specified directory.
def purge
 Removes a CDN-enabled object from public access before the TTL expires.
def get_metadata
 Returns the metadata for the specified object as a dict.
def set_metadata
 Accepts a dictionary of metadata key/value pairs and updates the specified object metadata with them.
def remove_metadata_key
 Removes the specified key from the object's metadata.

Detailed Description

Handles all the interactions with StorageObjects.


Member Function Documentation

def container (   self)
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,
  obj 
)

Deletes the object if it exists; raises NoSuchObject exception if it does not exist.

Reimplemented from BaseManager.

def delete_all_objects (   self,
  nms,
  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 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 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, the 'include_meta' parameter is ignored.

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,
  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,
  obj 
)

Gets the information about the specified object.

This overrides the base behavior, since Swift uses HEAD to get information, and GET to download the object.

Reimplemented from BaseManager.

def get_metadata (   self,
  obj,
  prefix = None 
)

Returns the metadata for the specified object as a dict.

def list (   self,
  marker = None,
  limit = None,
  prefix = None,
  delimiter = None,
  end_marker = None,
  return_raw = False 
)
def name (   self)

The URI base is the same as the container name.

def purge (   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_metadata_key (   self,
  obj,
  key 
)

Removes the specified key from the object's metadata.

If the key does not exist in the metadata, nothing is done.

def set_metadata (   self,
  obj,
  metadata,
  clear = False,
  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.

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.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Properties