Common and Misc Libraries

Libraries common throughout Manila or just ones that haven’t yet been categorized in depth.

The manila.context Module

RequestContext: context for requests that persist through all of manila.

class RequestContext(user_id, project_id, is_admin=None, read_deleted='no', roles=None, remote_address=None, timestamp=None, request_id=None, auth_token=None, overwrite=True, quota_class=None, service_catalog=None, **kwargs)

Bases: object

Security context and request information.

Represents the user taking a given action within the system.

RequestContext.elevated(read_deleted=None, overwrite=False)

Return a version of this context with admin flag set.

classmethod RequestContext.from_dict(values)
RequestContext.read_deleted
RequestContext.tenant
RequestContext.to_dict()
RequestContext.update_store()
RequestContext.user
generate_request_id()
get_admin_context(read_deleted='no')

The manila.exception Module

Manila base exception handling.

Includes decorator for re-raising Manila-type exceptions.

SHOULD include dedicated exception logging.

exception AdminRequired(message=None, **kwargs)

Bases: manila.exception.NotAuthorized

AdminRequired.message = 'User does not have admin privileges.'
exception BridgeDoesNotExist(message=None, **kwargs)

Bases: manila.exception.ManilaException

BridgeDoesNotExist.message = 'Bridge %(bridge)s does not exist.'
exception ConfigNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

ConfigNotFound.message = 'Could not find config at %(path)s.'
exception ConvertedException(code=0, title='', explanation='')

Bases: webob.exc.WSGIHTTPException

exception EMCVnxXMLAPIError(message=None, **kwargs)

Bases: manila.exception.Invalid

EMCVnxXMLAPIError.message = '%(err)s'
exception Error

Bases: exceptions.Exception

exception FileNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

FileNotFound.message = 'File %(file_path)s could not be found.'
exception GlusterfsException(message=None, **kwargs)

Bases: manila.exception.ManilaException

GlusterfsException.message = 'Unknown Gluster exception.'
exception HostBinaryNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

HostBinaryNotFound.message = 'Could not find binary %(binary)s on host %(host)s.'
exception HostNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

HostNotFound.message = 'Host %(host)s could not be found.'
exception InUse(message=None, **kwargs)

Bases: manila.exception.ManilaException

InUse.message = 'Resource is in use.'
exception InstanceNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

InstanceNotFound.message = 'Instance %(instance_id)s could not be found.'
exception Invalid(message=None, **kwargs)

Bases: manila.exception.ManilaException

Invalid.code = 400
Invalid.message = 'Unacceptable parameters.'
exception InvalidContentType(message=None, **kwargs)

Bases: manila.exception.Invalid

InvalidContentType.message = 'Invalid content type %(content_type)s.'
exception InvalidInput(message=None, **kwargs)

Bases: manila.exception.Invalid

InvalidInput.message = 'Invalid input received: %(reason)s.'
exception InvalidParameterValue(message=None, **kwargs)

Bases: manila.exception.Invalid

InvalidParameterValue.message = '%(err)s'
exception InvalidQuotaValue(message=None, **kwargs)

Bases: manila.exception.Invalid

InvalidQuotaValue.msg_fmt = 'Change would make usage less than 0 for the following resources: %(unders)s.'
exception InvalidRequest(message=None, **kwargs)

Bases: manila.exception.Invalid

InvalidRequest.message = 'The request is invalid.'
exception InvalidReservationExpiration(message=None, **kwargs)

Bases: manila.exception.Invalid

InvalidReservationExpiration.message = 'Invalid reservation expiration %(expire)s.'
exception InvalidResults(message=None, **kwargs)

Bases: manila.exception.Invalid

InvalidResults.message = 'The results are invalid.'
exception InvalidShare(message=None, **kwargs)

Bases: manila.exception.Invalid

InvalidShare.message = 'Invalid share: %(reason)s.'
exception InvalidShareAccess(message=None, **kwargs)

Bases: manila.exception.Invalid

InvalidShareAccess.message = 'Invalid access_rule: %(reason)s.'
exception InvalidShareMetadata(message=None, **kwargs)

Bases: manila.exception.Invalid

