paradrop.core.chute package

Submodules

paradrop.core.chute.chute module

class Chute(description=None, name=None, owner=None, state='running', version=None, config=NOTHING, environment=NOTHING, services=NOTHING, web=NOTHING, cache=NOTHING)[source]

Bases: object

This Chute class provides the internal representation of a Paradrop chute.

This class encapsulates the complex configuration details of a chute and provides a stable interface for the execution path even as the chute specification language evolves over time.

The Chute class has minimal external dependencies, e.g. no dependency on the Docker API. Chute objects should be immutable, since they describe a desired software state at a fixed point in time.

Args:
name (str): The name of the chute. description (str): The human-friendly description of the chute. state (str): Desired run state of the chute (“running”, “stopped”). version (str): The version of the chute. config (dict): Configuration settings for the chute. environment (dict): Environment variables to set for all chute services.
STATE_DISABLED = 'disabled'
STATE_FROZEN = 'frozen'
STATE_INVALID = 'invalid'
STATE_RUNNING = 'running'
STATE_STOPPED = 'stopped'
add_service(service)[source]

Add a service to the chute.

create_specification()[source]

Create a new chute specification from the existing chute.

This is a completely clean copy of all information necessary to rebuild the Chute object. It should contain only primitive types, which can easily be serialized as JSON or YAML.

getCache(key)[source]

Get a value from the cache or None if it does not exist.

getCacheContents()[source]

Get the contents of the cache as a dictionary.

getConfiguration()[source]

Get the chute’s configuration object.

getHostConfig()[source]

Get the chute’s host_config options for Docker.

Returns an empty dictionary if there is no host_config setting.

getWebPort()[source]

Get the port configured for the chute’s web server.

Returns port (int) or None if no port is configured.

get_default_service()[source]

Get one of the chute’s services designated as the default one.

This is more for convenience with existing API functions where the caller did not need to specify a service because prior to 0.12.0, chutes could only have one Docker container. We use some heuristics such as the service’s name is “main” to identify one of the services as the default.

get_environment()[source]

Get the chute environment variables.

These are defined by the developer or administrator and passed to all services that belong to the chute.

get_owner()[source]

Get the name of the user who owns this installed chute.

get_service(name)[source]

Get a service by name.

get_services()[source]

Get a list of services installed by this chute.

get_web_port_and_service()[source]

Get the port and Service object that provides this chutes web service.

Returns a tuple containing the port number and Service object. Both values will be None if a web service is not configured.

inherit_attributes(other)[source]

Inherit attributes from another version of the chute.

If any settings are None or missing in this chute but present in the other version, they will be copied over. The return value is a dictionary containing changes that were applied.

isRunning()[source]

Check if the chute is supposed to be running.

isValid()[source]

Return True only if the Chute object we have has all the proper things defined to be in a valid state.

setCache(key, value)[source]

Set a value in the cache.

Deprecated: Most of the cache functionality has been moved to the Update object because they are values that are used as temporary storage between one update step and the following steps. However, there are a few instances of cache values that we do still read from chute storage. Any calls to the getCache method throughout the project are still depending on this functionality, so we have corresponding calls to setCache that ensure the required information is present in the chute cache and not just in the update cache. Eventually, we should remove this dependency either by using a less stateful design or by formalizing the process for storing persistent chute state, such as the networkInterfaces list.

updateCache(other)[source]

Update the chute cache from another dictionary.

paradrop.core.chute.chute_storage module

class ChuteStorage(filename=None, save_timer=0)[source]

Bases: paradrop.lib.utils.pd_storage.PDStorage

ChuteStorage class.

This class holds onto the list of Chutes on this AP.

It implements the PDStorage class which allows us to save the chuteList to disk transparently

attrSaveable()[source]

Returns True if we should save the ChuteList, otherwise False.

chuteList = {}
clearChuteStorage()[source]
deleteChute(ch)[source]

Deletes a chute from the chute storage. Can be sent the chute object, or the chute name.

getAttr()[source]

Get our attr (as class variable for all to see)

getChute(name)[source]

Returns a reference to a chute we have in our cache, or None.

getChuteList()[source]

Return a list of the names of the chutes we know of.

classmethod get_chute(name)[source]
saveChute(ch)[source]

Saves the chute provided in our internal chuteList. Also since we just received a new chute to hold onto we should save our ChuteList to disk.

setAttr(attr)[source]

Save our attr however we want (as class variable for all to see)

paradrop.core.chute.restart module

Contains the functions required to restart chutes properly on power cycle of device. Checks with pdconfd to make sure it was able to properly bring up all interfaces before starting chutes.

reloadChutes()[source]

Get update objects to chutes that should be running at startup.

This function is called to restart any chutes that were running prior to the system being restarted. It waits for pdconfd to come up and report whether or not it failed to bring up any of the interfaces that existed before the power cycle. If pdconfd indicates something failed we then force a stop update in order to bring down all interfaces associated with that chute and mark it with a warning. If the stop fails we mark the chute with a warning manually and change its state to stopped and save to storage this isn’t great as it could mean our system still has interfaces up associated with that chute. If pdconfd doesn’t report failure we attempt to start the chute and if this fails we trust the abort process to restore the system to a consistent state and we manually mark the chute as stopped and add a warning to it.

Returns:(list) A list of UpdateChute objects that should be run before accepting new updates.
updateStatus(update)[source]

This function is a callback for the updates we do upon restarting the system. It checks whether or not the update completed successfully and if not it changes the state of the chute to stopped and adds a warning. :param update: The update object containing information about the chute that was created and whether it was successful or not. :type update: obj :returns: None

Module contents