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.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.
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.
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.semver_db module¶
glare.common.store_api module¶
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.
-
class
glare.common.utils.
LimitingReader
(data, limit)[source]¶ Bases:
object
Reader designed to fail when reading blob data past the configured allowable amount.
-
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
-
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.
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.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.
-
class
glare.common.wsgi.
JSONRequestDeserializer
[source]¶ Bases:
object
-
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’])¶
-
valid_transfer_encoding
= frozenset([‘gzip’, ‘chunked’, ‘compress’, ‘identity’, ‘deflate’])¶
-
-
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.
-
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.
-
class
glare.common.wsgi.
Router
(mapper)[source]¶ Bases:
object
WSGI middleware that maps incoming requests to WSGI apps.
-
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
-
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.
-
-
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_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