InvalidShareMetadata.message = 'Invalid metadata.'
exception InvalidShareMetadataSize(message=None, **kwargs)

Bases: manila.exception.Invalid

InvalidShareMetadataSize.message = 'Invalid metadata size.'
exception InvalidShareSnapshot(message=None, **kwargs)

Bases: manila.exception.Invalid

InvalidShareSnapshot.message = 'Invalid share snapshot: %(reason)s.'
exception InvalidUUID(message=None, **kwargs)

Bases: manila.exception.Invalid

InvalidUUID.message = 'Expected a uuid but received %(uuid)s.'
exception InvalidVolume(message=None, **kwargs)

Bases: manila.exception.Invalid

InvalidVolume.message = 'Invalid volume.'
exception InvalidVolumeType(message=None, **kwargs)

Bases: manila.exception.Invalid

InvalidVolumeType.message = 'Invalid volume type: %(reason)s.'
exception MalformedRequestBody(message=None, **kwargs)

Bases: manila.exception.ManilaException

MalformedRequestBody.message = 'Malformed message body: %(reason)s.'
exception ManilaException(message=None, **kwargs)

Bases: exceptions.Exception

Base Manila Exception

To correctly use this class, inherit from it and define a ‘message’ property. That message will get printf’d with the keyword arguments provided to the constructor.

ManilaException.code = 500
ManilaException.headers = {}
ManilaException.message = 'An unknown exception occurred.'
ManilaException.safe = False
exception MigrationError(message=None, **kwargs)

Bases: manila.exception.ManilaException

MigrationError.message = 'Migration error: %(reason)s.'
exception MigrationNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

MigrationNotFound.message = 'Migration %(migration_id)s could not be found.'
exception MigrationNotFoundByStatus(message=None, **kwargs)

Bases: manila.exception.MigrationNotFound

MigrationNotFoundByStatus.message = 'Migration not found for instance %(instance_id)s with status %(status)s.'
exception NetAppException(message=None, **kwargs)

Bases: manila.exception.ManilaException

NetAppException.message = 'Exception due to NetApp failure.'
exception NetworkBadConfigurationException(message=None, **kwargs)

Bases: manila.exception.NetworkException

NetworkBadConfigurationException.message = 'Bad network configuration: %(reason)s.'
exception NetworkException(message=None, **kwargs)

Bases: manila.exception.ManilaException

NetworkException.message = 'Exception due to network failure.'
exception NoValidHost(message=None, **kwargs)

Bases: manila.exception.ManilaException

NoValidHost.message = 'No valid host was found. %(reason)s.'
exception NotAuthorized(message=None, **kwargs)

Bases: manila.exception.ManilaException

NotAuthorized.code = 403
NotAuthorized.message = 'Not authorized.'
exception NotFound(message=None, **kwargs)

Bases: manila.exception.ManilaException

NotFound.code = 404
NotFound.message = 'Resource could not be found.'
NotFound.safe = True
exception OverQuota(message=None, **kwargs)

Bases: manila.exception.ManilaException

OverQuota.msg_fmt = 'Quota exceeded for resources: %(overs)s.'
exception PasteAppNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

PasteAppNotFound.message = "Could not load paste app '%(name)s' from %(path)s."
exception PolicyNotAuthorized(message=None, **kwargs)

Bases: manila.exception.NotAuthorized

PolicyNotAuthorized.message = "Policy doesn't allow %(action)s to be performed."
exception PortLimitExceeded(message=None, **kwargs)

Bases: manila.exception.QuotaError

PortLimitExceeded.message = 'Maximum number of ports exceeded.'
exception ProjectQuotaNotFound(message=None, **kwargs)

Bases: manila.exception.QuotaNotFound

ProjectQuotaNotFound.msg_fmt = 'Quota for project %(project_id)s could not be found.'
exception ProjectUserQuotaNotFound(message=None, **kwargs)

Bases: manila.exception.QuotaNotFound

ProjectUserQuotaNotFound.msg_fmt = 'Quota for user %(user_id)s in project %(project_id)s could not be found.'
exception QuotaClassNotFound(message=None, **kwargs)

Bases: manila.exception.QuotaNotFound

