Table Of Contents

Previous topic

Object

This Page

Psst... hey. Did you know you can read about Swift at docs.openstack.org also? Plus you can get to past versions atSwift 1.3 docs and Swift 1.2 docs.

Misc

Exceptions

Constraints

swift.common.constraints.ACCOUNT_LISTING_LIMIT = 10000

Max container list length of a get request for an account

swift.common.constraints.CONTAINER_LISTING_LIMIT = 10000

Max object list length of a get request for a container

swift.common.constraints.FORMAT2CONTENT_TYPE = {'xml': 'application/xml', 'plain': 'text/plain', 'json': 'application/json'}

Query string format= values to their corresponding content-type values

swift.common.constraints.MAX_FILE_SIZE = 5368709122L

Max file size allowed for objects

swift.common.constraints.MAX_META_COUNT = 90

Max number of metadata items

swift.common.constraints.MAX_META_NAME_LENGTH = 128

Max length of the name of a key for metadata

swift.common.constraints.MAX_META_OVERALL_SIZE = 4096

Max overall size of metadata

swift.common.constraints.MAX_META_VALUE_LENGTH = 256

Max length of the value of a key for metadata

swift.common.constraints.MAX_OBJECT_NAME_LENGTH = 1024

Max object name length

swift.common.constraints.check_float(string)

Helper function for checking if a string can be converted to a float.

Parameters:string – string to be verified as a float
Returns:True if the string can be converted to a float, False otherwise
swift.common.constraints.check_metadata(req, target_type)

Check metadata sent in the request headers.

Parameters:
  • req – request object
  • target_type – str: one of: object, container, or account: indicates which type the target storage for the metadata is
Raises HTTPBadRequest:
 

bad metadata

swift.common.constraints.check_mount(root, drive)

Verify that the path to the device is a mount point and mounted. This allows us to fast fail on drives that have been unmounted because of issues, and also prevents us for accidently filling up the root partition.

Parameters:
  • root – base path where the devices are mounted
  • drive – drive name to be checked
Returns:

True if it is a valid mounted device, False otherwise

swift.common.constraints.check_object_creation(req, object_name)

Check to ensure that everything is alright about an object to be created.

Parameters:
  • req – HTTP request object
  • object_name – name of object to be created
Raises:
  • HTTPRequestEntityTooLarge – the object is too large
  • HTTPLengthRequered – missing content-length header and not a chunked request
  • HTTPBadRequest – missing or bad content-type header, or bad metadata
swift.common.constraints.check_utf8(string)

Validate if a string is valid UTF-8 str or unicode

Parameters:string – string to be validated
Returns:True if the string is valid utf-8 str or unicode, False otherwise

Utils

TempAuth

ACLs

WSGI

Direct Client

Internal Client

Buffered HTTP

Healthcheck

class swift.common.middleware.healthcheck.HealthCheckMiddleware(app, *args, **kwargs)

Bases: object

Healthcheck middleware used for monitoring.

If the path is /healthcheck, it will respond with “OK” in the body

GET(req)

Returns a 200 response with “OK” in the body.

Recon

MemCacheD

Lucid comes with memcached: v1.4.2. Protocol documentation for that version is at:

http://github.com/memcached/memcached/blob/1.4.2/doc/protocol.txt

class swift.common.memcached.MemcacheRing(servers, connect_timeout=0.3, io_timeout=2.0, tries=3, allow_pickle=False, allow_unpickle=False)

Bases: object

Simple, consistent-hashed memcache client.

decr(key, delta=1, timeout=0)

Decrements a key which has a numeric value by delta. Calls incr with -delta.

Parameters:
  • key – key
  • delta – amount to subtract to the value of key (or set the value to 0 if the key is not found) will be cast to an int
  • timeout – ttl in memcache
Raises MemcacheConnectionError:
 

delete(key)

Deletes a key/value pair from memcache.

Parameters:key – key to be deleted
get(key)

Gets the object specified by key. It will also unserialize the object before returning if it is serialized in memcache with JSON, or if it is pickled and unpickling is allowed.

Parameters:key – key
Returns:value of the key in memcache
get_multi(keys, server_key)

Gets multiple values from memcache for the given keys.

Parameters:
  • keys – keys for values to be retrieved from memcache
  • servery_key – key to use in determining which server in the ring is used
Returns:

list of values

incr(key, delta=1, timeout=0)

Increments a key which has a numeric value by delta. If the key can’t be found, it’s added as delta or 0 if delta < 0. If passed a negative number, will use memcached’s decr. Returns the int stored in memcached Note: The data memcached stores as the result of incr/decr is an unsigned int. decr’s that result in a number below 0 are stored as 0.

Parameters:
  • key – key
  • delta – amount to add to the value of key (or set as the value if the key is not found) will be cast to an int
  • timeout – ttl in memcache
Raises MemcacheConnectionError:
 

set(key, value, serialize=True, timeout=0)

Set a key/value pair in memcache

Parameters:
  • key – key
  • value – value
  • serialize – if True, value is serialized with JSON before sending to memcache, or with pickle if configured to use pickle instead of JSON (to avoid cache poisoning)
  • timeout – ttl in memcache
set_multi(mapping, server_key, serialize=True, timeout=0)

Sets multiple key/value pairs in memcache.

Parameters:
  • mapping – dictonary of keys and values to be set in memcache
  • servery_key – key to use in determining which server in the ring is used
  • serialize – if True, value is serialized with JSON before sending to memcache, or with pickle if configured to use pickle instead of JSON (to avoid cache poisoning)
  • timeout – ttl for memcache

Manager

Ratelimit

StaticWeb

TempURL

FormPost

Domain Remap

Domain Remap Middleware

Middleware that translates container and account parts of a domain to path parameters that the proxy server understands.

container.account.storageurl/object gets translated to container.account.storageurl/path_root/account/container/object

account.storageurl/path_root/container/object gets translated to account.storageurl/path_root/account/container/object

Browsers can convert a host header to lowercase, so check that reseller prefix on the account is the correct case. This is done by comparing the items in the reseller_prefixes config option to the found prefix. If they match except for case, the item from reseller_prefixes will be used instead of the found reseller prefix. The reseller_prefixes list is exclusive. If defined, any request with an account prefix not in that list will be ignored by this middleware. reseller_prefixes defaults to ‘AUTH’.

Note that this middleware requires that container names and account names (except as described above) must be DNS-compatible. This means that the account name created in the system and the containers created by users cannot exceed 63 characters or have UTF-8 characters. These are restrictions over and above what swift requires and are not explicitly checked. Simply put, the this middleware will do a best-effort attempt to derive account and container names from elements in the domain name and put those derived values into the URL path (leaving the Host header unchanged).

Also note that using container sync with remapped domain names is not advised. With container sync, you should use the true storage end points as sync destinations.

class swift.common.middleware.domain_remap.DomainRemapMiddleware(app, conf)

Bases: object

Domain Remap Middleware

See above for a full description.

Parameters:
  • app – The next WSGI filter or app in the paste.deploy chain.
  • conf – The configuration dict for the middleware.

CNAME Lookup

Proxy Logging