Libraries common throughout Nova or just ones that haven’t been categorized very well yet.
RequestContext: context for requests that persist through all of nova.
Bases: object
Security context and request information.
Represents the user taking a given action within the system.
Return a version of this context with admin flag set.
Nova base exception handling.
Includes decorator for re-raising Nova-type exceptions.
SHOULD include dedicated exception logging.
Bases: nova.exception.NotFound
Bases: nova.exception.NotAuthorized
Bases: nova.exception.NovaException
Bases: nova.exception.Duplicate
Bases: nova.exception.Duplicate
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.Duplicate
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NovaException
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.HostNotFound
Bases: nova.exception.ServiceUnavailable
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.ConsoleNotFound
Bases: nova.exception.ConsoleNotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.Invalid
Bases: webob.exc.WSGIHTTPException
Bases: nova.exception.NovaException
Bases: nova.exception.NovaException
Bases: nova.exception.Error
Wraps an implementation specific exception.
Bases: nova.exception.NotFound
Bases: nova.exception.NovaException
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.NotFound
Bases: nova.exception.NovaException
Bases: nova.exception.Duplicate
Bases: nova.exception.Duplicate
Bases: nova.exception.Error
Bases: exceptions.Exception
Bases: nova.exception.NotFound
Bases: nova.exception.NovaException
Bases: nova.exception.Invalid
Bases: nova.exception.NotFound
Bases: nova.exception.FixedIpNotFound
Bases: nova.exception.FixedIpNotFound
Bases: nova.exception.FixedIpNotFound
Bases: nova.exception.FixedIpNotFound
Bases: nova.exception.FixedIpNotFound
Bases: nova.exception.FixedIpNotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NovaException
Bases: nova.exception.Invalid
Bases: nova.exception.NovaException
Bases: nova.exception.NotFound
Bases: nova.exception.FloatingIpNotFound
Bases: nova.exception.FloatingIpNotFound
Bases: nova.exception.NovaException
Bases: nova.exception.NotAllowed
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NovaException
Bases: nova.exception.NotFound
Bases: nova.exception.NovaException
Bases: nova.exception.NovaException
Bases: nova.exception.NovaException
Bases: nova.exception.Invalid
Bases: nova.exception.Duplicate
Bases: nova.exception.Invalid
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.NovaException
Bases: nova.exception.NovaException
Bases: nova.exception.Duplicate
Bases: nova.exception.NotFound
Bases: nova.exception.NovaException
Bases: nova.exception.NotFound
Bases: nova.exception.InstanceTypeNotFound
Bases: nova.exception.Invalid
Bases: nova.exception.NovaException
Bases: nova.exception.NovaException
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.InvalidBDM
Bases: nova.exception.InvalidBDM
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.NovaException
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.ImageNotFound
Bases: nova.exception.Duplicate
Bases: nova.exception.NotFound
Bases: nova.exception.Duplicate
Bases: nova.exception.NotFound
Bases: nova.exception.LDAPObjectNotFound
Bases: nova.exception.Duplicate
Bases: nova.exception.NotFound
Bases: nova.exception.UserExists
Bases: nova.exception.LDAPObjectNotFound
Bases: nova.exception.Invalid
Bases: nova.exception.NovaException
Bases: nova.exception.NovaException
Bases: nova.exception.NovaException
Bases: nova.exception.NotFound
Bases: nova.exception.MigrationNotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NovaException
Bases: nova.exception.NovaException
Bases: nova.exception.NovaException
Bases: nova.exception.NovaException
Bases: nova.exception.NotFound
Bases: nova.exception.NetworkNotFound
Bases: nova.exception.NetworkNotFound
Bases: nova.exception.NetworkNotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NetworkNotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NovaException
Bases: nova.exception.FloatingIpNotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NovaException
Bases: nova.exception.NotFound
Bases: nova.exception.NovaException
Bases: nova.exception.NovaException
Bases: nova.exception.NovaException
Bases: exceptions.Exception
Base Nova 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.
Bases: nova.exception.NotFound
Bases: nova.exception.NotAuthorized
Bases: exceptions.IOError
Bases: nova.exception.Duplicate
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.QuotaNotFound
Bases: nova.exception.NovaException
Bases: nova.exception.NotFound
Bases: nova.exception.NovaException
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.Invalid
Bases: nova.exception.Invalid
Bases: nova.exception.NotFound
Bases: nova.exception.SecurityGroupNotFound
Bases: nova.exception.SecurityGroupNotFound
Bases: nova.exception.NotFound
Bases: nova.exception.Invalid
Bases: nova.exception.NotFound
Bases: nova.exception.NovaException
Bases: nova.exception.NovaException
Bases: nova.exception.NotFound
Bases: nova.exception.SolidFireAPIException
Bases: nova.exception.NovaException
Bases: nova.exception.SolidFireAPIException
Bases: nova.exception.Invalid
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.Invalid
Bases: nova.exception.Duplicate
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.NovaException
Bases: nova.exception.NovaException
Bases: nova.exception.NotFound
Bases: nova.exception.NovaException
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.VolumeNotFound
Bases: nova.exception.ServiceUnavailable
Bases: nova.exception.NovaException
Bases: nova.exception.Duplicate
Bases: nova.exception.NotFound
Bases: nova.exception.NotFound
Bases: nova.exception.VolumeTypeNotFound
Bases: nova.exception.Invalid
Bases: nova.exception.NovaException
Bases: nova.exception.NovaException
This decorator wraps a method to catch any exceptions that may get thrown. It logs the exception as well as optionally sending it to the notification system.
Command-line flag library.
Emulates gflags by wrapping cfg.ConfigOpts.
The idea is to move fully to cfg eventually, and this wrapper is a stepping stone.
Bases: exceptions.Exception
Invoke a remote method that returns something.
Parameters: |
|
---|---|
Returns: | A dict from the remote method. |
Raises : | nova.rpc.common.Timeout if a complete response is not received before the timeout is reached. |
Invoke a remote method that does not return anything.
Parameters: |
|
---|---|
Returns: | None |
Invoke a remote method that does not return anything.
Parameters: |
|
---|---|
Returns: | None |
Clean up resoruces in use by implementation.
Clean up any resources that have been allocated by the RPC implementation. This is typically open connections to a messaging service. This function would get called before an application using this API exits to allow connections to get torn down cleanly.
Returns: | None |
---|
Create a connection to the message bus used for rpc.
For some example usage of creating a connection and some consumers on that connection, see nova.service.
Parameters: | new – Whether or not to create a new connection. A new connection will be created by default. If new is False, the implementation is free to return an existing connection from a pool. |
---|---|
Returns: | An instance of nova.rpc.common.Connection |
Broadcast a remote method invocation with no return.
This method will get invoked on all consumers that were set up with this topic name and fanout=True.
Parameters: |
|
---|---|
Returns: | None |
Broadcast to a remote method invocation with no return.
Parameters: |
|
---|---|
Returns: | None |
Invoke a remote method and get back an iterator.
In this case, the remote method will be returning multiple values in separate messages, so the return values can be processed as the come in via an iterator.
Parameters: |
|
---|---|
Returns: | An iterator. The iterator will yield a tuple (N, X) where N is an index that starts at 0 and increases by one for each value returned and X is the Nth value that was returned by the remote method. |
Raises : | nova.rpc.common.Timeout if a complete response is not received before the timeout is reached. |
Send notification event.
Parameters: |
|
---|---|
Returns: | None |
Base classes for our unit tests.
Allows overriding of flags for use of fakes, and some black magic for inline callbacks.
Bases: unittest.case.TestCase
Test case base class for all unit tests.
Assert a list of dicts are equivalent.
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.
Python < v2.7 compatibility. Assert ‘a’ in ‘b’
Python < v2.7 compatibility. Assert ‘a’ NOT in ‘b’
Assert a sub_dict is subset of super_dict.
Override flag variables for a test.
Resets all flag variables for the test.
Runs after each test.
Run before each test method to initialize test environment.
Runs after each test method to tear down test environment.
Bases: exceptions.Exception
Bases: object
Decorator that skips a test if condition is true.
Decorator that skips a test if running in fake mode.
Bases: object
Decorator that skips a test.
Bases: object
Decorator that skips a test if condition is not true.
Utilities and helper functions.
Bases: lockfile.LinkFileLock
Implementation of lockfile that allows for a lock per greenthread.
Simply implements lockfile:LockBase init with an addiontall suffix on the unique name of the greenthread identifier
Bases: object
A pluggable backend loaded lazily based on some value.
Bases: object
Bases: exceptions.Exception
Exception to break out and stop a LoopingCall.
The poll-function passed to LoopingCall can raise this exception to break out of the loop normally. This is somewhat analogous to StopIteration.
An optional return-value can be included as the argument to the exception; this return-value will be returned by LoopingCall.wait()
Bases: xml.sax.expatreader.ExpatParser
An expat parser which disables DTD’s and entities by default.
Bases: object
Provides a mechanism to facilitate rolling back a series of actions when an exception is raised.
Rollback a series of actions then re-raise the exception.
Note
(sirp) This should only be called within an exception handler.
Advance overriden time using a datetime.timedelta.
Advance overriden time by seconds.
Convert a string representation of a bool into a bool value
Checks that obj is of type cls, and lets PyLint infer types.
clean up stale locks left behind by process failures
The lockfile module, used by @synchronized, can leave stale lockfiles behind after process failure. These locks can cause process hangs at startup, when a process deadlocks on a lock which will never be unlocked.
Intended to be called at service startup.
Remove the overridden time.
Convert a value or list into a list of dicts
This method gives you the most recently completed audit period.
delete a file, but ignore file not found error
Marks a function, class, or method as being deprecated. For functions and methods, emits a warning each time the function or method is called. For classes, generates a new subclass which will emit a warning each time the class is instantiated, or each time any class or static method is called.
If a message is passed to the decorator, that message will be appended to the emitted warning. This may be used to suggest an alternate way of achieving the desired effect, or to explain why the function, class, or method is deprecated.
Helper method to execute command with optional retry.
If you add a run_as_root=True command, don’t forget to add the corresponding filter to nova.rootwrap !
Parameters: |
|
---|---|
Raises: |
|
Returns: | a tuple, (stdout, stderr) from the spawned process, or None if the command fails. |
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 : | nova.exception.ConfigNotFound |
Recursively flatten a nested dictionary.
Generate the URL to glance.
Generate an Ethernet MAC address.
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!)
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.
Generate a hash for the contents of a file.
Returns a class from a string including module and class.
Returns an object including a module or module and class.
Return True if before is older than seconds.
For our purposes, a UUID is a string in canonical form:
aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
Check if the provided ipv4 or ipv6 address is a valid CIDR address or not
valid the address strictly as per format xxx.xxx.xxx.xxx. where xxx is a value between 0 and 255.
Stringify time in ISO 8601 format
Catches exception, write message to the log, re-raise. This is a common refinement of save_and_reraise that writes a specific message to the log.
Return a path to a particular device.
>>> make_dev_path('xvdc')
/dev/xvdc
>>> make_dev_path('xvdc', 1)
/dev/xvdc1
Return a dict in which the dictionaries keys are mapped to new keys.
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 FLAGS.monkey_patch_modules. The format is “Module path:Decorator function”. Example: ‘nova.api.ec2.cloud:nova.notifier.api.notify_decorator’
Parameters of the decorator is as follows. (See nova.notifier.api.notify_decorator)
name - name of the function function - object of the function
Normalize time in arbitrary timezone to UTC
Turn an iso formatted time back into a datetime.
Parses the given server_string and returns a list of host and port. If it’s not a combination of host part and port, the port element is a null string. If the input is invalid expression, return a null list.
Turn a formatted time back into a datetime.
Return two dicts, one with keys the other with everything else.
Read from a file if it has been modified.
Parameters: |
|
---|---|
Returns: | data from file |
Secure helper to read file as root.
Parse an XML string using minidom safely.
Return a hostname which conforms to RFC-952 and RFC-1123 specs.
Save current exception, run some code and then re-raise.
In some cases the exception context can be cleared, resulting in None being attempted to be reraised after an exception handler is run. This can happen when eventlet switches greenthreads or when running an exception handler, code raises and catches an exception. In both cases the exception context will be cleared.
To work around this, we save the exception state, run handler code, and then re-raise the original exception. If another exception occurs, the saved exception is logged and the new exception is reraised.
Check whether a service is up based on last heartbeat.
Override utils.utcnow to return a constant time.
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.
Returns formatted utcnow.
Return a dict that only contains a subset of keys.
Synchronization decorator.
Decorating a method like so:
@synchronized('mylock')
def foo(self, *args):
...
ensures that only one thread will execute the bar method at a time.
Different methods can share the same lock:
@synchronized('mylock')
def foo(self, *args):
...
@synchronized('mylock')
def bar(self, *args):
...
This way only one of either foo or bar can be executing at a time.
The external keyword argument denotes whether this lock should work across multiple processes. This means that if two different workers both run a a method decorated with @synchronized(‘mylock’, external=True), only one of them will execute at a time.
Important limitation: you can only have one external lock running per thread at a time. For example the following will fail:
@utils.synchronized(‘testlock1’, external=True) def outer_lock():
@utils.synchronized(‘testlock2’, external=True) def inner_lock():
passinner_lock()
outer_lock()
Temporarily chown a path.
Params owner_uid: | |
---|---|
UID of temporary owner (defaults to current user) |
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()
Decorator that logs how long a particular function took to execute
Convert a complex object into primitives.
Handy for JSON serialization. We can optionally handle instances, but since this is a recursive function, we could have cyclical data structures.
To handle cyclical data structures we could track the actual objects visited in a set, but not all objects are hashable. Instead we just track the depth of the object inspections and don’t go too deep.
Therefore, convert_instances=True is lossy ... be aware.
Local total_seconds implementation for compatibility with python 2.6
A wrapper around execute() to more easily handle warnings and errors.
Returns an (out, err) tuple of strings containing the output of the command’s stdout and stderr. If ‘err’ is not empty then the command can be considered to have failed.
Overridable version of utils.utcnow.
Timestamp version of our utcnow function.
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
Sends a vpn negotiation packet and returns the server session.
Returns False on a failure. Basic packet structure is below.
Client packet (14 bytes):
0 1 8 9 13
+-+--------+-----+
|x| cli_id |?????|
+-+--------+-----+
x = packet identifier 0x38
cli_id = 64 bit identifier
? = unknown, probably flags/padding
Server packet (26 bytes):
0 1 8 9 13 14 21 2225
+-+--------+-----+--------+----+
|x| srv_id |?????| cli_id |????|
+-+--------+-----+--------+----+
x = packet identifier 0x40
cli_id = 64 bit identifier
? = unknown, probably flags/padding
bit 9 was 1 and the rest were 0 in testing
Issues a warning to indicate that the given class is deprecated. If a message is given, it is appended to the deprecation warning.
Issues a warning to indicate that the given function is deprecated. If a message is given, it is appended to the deprecation warning.
Escapes a string so it is valid within XML or XHTML.
Utility methods for working with WSGI servers.
Bases: object
Base WSGI application wrapper. Subclasses need to implement __call__.
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 = nova.api.fancy_api:Wadl.factory
which would result in a call to the Wadl class as
import nova.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.
Bases: nova.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.
Iterator that prints the contents of a wrapper string.
Bases: object
Used to load WSGI applications from paste configurations.
Return the paste URLMap wrapped WSGI application.
Parameters: | name – Name of the application to load. |
---|---|
Returns: | Paste URLMap object wrapping the requested application. |
Raises : | nova.exception.PasteAppNotFound |
Bases: nova.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.
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 = nova.api.analytics:Analytics.factory
which would result in a call to the Analytics class as
import nova.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.
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.
Do whatever you’d like to the response.
Bases: webob.request.Request
Bases: object
WSGI middleware that maps incoming requests to WSGI apps.
Bases: object
Server class to manage a WSGI server, serving a WSGI application.
Start serving a WSGI application.
Parameters: | backlog – Maximum number of queued connections. |
---|---|
Returns: | None |
Run a raw TCP server with the given application.
Stop this server.
This is not a very nice action, as currently the method by which a server is stopped is by killing it’s eventlet.
Returns: | None |
---|
Block, until the server has stopped.
Waits on the server’s eventlet to finish, then returns.
Returns: | None |
---|