QuotaClassNotFound.msg_fmt = 'Quota class %(class_name)s could not be found.'
exception QuotaError(message=None, **kwargs)

Bases: manila.exception.ManilaException

QuotaError.code = 413
QuotaError.headers = {'Retry-After': 0}
QuotaError.message = 'Quota exceeded: code=%(code)s.'
QuotaError.safe = True
exception QuotaExists(message=None, **kwargs)

Bases: manila.exception.ManilaException

QuotaExists.msg_fmt = 'Quota exists for project %(project_id)s, resource %(resource)s.'
exception QuotaNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

QuotaNotFound.msg_fmt = 'Quota could not be found.'
exception QuotaResourceUnknown(message=None, **kwargs)

Bases: manila.exception.QuotaNotFound

QuotaResourceUnknown.msg_fmt = 'Unknown quota resources %(unknown)s.'
exception QuotaUsageNotFound(message=None, **kwargs)

Bases: manila.exception.QuotaNotFound

QuotaUsageNotFound.msg_fmt = 'Quota usage for project %(project_id)s could not be found.'
exception ReservationNotFound(message=None, **kwargs)

Bases: manila.exception.QuotaNotFound

ReservationNotFound.msg_fmt = 'Quota reservation %(uuid)s could not be found.'
exception SchedulerHostFilterNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

SchedulerHostFilterNotFound.message = 'Scheduler Host Filter %(filter_name)s could not be found.'
exception SchedulerHostWeigherNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

SchedulerHostWeigherNotFound.message = 'Scheduler Host Weigher %(weigher_name)s could not be found.'
exception SecurityServiceNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

SecurityServiceNotFound.message = 'Security service %(security_service_id)s could not be found.'
exception ServiceInstanceException(message=None, **kwargs)

Bases: manila.exception.ManilaException

ServiceInstanceException.message = 'Exception in service instance manager occurred.'
exception ServiceInstanceUnavailable(message=None, **kwargs)

Bases: manila.exception.ServiceInstanceException

ServiceInstanceUnavailable.message = 'Service Instance is not available.'
exception ServiceNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

ServiceNotFound.message = 'Service %(service_id)s could not be found.'
exception ShareAccessExists(message=None, **kwargs)

Bases: manila.exception.ManilaException

ShareAccessExists.message = 'Share access %(access_type)s:%(access)s exists.'
exception ShareBackendException(message=None, **kwargs)

Bases: manila.exception.ManilaException

ShareBackendException.message = 'Share backend error: %(msg)s.'
exception ShareIsBusy(message=None, **kwargs)

Bases: manila.exception.ManilaException

ShareIsBusy.message = 'Deleting $(share_name) share that used.'
exception ShareLimitExceeded(message=None, **kwargs)

Bases: manila.exception.QuotaError

ShareLimitExceeded.message = 'Maximum number of shares allowed (%(allowed)d) exceeded.'
exception ShareMetadataNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

ShareMetadataNotFound.message = 'Metadata item is not found.'
exception ShareNetworkNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

ShareNetworkNotFound.message = 'Network %(share_network_id)s could not be found.'
exception ShareNetworkSecurityServiceAssociationError(message=None, **kwargs)

Bases: manila.exception.ManilaException

ShareNetworkSecurityServiceAssociationError.message = 'Failed to associate share network %(share_network_id)s and security service %(security_service_id)s: %(reason)s.'
exception ShareNetworkSecurityServiceDissociationError(message=None, **kwargs)

Bases: manila.exception.ManilaException

ShareNetworkSecurityServiceDissociationError.message = 'Failed to dissociate share network %(share_network_id)s and security service %(security_service_id)s: %(reason)s.'
exception ShareNetworksLimitExceeded(message=None, **kwargs)

Bases: manila.exception.QuotaError

ShareNetworksLimitExceeded.message = 'Maximum number of share-networks allowed (%(allowed)d) exceeded.'
exception ShareServerInUse(message=None, **kwargs)

Bases: manila.exception.InUse

ShareServerInUse.message = 'Share Server %(share_server_id)s is in use.'
exception ShareServerNotCreated(message=None, **kwargs)

Bases: manila.exception.ManilaException

