dockermap.map.runner package

Submodules

dockermap.map.runner.attached module

dockermap.map.runner.base module

dockermap.map.runner.cmd module

class dockermap.map.runner.cmd.ExecMixin

Bases: object

Utility mixin for executing configured commands inside containers.

action_method_names = [(ItemType.CONTAINER, ContainerUtilAction.EXEC_COMMANDS, u'exec_commands'), (ItemType.CONTAINER, ContainerUtilAction.EXEC_ALL, u'exec_container_commands')]
exec_commands(action, c_name, run_cmds, **kwargs)

Runs a single command inside a container.

Parameters:
Returns:

List of exec command return values (e.g. containing the command id), if applicable, or None if either no commands have been run or no values have been returned from the API.

Return type:

list[dict] | NoneType

exec_container_commands(action, c_name, **kwargs)

Runs all configured commands of a container configuration inside the container instance.

Parameters:
Returns:

List of exec command return values (e.g. containing the command id), if applicable, or None if either no commands have been run or no values have been returned from the API.

Return type:

list[dict] | NoneType

dockermap.map.runner.image module

class dockermap.map.runner.image.ImageMixin(*args, **kwargs)

Bases: object

action_method_names = [(ItemType.IMAGE, ImageAction.PULL, u'pull')]
login(action, registry, **kwargs)

Logs in to a Docker registry.

Parameters:
  • action (dockermap.map.runner.ActionConfig) – Action configuration.
  • registry (unicode | str) – Name of the registry server to login to.
  • kwargs (dict) – Additional keyword arguments to complement or override the configuration-based values.
pull(action, image_name, **kwargs)

Pulls an image for a container configuration

Parameters:
  • action (dockermap.map.runner.ActionConfig) – Action configuration.
  • image_name (unicode | str) – Image name.
  • kwargs (dict) – Additional keyword arguments to complement or override the configuration-based values.

dockermap.map.runner.network module

class dockermap.map.runner.network.NetworkUtilMixin

Bases: object

action_method_names = [(ItemType.NETWORK, NetworkUtilAction.DISCONNECT_ALL, u'disconnect_all_containers'), (ItemType.CONTAINER, Action.CONNECT, u'connect_networks'), (ItemType.CONTAINER, Action.DISCONNECT, u'disconnect_networks'), (ItemType.CONTAINER, ContainerUtilAction.CONNECT_ALL, u'connect_all_networks')]
connect_all_networks(action, container_name, **kwargs)

Connects a container to all of its configured networks. Assuming that this is typically used after container creation, where teh first endpoint is already defined, this skips the first configuration. Pass skip_first as False to change this.

Parameters:
  • action (dockermap.map.runner.ActionConfig) – Action configuration.
  • container_name (unicode | str) – Container names or id.
  • kwargs (dict) – Additional keyword arguments to complement or override the configuration-based values.
connect_networks(action, container_name, endpoints, skip_first=False, **kwargs)

Connects a container to a set of configured networks. By default this assumes the container has just been created, so it will skip the first network that is already considered during creation.

Parameters:
  • action (dockermap.map.runner.ActionConfig) – Action configuration.
  • container_name (unicode | str) – Container names or id.
  • endpoints (list[dockermap.map.input.NetworkEndpoint]) – Network endpoint configurations.
  • skip_first (bool) – Skip the first network passed in endpoints. Defaults to False, but should be set to True when the container has just been created and the first network has been set up there.
  • kwargs (dict) – Additional keyword arguments to complement or override the configuration-based values.
disconnect_all_containers(action, network_name, containers, **kwargs)

Disconnects all containers from a network.

Parameters:
  • action (dockermap.map.runner.ActionConfig) – Action configuration.
  • network_name (unicode | str) – Network name or id.
  • containers (collections.Iterable[unicode | str]) – Container names or ids.
  • kwargs (dict) – Additional keyword arguments.
disconnect_networks(action, container_name, networks, **kwargs)

Disconnects a container from a set of networks.

Parameters:
  • action (dockermap.map.runner.ActionConfig) – Action configuration.
  • container_name (unicode | str) – Container names or id.
  • networks (collections.Iterable[unicode | str]) – List of network names or ids.
  • kwargs (dict) – Additional keyword arguments.

dockermap.map.runner.script module

class dockermap.map.runner.script.ScriptMixin

Bases: object

action_method_names = [(ItemType.CONTAINER, ContainerUtilAction.SCRIPT, u'run_script')]
policy_options = [u'remove_created_after']
remove_created_after = True
run_script(action, c_name, script_path=None, entrypoint=None, command_format=None, wait_timeout=None, container_script_dir=u'/tmp/script_run', timestamps=None, tail=u'all')

Creates a container from its configuration to run a script or single command. The container is specifically created for this action. If it exists prior to the script run, it fails; optionally it can be removed by setting remove_existing_before to True. The script is run by setting entrypoint and command and mounting the directory containing the script to the new container. After the script run, the container is destroyed (excluding its dependencies), unless remove_created_after is set to False.

