Package cloudfiles :: Module container :: Class Container
[frames] | no frames]

Class Container

source code


Container object and Object instance factory.

If your account has the feature enabled, containers can be publically shared over a global content delivery network.

Instance Methods
 
__init__(self, connection=None, name=None, count=None, size=None, metadata=None)
Containers will rarely if ever need to be instantiated directly by the user.
source code
 
update_metadata(*args, **kwargs)
Update Container Metadata
 
enable_static_web(self, index=None, listings=None, error=None, listings_css=None)
Enable static web for this Container
source code
 
disable_static_web(self)
Disable static web for this Container
source code
 
enable_object_versioning(self, container_name)
Enable object versioning on this container
source code
 
disable_object_versioning(self)
Disable object versioning on this container
source code
 
make_public(*args, **kwargs)
Either publishes the current container to the CDN or updates its CDN attributes.
 
make_private(*args, **kwargs)
Disables CDN access to this container.
 
purge_from_cdn(*args, **kwargs)
Purge Edge cache for all object inside of this container.
 
log_retention(*args, **kwargs)
Enable CDN log retention on the container.
bool
is_public(self)
Returns a boolean indicating whether or not this container is publically accessible via the CDN.
source code
str
public_uri(*args, **kwargs)
Return the URI for this container, if it is publically accessible via the CDN.
str
public_ssl_uri(*args, **kwargs)
Return the SSL URI for this container, if it is publically accessible via the CDN.
str
public_streaming_uri(*args, **kwargs)
Return the Streaming URI for this container, if it is publically accessible via the CDN.
Object
create_object(*args, **kwargs)
Return an Object instance, creating it if necessary.
ObjectResults
get_objects(*args, **kwargs)
Return a result set of all Objects in the Container.
Object
get_object(*args, **kwargs)
Return an Object instance for an existing storage object.
list({"name":"...", "hash":..., "size":..., "type":...})
list_objects_info(*args, **kwargs)
Return information about all objects in the Container.
list(str)
list_objects(*args, **kwargs)
Return names of all Objects in the Container.
 
__getitem__(self, key) source code
 
__str__(self)
str(x)
source code
 
delete_object(*args, **kwargs)
Permanently remove a storage object.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Instance Variables
str name
the container's name (generally treated as read-only)
bool cdn_log_retention
retention of the logs in the container.
number cdn_ttl
the time-to-live of the CDN's public cache of this container (cached, use make_public to alter)
number object_count
the number of objects in this container (cached)
number size_used
the sum of the sizes of all objects in this container (cached)
Properties

Inherited from object: __class__

Method Details

__init__(self, connection=None, name=None, count=None, size=None, metadata=None)
(Constructor)

source code 

Containers will rarely if ever need to be instantiated directly by the user.

Instead, use the create_container, get_container, list_containers and other methods on a valid Connection object.

Overrides: object.__init__

update_metadata(*args, **kwargs)

 

Update Container Metadata

>>> metadata = {'x-container-meta-foo' : 'bar'}
>>> container.update_metadata(metadata)
Parameters:
  • metadata (dict) - A dictionary containing metadata.
Decorators:
  • @requires_name(InvalidContainerName)

enable_static_web(self, index=None, listings=None, error=None, listings_css=None)

source code 

Enable static web for this Container

>>> container.enable_static_web('index.html', 'error.html', True, 'style.css')
Parameters:
  • index (str) - The name of the index landing page
  • listings - A boolean value to enable listing.
  • listings_css (str) - The file to be used when applying CSS to the listing.
  • error (bool) - The suffix to be used for 404 and 401 error pages.

disable_static_web(self)

source code 

Disable static web for this Container

>>> container.disable_static_web()

enable_object_versioning(self, container_name)

source code 

Enable object versioning on this container

>>> container.enable_object_versioning('container_i_want_versions_to_go_to')
Parameters:
  • container_url - The container where versions will be stored
  • container_name (str)

disable_object_versioning(self)

source code 

Disable object versioning on this container

>>> container.disable_object_versioning()

make_public(*args, **kwargs)

 

Either publishes the current container to the CDN or updates its CDN attributes. Requires CDN be enabled on the account.

>>> container.make_public(ttl=604800) # expire in 1 week
Parameters:
  • ttl (number) - cache duration in seconds of the CDN server
Decorators:
  • @requires_name(InvalidContainerName)

make_private(*args, **kwargs)

 

Disables CDN access to this container. It may continue to be available until its TTL expires.

>>> container.make_private()
Decorators:
  • @requires_name(InvalidContainerName)

purge_from_cdn(*args, **kwargs)

 

Purge Edge cache for all object inside of this container. You will be notified by email if one is provided when the job completes.

>>> container.purge_from_cdn("user@dmain.com")

or

>>> container.purge_from_cdn("user@domain.com,user2@domain.com")

or

>>> container.purge_from_cdn()
Parameters:
  • email (str) - A Valid email address
Decorators:
  • @requires_name(InvalidContainerName)

log_retention(*args, **kwargs)

 

Enable CDN log retention on the container. If enabled logs will be periodically (at unpredictable intervals) compressed and uploaded to a ".CDN_ACCESS_LOGS" container in the form of "container_name/YYYY/MM/DD/HH/XXXX.gz". Requires CDN be enabled on the account.