ShareServerNotCreated.message = 'Share Server %(share_server_id)s failed on creation.'
exception ShareServerNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

ShareServerNotFound.message = 'Share Server %(share_server_id)s could not be found.'
exception ShareServerNotFoundByFilters(message=None, **kwargs)

Bases: manila.exception.ShareServerNotFound

ShareServerNotFoundByFilters.message = 'Share Server could not be found by filters: %(filters_description)s.'
exception ShareSizeExceedsAvailableQuota(message=None, **kwargs)

Bases: manila.exception.QuotaError

ShareSizeExceedsAvailableQuota.message = 'Requested share or snapshot exceeds allowed Gigabytes quota.'
exception ShareSnapshotIsBusy(message=None, **kwargs)

Bases: manila.exception.ManilaException

ShareSnapshotIsBusy.message = 'Deleting snapshot %(snapshot_name)s that has dependent shares.'
exception ShareSnapshotNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

ShareSnapshotNotFound.message = 'Snapshot %(snapshot_id)s could not be found.'
exception SnapshotLimitExceeded(message=None, **kwargs)

Bases: manila.exception.QuotaError

SnapshotLimitExceeded.message = 'Maximum number of snapshots allowed (%(allowed)d) exceeded.'
exception VolumeNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

VolumeNotFound.message = 'Volume %(volume_id)s could not be found.'
exception VolumeSnapshotNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

VolumeSnapshotNotFound.message = 'Snapshot %(snapshot_id)s could not be found.'
exception VolumeTypeCreateFailed(message=None, **kwargs)

Bases: manila.exception.ManilaException

VolumeTypeCreateFailed.message = 'Cannot create volume_type with name %(name)s and specs %(extra_specs)s.'
exception VolumeTypeExists(message=None, **kwargs)

Bases: manila.exception.ManilaException

VolumeTypeExists.message = 'Volume Type %(id)s already exists.'
exception VolumeTypeExtraSpecsNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

VolumeTypeExtraSpecsNotFound.message = 'Volume Type %(volume_type_id)s has no extra specs with key %(extra_specs_key)s.'
exception VolumeTypeInUse(message=None, **kwargs)

Bases: manila.exception.ManilaException

VolumeTypeInUse.message = 'Volume Type %(volume_type_id)s deletion is not allowed with volumes present with the type.'
exception VolumeTypeNotFound(message=None, **kwargs)

Bases: manila.exception.NotFound

VolumeTypeNotFound.message = 'Volume type %(volume_type_id)s could not be found.'
exception VolumeTypeNotFoundByName(message=None, **kwargs)

Bases: manila.exception.VolumeTypeNotFound

VolumeTypeNotFoundByName.message = 'Volume type with name %(volume_type_name)s could not be found.'
exception VserverUnavailable(message=None, **kwargs)

Bases: manila.exception.NetAppException

VserverUnavailable.message = 'Vserver %(vserver)s is not available.'
exception WillNotSchedule(message=None, **kwargs)

Bases: manila.exception.ManilaException

WillNotSchedule.message = "Host %(host)s is not up or doesn't exist."

The manila.test Module

Base classes for our unit tests.

Allows overriding of flags for use of fakes, and some black magic for inline callbacks.

class Database(db_session, db_migrate, sql_connection, sqlite_db, sqlite_clean_db)

Bases: fixtures.fixture.Fixture

Database.setUp()
Database.setup_sqlite(db_migrate)
class StubOutForTesting(parent)

Bases: object

StubOutForTesting.Set(obj, attr_name, new_attr)
class TestCase(*args, **kwargs)

Bases: testtools.testcase.TestCase

Test case base class for all unit tests.

TestCase.assertDictListMatch(L1, L2, approx_equal=False, tolerance=0.001)

Assert a list of dicts are equivalent.

TestCase.assertDictMatch(d1, d2, approx_equal=False, tolerance=0.001)

Assert two dicts are equivalent.

This is a ‘deep’ match in the sense that it handles nested dictionaries appropriately.

NOTE:

If you don’t care (or don’t know) a given value, you can specify the string DONTCARE as the value. This will cause that dict-item to be skipped.
TestCase.assertIn(a, b, *args, **kwargs)

