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.
-
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”
}]
-
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”
-
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.
-
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_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.
-
removeAllContainers
(update)[source]¶ Remove all containers on the system. This should only be used as part of a factory reset mechanism.
Returns: None
-
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
-
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
paradrop.core.container.dockerfile module¶
This module generates a Dockerfile for use with light chutes.
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
-
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’}
-
-
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.