>>> container.log_retention(True)
Parameters:
  • log_retention (bool) - Enable or disable logs retention.
Decorators:
  • @requires_name(InvalidContainerName)

is_public(self)

source code 

Returns a boolean indicating whether or not this container is publically accessible via the CDN.

>>> container.is_public()
False
>>> container.make_public()
>>> container.is_public()
True
Returns: bool
whether or not this container is published to the CDN

public_uri(*args, **kwargs)

 

Return the URI for this container, if it is publically accessible via the CDN.

>>> connection['container1'].public_uri()
'http://c00061.cdn.cloudfiles.rackspacecloud.com'
Returns: str
the public URI for this container
Decorators:
  • @requires_name(InvalidContainerName)

public_ssl_uri(*args, **kwargs)

 

Return the SSL URI for this container, if it is publically accessible via the CDN.

>>> connection['container1'].public_ssl_uri()
'https://c61.ssl.cf0.rackcdn.com'
Returns: str
the public SSL URI for this container
Decorators:
  • @requires_name(InvalidContainerName)

public_streaming_uri(*args, **kwargs)

 

Return the Streaming URI for this container, if it is publically accessible via the CDN.

>>> connection['container1'].public_ssl_uri()
'https://c61.stream.rackcdn.com'
Returns: str
the public Streaming URI for this container
Decorators:
  • @requires_name(InvalidContainerName)

create_object(*args, **kwargs)

 

Return an Object instance, creating it if necessary.

When passed the name of an existing object, this method will return an instance of that object, otherwise it will create a new one.

>>> container.create_object('new_object')
<cloudfiles.storage_object.Object object at 0xb778366c>
>>> obj = container.create_object('new_object')
>>> obj.name
'new_object'
Parameters:
  • object_name (str) - the name of the object to create
Returns: Object
an object representing the newly created storage object
Decorators:
  • @requires_name(InvalidContainerName)

get_objects(*args, **kwargs)

 

Return a result set of all Objects in the Container.

Keyword arguments are treated as HTTP query parameters and can be used to limit the result set (see the API documentation).

>>> container.get_objects(limit=2)
ObjectResults: 2 objects
>>> for obj in container.get_objects():
...     print obj.name
new_object
old_object
Parameters:
  • prefix (str) - filter the results using this prefix
  • limit (int) - return the first "limit" objects found
  • marker (str) - return objects whose names are greater than "marker"
  • path (str) - return all objects in "path"
  • delimiter (char) - use this character as a delimiter for subdirectories
Returns: ObjectResults
an iterable collection of all storage objects in the container
Decorators:
  • @requires_name(InvalidContainerName)

get_object(*args, **kwargs)

 

Return an Object instance for an existing storage object.

If an object with a name matching object_name does not exist then a NoSuchObject exception is raised.

>>> obj = container.get_object('old_object')
>>> obj.name
'old_object'
Parameters:
  • object_name (str) - the name of the object to retrieve
Returns: Object
an Object representing the storage object requested
Decorators:
  • @requires_name(InvalidContainerName)

list_objects_info(*args, **kwargs)

 

Return information about all objects in the Container.

Keyword arguments are treated as HTTP query parameters and can be used limit the result set (see the API documentation).

>>> conn['container1'].list_objects_info(limit=2)
[{u'bytes': 4820,
  u'content_type': u'application/octet-stream',
  u'hash': u'db8b55400b91ce34d800e126e37886f8',
  u'last_modified': u'2008-11-05T00:56:00.406565',
  u'name': u'new_object'},
 {u'bytes': 1896,
  u'content_type': u'application/octet-stream',
  u'hash': u'1b49df63db7bc97cd2a10e391e102d4b',
  u'last_modified': u'2008-11-05T00:56:27.508729',
  u'name': u'old_object'}]
Parameters:
  • prefix (str) - filter the results using this prefix
  • limit (int) - return the first "limit" objects found
  • marker (str) - return objects with names greater than "marker"
  • path (str) - return all objects in "path"
  • delimiter (char) - use this character as a delimiter for subdirectories
Returns: list({"name":"...", "hash":..., "size":..., "type":...})
a list of all container info as dictionaries with the keys "name", "hash", "size", and "type"
Decorators:
  • @requires_name(InvalidContainerName)

list_objects(*args, **kwargs)

 

Return names of all Objects in the Container.

Keyword arguments are treated as HTTP query parameters and can be used to limit the result set (see the API documentation).

>>> container.list_objects()
['new_object', 'old_object']
Parameters:
  • prefix (str) - filter the results using this prefix
  • limit (int) - return the first "limit" objects found
  • marker (str) - return objects with names greater than "marker"
  • path (str) - return all objects in "path"
  • delimiter (char) - use this character as a delimiter for subdirectories
Returns: list(str)
a list of all container names
Decorators:
  • @requires_name(InvalidContainerName)

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

delete_object(*args, **kwargs)

 

Permanently remove a storage object.

>>> container.list_objects()
['new_object', 'old_object']
>>> container.delete_object('old_object')
>>> container.list_objects()
['new_object']
Parameters:
  • object_name (str) - the name of the object to retrieve
Decorators:
  • @requires_name(InvalidContainerName)

Instance Variable Details

name

the container's name (generally treated as read-only)
Get Method:
unreachable(self)
Set Method:
__set_name(self, name)