Python < v2.7 compatibility. Assert ‘a’ in ‘b’.

TestCase.assertIsInstance(a, b, *args, **kwargs)

Python < v2.7 compatibility.

TestCase.assertIsNone(a, *args, **kwargs)

Python < v2.7 compatibility.

TestCase.assertNotIn(a, b, *args, **kwargs)

Python < v2.7 compatibility. Assert ‘a’ NOT in ‘b’.

TestCase.assertSubDictMatch(sub_dict, super_dict)

Assert a sub_dict is subset of super_dict.

TestCase.flags(**kw)

Override flag variables for a test.

TestCase.setUp()

Run before each test method to initialize test environment.

TestCase.start_service(name, host=None, **kwargs)
TestCase.tearDown()

Runs after each test method to tear down test environment.

The manila.utils Module

Utilities and helper functions.

class IsAMatcher(expected_value=None)

Bases: object

class LazyPluggable(pivot, **backends)

Bases: object

A pluggable backend loaded lazily based on some value.

class ProtectedExpatParser(forbid_dtd=True, forbid_entities=True, *args, **kwargs)

Bases: xml.sax.expatreader.ExpatParser

An expat parser which disables DTD’s and entities by default.

ProtectedExpatParser.entity_decl(entityName, is_parameter_entity, value, base, systemId, publicId, notationName)
ProtectedExpatParser.reset()
ProtectedExpatParser.start_doctype_decl(name, sysid, pubid, has_internal_subset)
ProtectedExpatParser.unparsed_entity_decl(name, base, sysid, pubid, notation_name)
class SSHPool(ip, port, conn_timeout, login, password=None, privatekey=None, *args, **kwargs)

Bases: eventlet.pools.Pool

A simple eventlet pool to hold ssh connections.

SSHPool.create()
SSHPool.get()

Return an item from the pool, when one is available.

This may cause the calling greenthread to block. Check if a connection is active before returning it. For dead connections create and return a new connection.

SSHPool.remove(ssh)

Close an ssh client and remove it from free_items.

class UndoManager

Bases: object

Provides a mechanism to facilitate rolling back a series of actions.

This can be used when an exception is raised.

UndoManager.rollback_and_reraise(msg=None, **kwargs)

Rollback a series of actions then re-raise the exception.

Note

(sirp) This should only be called within an exception handler.

UndoManager.undo_with(undo_func)
cidr_to_netmask(cidr)

Convert cidr to netmask.

create_channel(client, width, height)

Invoke an interactive shell session on server.

debug(arg)
delete_if_exists(pathname)

Delete a file, but ignore file not found error.

ensure_tree(path)

Create a directory (and any ancestor directories required)

Parameters:path – Directory to create
execute(*cmd, **kwargs)

Convenience wrapper around oslo’s execute() function.

fetchfile(url, target)
file_open(*args, **kwargs)

Open file

see built-in file() documentation for more details

Note: The reason this is kept in a separate module is to easily
be able to provide a stub module that doesn’t alter system state at all (for unit tests)
find_config(config_path)

Find a configuration file using the given hint.

Parameters:config_path – Full or relative path to the config.
Returns:Full path of the config, if it exists.
Raises :manila.exception.ConfigNotFound
generate_mac_address()

Generate an Ethernet MAC address.

generate_password(length=20, symbolgroups=('23456789', 'ABCDEFGHJKLMNPQRSTUVWXYZ', 'abcdefghijkmnopqrstuvwxyz'))

Generate a random password from the supplied symbol groups.

At least one symbol from each group will be included. Unpredictable results if length is less than the number of symbol groups.

Believed to be reasonably secure (with a reasonable password length!)

generate_uid(topic, size=8)
generate_username(length=20, symbolgroups=('23456789', 'ABCDEFGHJKLMNPQRSTUVWXYZ', 'abcdefghijkmnopqrstuvwxyz'))
get_from_path(items, path)

Returns a list of items matching the specified path.

Takes an XPath-like expression e.g. prop1/prop2/prop3, and for each item in items, looks up items[prop1][prop2][prop3]. Like XPath, if any of the intermediate results are lists it will treat each list item individually. A ‘None’ in items or any child expressions will be ignored, this function will not throw because of None (anywhere) in items. The returned list will contain no None values.

