paradrop.core.container package

Submodules

paradrop.core.container.chutecontainer module

class ChuteContainer(name, docker_url='unix://var/run/docker.sock')[source]

Bases: object

Class for accessing information about a chute’s container.

getID()[source]

Look up the container ID as used by Docker.

getIP()[source]

Look up the IP address assigned to the container.

getPID()[source]

Look up the PID of the container, if running.

getPortConfiguration(port, protocol='tcp')[source]

Look up network port configuration. This tells us if a port in the host is bound to a port inside the container.

Returns a list, typically with zero or one elements.

Example:

[{
“HostIp”: “0.0.0.0”, “HostPort”: “32768”

}]

getStatus()[source]

Return the status of the container (running, exited, paused).

Returns “missing” if the chute does not exist.

inspect()[source]

Return the full container status from Docker.

isRunning()[source]

Check if container is running.

Returns True/False; returns False if the container does not exist.

paradrop.core.container.dockerapi module

Functions associated with deploying and cleaning up docker containers.

build_host_config(update, service)[source]

Build the host_config dict for a docker container based on the passed in update.

Parameters:chute (obj) – The chute object containing information about the chute.
Returns:(dict) The host_config dict which docker needs in order to create the container.
call_in_netns(service, env, command, onerror='raise', pid=None)[source]

Call command within a service’s namespace.

command: should be a list of strings. onerror: should be “raise” or “ignore”

call_retry(cmd, env, delay=3, tries=3)[source]
check_image(update, service)[source]

Check if image exists.

cleanup_net_interfaces(update)[source]

Cleanup special interfaces when bringing down a container.

This applies to monitor mode interfaces, which need to be renamed before they come back to the host network, e.g. “mon0” inside the container should be renamed to the appropriate “wlanX” before the container exits.

create_bridge(update)[source]

Create a user-defined bridge network for the chute.

getBridgeGateway()[source]

Look up the gateway IP address for the docker bridge network.

This is the docker0 IP address; it is the IP address of the host from the chute’s perspective.

getPortList(chute)[source]

Get a list of ports to expose in the format expected by create_container.

Uses the port binding dictionary from the chute host_config section. The keys are expected to be integers or strings in one of the following formats: “port” or “port/protocol”.

Example: port_bindings = {

“1111/udp”: 1111, “2222”: 2222

} getPortList returns [(1111, ‘udp’), (2222, ‘tcp’)]

prepare_environment(update, service)[source]

Prepare environment variables for a chute container.

prepare_image(update, service)[source]

Prepare a Docker image for execution.

This is usually the longest operation during a chute installation, so instead of running this step in the update thread, we spin off a worker thread and return a Deferred. This will suspend processing of the current update until the worker thread finishes.

prepare_port_bindings(service)[source]
removeAllContainers(update)[source]

Remove all containers on the system. This should only be used as part of a factory reset mechanism.

Returns:None
remove_bridge(update)[source]

Remove the bridge network associated with the chute.

remove_container(update, service)[source]

Remove a service’s container.

remove_image(update, service)[source]

Remove a Docker image.

restartChute(update)[source]

Start a docker container based on the passed in update.

Parameters:update (obj) – The update object containing information about the chute.
Returns:None
revertResourceAllocation(update)[source]
setResourceAllocation(update)[source]

Adjust compute resources assigned to chute containers.

setup_net_interfaces(update)[source]

Link interfaces in the host to the internal interfaces in the Docker container.

The commands are based on the pipework script (https://github.com/jpetazzo/pipework).

Parameters:chute – The chute object containing information about the chute.
Returns:None
start_container(update, service)[source]

Start running a service in a new container.

stopChute(update)[source]

Stop a docker container based on the passed in update.

Parameters:update (obj) – The update object containing information about the chute.
Returns:None
writeDockerConfig()[source]

Write options to Docker configuration.

Mainly, we want to tell Docker not to start containers automatically on system boot.

paradrop.core.container.dockerfile module

This module generates a Dockerfile for use with light chutes.

class Dockerfile(service)[source]

Bases: object

getBytesIO()[source]

Geterate a Dockerfile and return as a BytesIO object.

getString()[source]

Generate a Dockerfile as a multi-line string.

isValid()[source]

Check if configuration is valid.

Returns a tuple (True/False, None or str).

requiredFields = ['image', 'command']
writeFile(path)[source]

Generate Dockerfile and write to a file.

paradrop.core.container.downloader module

This module downloads a package from a given URL using one of potentially many different methods. We currently support the github web API and simple HTTP(S). The github method is more developed and returns meta data about the project (the commit hash and message), but support for other methods, e.g. download a tar file that was uploaded to a web server, are not precluded.

Private downloads are supported with the HTTP Authorization header. For github, we need to use the github API to request a token to access the owner’s private repository. That part is not implemented here.

class Downloader(url, user=None, secret=None, repo_owner=None, repo_name=None)[source]

Bases: object

download()[source]
extract()[source]
fetch()[source]

Download the project.

Returns the full path to the temporary directory containing the project and a dictionary containing meta data.

meta()[source]
class GitSSHDownloader(url, checkout='master', **kwargs)[source]

Bases: paradrop.core.container.downloader.Downloader

download()[source]
meta()[source]
class GithubDownloader(url, checkout='master', **kwargs)[source]

Bases: paradrop.core.container.downloader.Downloader

download()[source]
meta()[source]

Return repository meta data as a dictionary.

class WebDownloader(url, user=None, secret=None, repo_owner=None, repo_name=None)[source]

Bases: paradrop.core.container.downloader.Downloader

download()[source]
meta()[source]

Return repository meta data as a dictionary.

downloader(url, user=None, secret=None, **kwargs)[source]

Return an appropriate Downloader for the given URL.

This should be used in a “with … as …” statement to perform cleanup on all exit cases.

Example: with downloader(“https://github.com/…”) as dl:

path, meta = dl.fetch() # do some work on the repo here

paradrop.core.container.log_provider module

Provides messages from container logs (STDOUT and STDERR).

class LogProvider(chute)[source]

Bases: object

attach()[source]

Start listening for log messages.

Log messages in the queue will appear like the following: {

‘service’: ‘main’, ‘timestamp’: ‘2017-01-30T15:46:23.009397536Z’, ‘message’: ‘Something happened’

}

detach()[source]

Stop listening for log messages.

After this is called, no additional messages will be added to the queue.

get_logs()[source]
monitor_logs(service_name, container_name, queue, tail=200)[source]

Iterate over log messages from a container and add them to the queue for consumption. This function will block and wait for new messages from the container. Use the queue to interface with async code.

tail: number of lines to retrieve from log history; the string “all” is also valid, but highly discouraged for performance reasons.

Module contents