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)
Containers will rarely if ever need to be instantiated directly by the user.
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.
 
acl_user_agent(*args, **kwargs)
Enable ACL restriction by User Agent for this container.
 
acl_referrer(*args, **kwargs)
Enable ACL restriction by referrer for 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.
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)
str cdn_acl_referrer
enable ACL restriction by Referrer for this container.
str cdn_acl_user_agent
enable ACL restriction by User Agent for this container.
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)
(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__

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)

acl_user_agent(*args, **kwargs)

 

Enable ACL restriction by User Agent for this container.

>>> container.acl_user_agent("Mozilla")
Parameters:
  • cdn_acl_user_agent (str) - Set the user agent ACL
Decorators:
  • @requires_name(InvalidContainerName)

acl_referrer(*args, **kwargs)

 

Enable ACL restriction by referrer for this container.

>>> container.acl_referrer("http://www.example.com")
Parameters:
  • cdn_acl_user_agent (str) - Set the referrer ACL
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.YYYYMMDDHH-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)

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)