glare.common package

Submodules

glare.common.config module

Routines for configuring Glare.

glare.common.config.load_paste_app(app_name, flavor=None, conf_file=None)[source]

Builds and returns a WSGI app from a paste config file.

We assume the last config file specified in the supplied ConfigOpts object is the paste config file, if conf_file is None.

Parameters:
  • app_name – name of the application to load
  • flavor – name of the variant of the application to load
  • conf_file – path to the paste config file
Raises:

RuntimeError when config file cannot be located or application cannot be loaded from config file

glare.common.config.parse_args(args=None, usage=None, default_config_files=None)[source]

glare.common.exception module

exception glare.common.exception.ApiVersionsIntersect(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’Version of %(name)s %(min_ver)s %(max_ver)s intersects with another versions.’
exception glare.common.exception.ArtifactNotFound(message=None, **kwargs)[source]

Bases: glare.common.exception.NotFound

message = u”Artifact with type name ‘%(type_name)s’ and id ‘%(id)s’ was not found.”
exception glare.common.exception.BadRequest(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’Bad request’
exception glare.common.exception.Conflict(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’The request could not be completed due to a conflict with the current state of the resource.’
exception glare.common.exception.DBNotAllowed(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

msg_fmt = u’This operation is not allowed with current DB’
exception glare.common.exception.FailedDependency(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’The method could not be performed because the requested action depended on another action and that action failed.’
exception glare.common.exception.Forbidden(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’You are not authorized to complete this action.’
exception glare.common.exception.GlareException(message=None, **kwargs)[source]

Bases: exceptions.Exception

Base Glare Exception class.

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.

message = u’An unknown exception occurred’
exception glare.common.exception.Gone(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’The requested resource is no longer available at the server and no forwarding address is known.’
exception glare.common.exception.IncorrectArtifactType(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’Artifact type is incorrect: %(explanation)s’
exception glare.common.exception.InvalidFilterOperatorValue(message=None, **kwargs)[source]

Bases: glare.common.exception.BadRequest

msg = u’Unable to filter by unknown operator.’
exception glare.common.exception.InvalidGlobalAPIVersion(message=None, **kwargs)[source]

Bases: glare.common.exception.NotAcceptable

message = u’Version %(req_ver)s is not supported by the API. Minimum is %(min_ver)s and maximum is %(max_ver)s.’
exception glare.common.exception.InvalidParameterValue(message=None, **kwargs)[source]

Bases: glare.common.exception.BadRequest

message = u’Invalid filter value ‘
exception glare.common.exception.InvalidVersion(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’Provided version is invalid’
exception glare.common.exception.Locked(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’The resource is locked.’
exception glare.common.exception.NotAcceptable(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’Not acceptable’
exception glare.common.exception.NotFound(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’An object with the specified identifier was not found.’
exception glare.common.exception.PolicyException(message=None, **kwargs)[source]

Bases: glare.common.exception.Forbidden

message = u’Policy check for %(policy_name)s failed with user credentials.’
exception glare.common.exception.PreconditionFailed(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’The precondition given in one or more of the request-header fields evaluated to false when it was tested on the server.’
exception glare.common.exception.RequestEntityTooLarge(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’The server is refusing to process a request because the request entity is larger than the server is willing or able to process.’
exception glare.common.exception.RequestRangeNotSatisfiable(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’The request included a Range request-header field, and none of the range-specifier values in this field overlap the current extent of the selected resource, and the request did not include an If-Range request-header field.’
exception glare.common.exception.RequestTimeout(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’The client did not produce a request within the time that the server was prepared to wait.’
exception glare.common.exception.SIGHUPInterrupt(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’System SIGHUP signal received.’
exception glare.common.exception.TypeNotFound(message=None, **kwargs)[source]

Bases: glare.common.exception.NotFound

message = u”Glare type with name ‘%(name)s’ was not found.”
exception glare.common.exception.Unauthorized(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’You are not authenticated’
exception glare.common.exception.UnsupportedMediaType(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’Unsupported media type.’
exception glare.common.exception.VersionNotFoundForAPIMethod(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’API version %(version)s is not supported on this method.’
exception glare.common.exception.WorkerCreationFailure(message=None, **kwargs)[source]

Bases: glare.common.exception.GlareException

message = u’Server worker creation failed: %(reason)s.’

glare.common.policy module

Glare policy operations inspired by Nova implementation.

glare.common.policy.authorize(policy_name, target, context, do_raise=True)[source]

Method checks that user action can be executed according to policies.

Parameters:
  • policy_name – policy name
  • target

:param do_raise :param context: :return: True if check passed

glare.common.policy.check_is_admin(context)[source]

Whether or not roles contains ‘admin’ role according to policy setting.

glare.common.policy.init(use_conf=True)[source]

Init an Enforcer class.

glare.common.policy.list_rules()[source]
glare.common.policy.reset()[source]

glare.common.semver_db module

class glare.common.semver_db.DBVersion(components_long, prerelease, build)[source]

Bases: object

class glare.common.semver_db.VersionComparator(prop, parentmapper, adapt_to_entity=None)[source]

Bases: sqlalchemy.orm.descriptor_props.Comparator

glare.common.semver_db.parse(version_string)[source]

glare.common.store_api module

glare.common.store_api.get_known_schemes()[source]
glare.common.store_api.read_data(flobj, limit=16777216)[source]

Read data into memory from the file-like object.

Parameters:
  • flobj – file-like object that contains data
  • limit – max file size that can be read into memory
Returns:

string with data from the object

glare.common.utils module

System-level utilities and helper functions.

class glare.common.utils.BlobIterator(data, chunk_size=65536)[source]

Bases: object

Reads data from a blob, one chunk at a time.

class glare.common.utils.CooperativeReader(fd)[source]

Bases: object

An eventlet thread friendly class for reading in blob data.

When accessing data either through the iterator or the read method we perform a sleep to allow a co-operative yield. When there is more than one blob being uploaded/downloaded this prevents eventlet thread starvation, ie allows all threads to be scheduled periodically rather than having the same thread be continuously active.

read(length=None)[source]

Return the requested amount of bytes, fetching the next chunk of the underlying iterator when needed.

This is replaced with cooperative_read in __init__ if the underlying fd already supports read().

class glare.common.utils.LimitingReader(data, limit)[source]

Bases: object

Reader designed to fail when reading blob data past the configured allowable amount.

read(length=None)[source]
glare.common.utils.cooperative_iter(iter)[source]

Return an iterator which schedules after each iteration. This can prevent eventlet thread starvation.

Parameters:iter – an iterator to wrap
glare.common.utils.cooperative_read(fd)[source]

Wrap a file descriptor’s read with a partial function which schedules after each read. This can prevent eventlet thread starvation.

Parameters:fd – a file descriptor to wrap
class glare.common.utils.error_handler(error_map, default_exception=None)[source]

Bases: object

glare.common.utils.get_glare_type(attr)[source]
glare.common.utils.get_schema_type(attr)[source]
glare.common.utils.get_system_ca_file()[source]

Return path to system default CA file.

glare.common.utils.get_test_suite_socket()[source]
glare.common.utils.initialize_glance_store()[source]

Initialize glance store.

glare.common.utils.no_4byte_params(f)[source]

Checks that no 4 byte unicode characters are allowed in dicts’ keys/values and string’s parameters.

glare.common.utils.set_glance_store_config_defaults()[source]
glare.common.utils.split_filter_op(expression)[source]

Split operator from threshold in an expression. Designed for use on a comparative-filtering query field. When no operator is found, default to an equality comparison.

Parameters:expression – the expression to parse
Returns:a tuple (operator, threshold) parsed from expression
glare.common.utils.split_filter_value_for_quotes(value)[source]

Split filter values

Split values by commas and quotes for ‘in’ operator, according api-wg.

glare.common.utils.stash_conf_values()[source]

Make a copy of some of the current global CONF’s settings. Allows determining if any of these values have changed when the config is reloaded.

glare.common.utils.validate_change_allowed(af, field_name)[source]

Validate if fields can be set for the artifact.

glare.common.utils.validate_key_cert(key_file, cert_file)[source]
glare.common.utils.validate_quotes(value)[source]

Validate filter values

Validation opening/closing quotes in the expression.

glare.common.utils.validate_status_transition(af, from_status, to_status)[source]
glare.common.utils.validate_visibility_transition(af, from_visibility, to_visibility)[source]

glare.common.wsgi module

Utility methods for working with WSGI servers

class glare.common.wsgi.APIMapper(controller_scan=<function controller_scan at 0x5eb4a28>, directory=None, always_scan=False, register=True, explicit=True)[source]

Bases: routes.mapper.Mapper

Handle route matching when url is ” because routes.Mapper returns an error in this case.

routematch(url=None, environ=None)[source]
class glare.common.wsgi.JSONRequestDeserializer[source]

Bases: object

default(request)[source]
from_json(datastring)[source]
has_body(request)[source]

Returns whether a Webob.Request object will possess an entity body.

Parameters:request – Webob.Request object
httpverb_may_have_body = frozenset([‘PUT’, ‘POST’, ‘PATCH’])
classmethod is_valid_encoding(request)[source]
classmethod is_valid_method(request)[source]
valid_transfer_encoding = frozenset([‘gzip’, ‘chunked’, ‘compress’, ‘identity’, ‘deflate’])
class glare.common.wsgi.JSONResponseSerializer[source]

Bases: object

default(response, result)[source]
to_json(data)[source]
class glare.common.wsgi.RejectMethodController[source]

Bases: object

reject(req, allowed_methods, *args, **kwargs)[source]
class glare.common.wsgi.Request(environ, charset=None, unicode_errors=None, decode_param_names=None, **kw)[source]

Bases: webob.request.Request

Add some OpenStack API-specific logic to the base webob.Request.

best_match_content_type()[source]

Determine the requested response content-type.

best_match_language()[source]

Determines best available locale from the Accept-Language header.

Returns:the best language match or None if the ‘Accept-Language’ header was not available in the request.
get_content_range()[source]

Return the Range in a request.

class glare.common.wsgi.Resource(controller, deserializer=None, serializer=None)[source]

Bases: object

WSGI app that handles (de)serialization and controller dispatch.

Reads routing information supplied by RoutesMiddleware and calls the requested action method upon its deserializer, controller, and serializer. Those three objects may implement any of the basic controller action methods (create, update, show, index, delete) along with any that may be specified in the api router. A ‘default’ method may also be implemented to be used in place of any non-implemented actions. Deserializer methods must accept a request argument and return a dictionary. Controller methods must accept a request argument. Additionally, they must also accept keyword arguments that represent the keys returned by the Deserializer. They may raise a webob.exc exception or return a dict, which will be serialized by requested content type.

dispatch(obj, action, *args, **kwargs)[source]

Find action-specific method on self and call it.

get_action_args(request_environment)[source]

Parse dictionary created by routes library.

class glare.common.wsgi.Router(mapper)[source]

Bases: object

WSGI middleware that maps incoming requests to WSGI apps.

classmethod factory(global_conf, **local_conf)[source]
class glare.common.wsgi.Server(threads=1000, initialize_glance_store=False)[source]

Bases: object

Server class to manage multiple WSGI sockets and applications.

This class requires initialize_glance_store set to True if glance store needs to be initialized.

configure(old_conf=None, has_changed=None)[source]

Apply configuration settings

Parameters:
  • old_conf – Cached old configuration settings (if any)
  • has_changed – callable to determine if a parameter has changed
configure_socket(old_conf=None, has_changed=None)[source]

Ensure a socket exists and is appropriately configured.

This function is called on start up, and can also be called in the event of a configuration reload.

When called for the first time a new socket is created. If reloading and either bind_host or bind_port have been changed the existing socket must be closed and a new socket opened (laws of physics).

In all other cases (bind_host/bind_port have not changed) the existing socket is reused.

Parameters:
  • old_conf – Cached old configuration settings (if any)
  • has_changed – callable to determine if a parameter has changed
create_pool()[source]
hup(*args)[source]

Reloads configuration files with zero down time

kill_children(*args)[source]

Kills the entire process group.

reload()[source]

Reload and re-apply configuration settings

Existing child processes are sent a SIGHUP signal and will exit after completing existing requests. New child processes, which will have the updated configuration, are spawned. This allows preventing interruption to the service.

run_child()[source]
run_server()[source]

Run a WSGI server.

start(application, default_port)[source]

Run a WSGI server with the given application.

Parameters:
  • application – The application to be run in the WSGI server
  • default_port – Port to bind to if none is specified in conf
start_wsgi()[source]
wait()[source]

Wait until all servers have completed running.

wait_on_children()[source]
glare.common.wsgi.get_asynchronous_eventlet_pool(size=1000)[source]

Return eventlet pool to caller.

Also store pools created in global list, to wait on it after getting signal for graceful shutdown.

Parameters:size – eventlet pool size
Returns:eventlet pool
glare.common.wsgi.get_bind_addr(default_port=None)[source]

Return the host and port to bind to.

glare.common.wsgi.get_num_workers()[source]

Return the configured number of workers.

glare.common.wsgi.get_socket(default_port)[source]

Bind socket to bind ip:port in conf

Parameters:default_port – port to bind to if none is specified in conf
Returns:a socket object as returned from socket.listen or ssl.wrap_socket if conf specifies cert_file
glare.common.wsgi.set_eventlet_hub()[source]
glare.common.wsgi.ssl_wrap_socket(sock)[source]

Wrap an existing socket in SSL

Parameters:sock – non-SSL socket to wrap
Returns:An SSL wrapped socket
glare.common.wsgi.translate_exception(req, e)[source]

Translates all translatable elements of the given exception.

Module contents