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.

buildImage(update)[source]

Build the Docker image and monitor progress.

build_host_config(chute)[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(chute, env, command, onerror='raise', pid=None)[source]

Call command within a chute’s namespace.

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

call_retry(cmd, env, delay=3, tries=3)[source]
cleanup_net_interfaces(chute)[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.

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.

getImageName(chute)[source]
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(chute)[source]

Prepare environment variables for a chute container.

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

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

Returns:None
removeChute(update)[source]

Remove a docker container and the image it was built on based on the passed in update.

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

Remove the newly started container during abort sequence.

removeNewImage(update)[source]

Remove the newly built image during abort sequence.

removeOldContainer(update)[source]

Remove the docker container for the old version of a chute.

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

Remove the image for the old version of the chute.

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]
setup_net_interfaces(chute)[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
startChute(update)[source]

Create a docker container based on the passed in update.

startOldContainer(update)[source]

Create a docker container using the old version of the image.

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(config)[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 = ['use', '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 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(chutename)[source]

Bases: object

attach()[source]

Start listening for log messages.

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

‘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(chute_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