get_my_linklocal(interface)
hash_file(file_like_object)

Generate a hash for the contents of a file.

is_eventlet_bug105()

Check if eventlet support IPv6 addresses.

See https://bitbucket.org/eventlet/eventlet/issue/105

Return type:bool
is_ipv6_configured()

Check if system contain IPv6 capable network interface.

Return type:bool
Raises :IOError
is_valid_boolstr(val)

Check if the provided string is a valid bool string or not.

is_valid_ipv4(address)

Validate IPv4 address.

Valid the address strictly as per format xxx.xxx.xxx.xxx. where xxx is a value between 0 and 255.

last_completed_audit_period(unit=None)

This method gives you the most recently completed audit period.

arguments:
units: string, one of ‘hour’, ‘day’, ‘month’, ‘year’
Periods normally begin at the beginning (UTC) of the period unit (So a ‘day’ period begins at midnight UTC, a ‘month’ unit on the 1st, a ‘year’ on Jan, 1) unit string may be appended with an optional offset like so: 'day@18‘ This will begin the period at 18:00 UTC. 'month@15‘ starts a monthly period on the 15th, and year@3 begins a yearly one on March 1st.
returns: 2 tuple of datetimes (begin, end)
The begin timestamp of this audit period is the same as the end of the previous.
last_octet(address)
make_dev_path(dev, partition=None, base='/dev')

Return a path to a particular device.

>>> make_dev_path('xvdc')
/dev/xvdc
>>> make_dev_path('xvdc', 1)
/dev/xvdc1
maniladir()
monkey_patch()

Patch decorator.

If the Flags.monkey_patch set as True, this function patches a decorator for all functions in specified modules. You can set decorators for each modules using CONF.monkey_patch_modules. The format is “Module path:Decorator function”. Example: ‘manila.api.ec2.cloud:’ manila.openstack.common.notifier.api.notify_decorator’

Parameters of the decorator is as follows. (See manila.openstack.common.notifier.api.notify_decorator)

name - name of the function function - object of the function

parse_mailmap(mailmap='.mailmap')
read_cached_file(filename, cache_info, reload_func=None)

Read from a file if it has been modified.

Parameters:
  • cache_info – dictionary to hold opaque cache.
  • reload_func – optional function to be called with data when file is reloaded due to a modification.
Returns:

data from file

read_file_as_root(file_path)

Secure helper to read file as root.

safe_minidom_parse_string(xml_string)

Parse an XML string using minidom safely.

sanitize_hostname(hostname)

Return a hostname which conforms to RFC-952 and RFC-1123 specs.

service_is_up(service)

Check whether a service is up based on last heartbeat.

strcmp_const_time(s1, s2)

Constant-time string comparison.

Params s1:the first string
Params s2:the second string
Returns:True if the strings are equal.

This function takes two strings and compares them. It is intended to be used when doing a comparison for authentication purposes to help guard against timing attacks.

tempdir(*args, **kwds)
temporary_chown(*args, **kwds)

Temporarily chown a path.

Params owner_uid:
 UID of temporary owner (defaults to current user)
temporary_mutation(*args, **kwds)

Temporarily set the attr on a particular object.

Temporarily set the attr on a particular object to a given value then revert when finished.

One use of this is to temporarily set the read_deleted flag on a context object:

with temporary_mutation(context, read_deleted=”yes”):
do_something_that_needed_deleted_objects()
to_bytes(text, default=0)

Try to turn a string into a number of bytes.

Looks at the last characters of the text to determine what conversion is needed to turn the input text into a byte number.

Supports: B/b, K/k, M/m, G/g, T/t (or the same with b/B on the end).

trycmd(*args, **kwargs)

Convenience wrapper around oslo’s trycmd() function.

utf8(value)

Try to turn a string into utf-8 if possible.

Code is directly from the utf8 function in http://github.com/facebook/tornado/blob/master/tornado/escape.py

walk_class_hierarchy(clazz, encountered=None)

Walk class hierarchy, yielding most derived classes first.

xhtml_escape(value)

Escapes a string so it is valid within XML or XHTML.