Parameters:
  • action (dockermap.map.runner.ActionConfig) – Action configuration.
  • c_name (unicode | str) – Container name.
  • script_path – Path to the script on the Docker host. Note that this needs to have the executable bit set, if the script runtime (e.g. bash) requires it. If no script is to be used, (e.g. for a single command), this can point to a directory for writing back results to.
  • entrypoint (unicode | str) – Entrypoint of the container. Typically this should be the scripting executable, such as /bin/bash.
  • command_format (unicode | str | list[unicode | str] | tuple[unicode | str]) – Command to pass to the container. This should be any arguments to the entrypoint, and can include a formatting string variable {script_path} which is substituted with the path inside the container. The command_format can be provided as a single string or a list of strings. Of no command is set, ['-c', '{script_path}'] is assumed, which are the arguments to /bin/bash for running a single script.
  • wait_timeout (int) – How long to wait for the container to finish. If not set, will be read from the client configuration parameter wait_timeout.
  • container_script_dir (unicode | str) – Directory to use for the script inside the container. This is also the path where other files in the same directory as the script will be located.
  • timestamps (bool) –
  • tail (unicode | str) –
Returns:

A dictionary with the container id, the client alias client, the stdout output log, and the exit code exit_code. In case a wait timeout occurred, instead of log and exit_code returns a key error.

Return type:

dict[unicode | str, dict]

dockermap.map.runner.signal_stop module

class dockermap.map.runner.signal_stop.SignalMixin

Bases: object

action_method_names = [(ItemType.CONTAINER, ContainerUtilAction.SIGNAL_STOP, u'signal_stop')]
signal_stop(action, c_name, **kwargs)

Stops a container, either using the default client stop method, or sending a custom signal and waiting for the container to stop.

Parameters:
  • action (dockermap.map.runner.ActionConfig) – Action configuration.
  • c_name (unicode | str) – Container name.
  • kwargs (dict) – Additional keyword arguments to complement or override the configuration-based values.

dockermap.map.runner.utils module

dockermap.map.runner.utils.get_host_binds(container_map, config_name, config, instance, policy, named_volumes)

Generates the list of host volumes and named volumes (where applicable) for the host config bind argument during container creation.

Parameters:
Returns:

List of shared volumes with host volumes and the read-only flag.

Return type:

list[unicode | str]

dockermap.map.runner.utils.get_port_bindings(container_config, client_config)

Generates the input dictionary contents for the port_bindings argument.

Parameters:
Returns:

Dictionary of ports with mapped port, and if applicable, with bind address

Return type:

dict[unicode | str, list[unicode | str | int | tuple]]

dockermap.map.runner.utils.get_preparation_cmd(user, permissions, path)

Generates the command lines for adjusting a volume’s ownership and permission flags. Returns an empty list if there is nothing to adjust.

Parameters:
  • user (unicode | str | int | dockermap.functional.AbstractLazyObject) – User to set ownership for on the path via chown.
  • permissions (unicode | str | dockermap.functional.AbstractLazyObject) – Permission flags to set via chmod.
  • path (unicode | str) – Path to adjust permissions on.
Returns:

Iterator over resulting command strings.

Return type:

collections.Iterable[unicode | str]

dockermap.map.runner.utils.get_volumes(container_map, config, default_volume_paths, include_named)

Generates volume paths for the volumes argument during container creation.

Parameters:
Returns:

List of shared volume mount points.

Return type:

list[unicode | str]

dockermap.map.runner.utils.get_volumes_from(container_map, config_name, config, policy, include_volumes)

Generates volume paths for the host config volumes_from argument during container creation.

Parameters:
Returns:

List of shared volume mount points.

Return type:

list[unicode | str]

dockermap.map.runner.utils.update_kwargs(kwargs, *updates)

Utility function for merging multiple keyword arguments, depending on their type:

  • Non-existent keys are added.
  • Existing lists or tuples are extended, but not duplicating entries. The keywords command and entrypoint are however simply overwritten.
  • Nested dictionaries are updated, overriding previous key-value assignments.
  • Other items are simply overwritten (just like in a regular dictionary update) unless the updating value is None.

Lists/tuples and dictionaries are (shallow-)copied before adding and late resolving values are looked up. This function does not recurse.

Parameters:
  • kwargs (dict) – Base keyword arguments. This is modified in-place.
  • updates (dict) – Dictionaries to update kwargs with.

Module contents

class dockermap.map.runner.AbstractRunner(*args, **kwargs)

Bases: dockermap.map.policy.PolicyUtil

policy_options = []
run_actions(actions)

Runs the given lists of attached actions and instance actions on the client.

Parameters:actions (list[dockermap.map.action.ItemAction]) – Actions to apply.
Returns:Where the result is not None, returns the output from the client. Note that this is a generator and needs to be consumed in order for all actions to be performed.
Return type:collections.Iterable[dict]
class dockermap.map.runner.ActionConfig(client_name, config_id, client_config, client, container_map, config)

Bases: tuple

client

Alias for field number 3

client_config

Alias for field number 2

client_name

Alias for field number 0

config

Alias for field number 5

config_id

Alias for field number 1

container_map

Alias for field number 4

class dockermap.map.runner.ActionOutput(client_name, config_id, action_type, result)

Bases: tuple

action_type

Alias for field number 2

client_name

Alias for field number 0

config_id

Alias for field number 1

result

Alias for field number 3

class dockermap.map.runner.RunnerMeta(name, bases, dct)

Bases: dockermap.map.policy.PolicyUtilMeta

dockermap.map.runner.format_image_tag()

S.format(*args, **kwargs) -> unicode

Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces (‘{‘ and ‘}’).