The manila.wsgi Module

Utility methods for working with WSGI servers.

class Application

Bases: object

Base WSGI application wrapper. Subclasses need to implement __call__.

classmethod Application.factory(global_config, **local_config)

Used for paste app factories in paste.deploy config files.

Any local configuration (that is, values under the [app:APPNAME] section of the paste config) will be passed into the __init__ method as kwargs.

A hypothetical configuration would look like:

[app:wadl] latest_version = 1.3 paste.app_factory = manila.api.fancy_api:Wadl.factory

which would result in a call to the Wadl class as

import manila.api.fancy_api fancy_api.Wadl(latest_version=‘1.3’)

You could of course re-implement the factory method in subclasses, but using the kwarg passing it shouldn’t be necessary.

class Debug(application)

Bases: manila.wsgi.Middleware

Helper class for debugging a WSGI application.

Can be inserted into any WSGI application chain to get information about the request and response.

static Debug.print_generator(app_iter)

Iterator that prints the contents of a wrapper string.

class Loader(config_path=None)

Bases: object

Used to load WSGI applications from paste configurations.

Loader.load_app(name)

Return the paste URLMap wrapped WSGI application.

Parameters:name – Name of the application to load.
Returns:Paste URLMap object wrapping the requested application.
Raises :manila.exception.PasteAppNotFound
class Middleware(application)

Bases: manila.wsgi.Application

Base WSGI middleware.

These classes require an application to be initialized that will be called next. By default the middleware will simply call its wrapped app, or you can override __call__ to customize its behavior.

classmethod Middleware.factory(global_config, **local_config)

Used for paste app factories in paste.deploy config files.

Any local configuration (that is, values under the [filter:APPNAME] section of the paste config) will be passed into the __init__ method as kwargs.

A hypothetical configuration would look like:

[filter:analytics] redis_host = 127.0.0.1 paste.filter_factory = manila.api.analytics:Analytics.factory

which would result in a call to the Analytics class as

import manila.api.analytics analytics.Analytics(app_from_paste, redis_host=‘127.0.0.1’)

You could of course re-implement the factory method in subclasses, but using the kwarg passing it shouldn’t be necessary.

Middleware.process_request(req)

Called on each request.

If this returns None, the next application down the stack will be executed. If it returns a response then that response will be returned and execution will stop here.

Middleware.process_response(response)

Do whatever you’d like to the response.

class Request(environ, charset=None, unicode_errors=None, decode_param_names=None, **kw)

Bases: webob.request.Request

class Router(mapper)

Bases: object

WSGI middleware that maps incoming requests to WSGI apps.

class Server(name, app, host=None, port=None, pool_size=None, protocol=<class eventlet.wsgi.HttpProtocol at 0x47b2d70>)

Bases: object

Server class to manage a WSGI server, serving a WSGI application.

Server.default_pool_size = 1000
Server.host
Server.port
Server.start(backlog=128)

Start serving a WSGI application.

Parameters:backlog – Maximum number of queued connections.
Returns:None
Raises :manila.exception.InvalidInput
Server.stop()

Stop this server.

This is not a very nice action, as currently the method by which a server is stopped is by killing its eventlet.

Returns:None
Server.wait()

Block, until the server has stopped.

Waits on the server’s eventlet to finish, then returns.

Returns:None

Tests

The test_exception Module

class FakeNotifier

Bases: object

Acts like the manila.openstack.common.notifier.api module.

FakeNotifier.ERROR = 88
FakeNotifier.notify(context, publisher, event, priority, payload)
class ManilaExceptionResponseCode400(*args, **kwargs)

Bases: manila.test.TestCase

ManilaExceptionResponseCode400.test_invalid()
ManilaExceptionResponseCode400.test_invalid_content_type()
ManilaExceptionResponseCode400.test_invalid_input()
ManilaExceptionResponseCode400.test_invalid_parameter_value()
ManilaExceptionResponseCode400.test_invalid_quota_value()
ManilaExceptionResponseCode400.test_invalid_request()
ManilaExceptionResponseCode400.test_invalid_reservation_expiration()
ManilaExceptionResponseCode400.test_invalid_results()
ManilaExceptionResponseCode400.test_invalid_share()
ManilaExceptionResponseCode400.test_invalid_share_access()
ManilaExceptionResponseCode400.test_invalid_share_metadata()
ManilaExceptionResponseCode400.test_invalid_share_metadata_size()
ManilaExceptionResponseCode400.test_invalid_share_snapshot()
ManilaExceptionResponseCode400.test_invalid_uuid()
ManilaExceptionResponseCode400.test_invalid_volume()
ManilaExceptionResponseCode400.test_invalid_volume_type()
class ManilaExceptionResponseCode403(*args, **kwargs)

Bases: manila.test.TestCase

ManilaExceptionResponseCode403.test_admin_required()
ManilaExceptionResponseCode403.test_not_authorized()
ManilaExceptionResponseCode403.test_policy_not_authorized()
class ManilaExceptionResponseCode404(*args, **kwargs)

Bases: manila.test.TestCase

ManilaExceptionResponseCode404.test_config_not_found()
ManilaExceptionResponseCode404.test_file_not_found()
ManilaExceptionResponseCode404.test_host_binary_not_found()
ManilaExceptionResponseCode404.test_host_not_found()
ManilaExceptionResponseCode404.test_instance_not_found()
ManilaExceptionResponseCode404.test_migration_not_found()
ManilaExceptionResponseCode404.test_migration_not_found_by_status()
ManilaExceptionResponseCode404.test_not_found()
ManilaExceptionResponseCode404.test_paste_app_not_found()
ManilaExceptionResponseCode404.test_project_quota_not_found()
ManilaExceptionResponseCode404.test_quota_class_not_found()
ManilaExceptionResponseCode404.test_quota_not_found()
ManilaExceptionResponseCode404.test_quota_resource_unknown()
ManilaExceptionResponseCode404.test_quota_usage_not_found()
ManilaExceptionResponseCode404.test_reservation_not_found()
ManilaExceptionResponseCode404.test_scheduler_host_filter_not_found()
ManilaExceptionResponseCode404.test_scheduler_host_weigher_not_found()
ManilaExceptionResponseCode404.test_security_service_not_found()
ManilaExceptionResponseCode404.test_service_not_found()
ManilaExceptionResponseCode404.test_share_metadata_not_found()
ManilaExceptionResponseCode404.test_share_network_not_found()
ManilaExceptionResponseCode404.test_share_server_not_found()
ManilaExceptionResponseCode404.test_share_server_not_found_by_filters()
ManilaExceptionResponseCode404.test_share_snapshot_not_found()
ManilaExceptionResponseCode404.test_volume_not_found()
ManilaExceptionResponseCode404.test_volume_snapshot_not_found()
ManilaExceptionResponseCode404.test_volume_type_extra_specs_not_found()
ManilaExceptionResponseCode404.test_volume_type_not_found()
ManilaExceptionResponseCode404.test_volume_type_not_found_by_name()
class ManilaExceptionResponseCode413(*args, **kwargs)

Bases: manila.test.TestCase

ManilaExceptionResponseCode413.test_port_limit_exceeded()
ManilaExceptionResponseCode413.test_quota_error()
ManilaExceptionResponseCode413.test_share_limit_exceeded()
ManilaExceptionResponseCode413.test_share_networks_limit_exceeded()
ManilaExceptionResponseCode413.test_share_size_exceeds_available_quota()
ManilaExceptionResponseCode413.test_snapshot_limit_exceeded()
class ManilaExceptionTestCase(*args, **kwargs)

Bases: manila.test.TestCase

ManilaExceptionTestCase.test_default_error_code()
ManilaExceptionTestCase.test_default_error_msg()
ManilaExceptionTestCase.test_default_error_msg_with_kwargs()
ManilaExceptionTestCase.test_error_code_from_kwarg()
ManilaExceptionTestCase.test_error_msg()
ManilaExceptionTestCase.test_error_msg_exception_with_kwargs()
ManilaExceptionTestCase.test_error_msg_is_exception_to_string()
ManilaExceptionTestCase.test_exception_kwargs_to_string()
ManilaExceptionTestCase.test_exception_multi_kwargs_to_string()