dockermap.map.policy package

Submodules

dockermap.map.policy.base module

class dockermap.map.policy.base.BasePolicy(container_maps, clients)

Bases: object

Abstract base class providing the basic infrastructure for generating actions based on container state.

Parameters:
classmethod aname(map_name, attached_name, parent_name=None)

Generates a container name that should be used for creating new attached volume containers and checking the status of existing containers.

In this implementation, the format will be <map name>.<attached>, or <map name>.<parent name>.<attached> if the parent container configuration name is provided.

Parameters:
  • map_name (unicode | str) – Container map name.
  • attached_name (unicode | str) – Attached container alias.
  • parent_name (unicode | str) – Container configuration name that has contains attached container.
Returns:

Container name.

Return type:

unicode | str

base_image = u'tianon/true:latest'
clients

Docker client objects and configurations.

Returns:Dictionary of Docker client objects.
Return type:dict[unicode | str, dockermap.map.config.client.ClientConfiguration]
classmethod cname(map_name, container, instance=None)

Generates a container name that should be used for creating new containers and checking the status of existing containers.

In this implementation, the format will be <map name>.<container name>.<instance>. If no instance is provided, it is just <map name>.<container name>.

Parameters:
  • map_name (unicode | str) – Container map name.
  • container (unicode | str) – Container configuration name.
  • instance (unicode | str) – Instance name (optional).
Returns:

Container name.

Return type:

unicode | str

container_maps

Container maps with container configurations to base actions on.

Returns:Dictionary of container maps.
Return type:dict[unicode | str, dockermap.map.config.main.ContainerMap]
container_names

Names of existing containers on each client.

Returns:Dictionary of container names.
Return type:dict[unicode | str, dockermap.map.policy.cache.CachedContainerNames]
core_image = u'busybox:latest'
default_client_name = u'__default__'
default_network_names = [u'bridge']
default_volume_paths

Defined volume names of each map, with a dictionary of default container paths per volume alias. Also includes paths of attached volumes that are defined directly on container configurations.

Returns:Default volume paths.
Return type:dict[unicode | str, dict]
get_dependencies(config_id)

Generates the list of dependency containers, in reverse order (i.e. the last dependency coming first).

Parameters:config_id (dockermap.map.input.MapConfigId) – MapConfigId tuple.
Returns:Dependency configuration types, container map names, configuration names, and instances.
Return type:collections.Iterable[(unicode | str, unicode | str, unicode | str, unicode | str)]
get_dependents(config_id)

Generates the list of dependent containers, in reverse order (i.e. the last dependent coming first).

Parameters:config_id (dockermap.map.input.MapConfigId) – MapConfigId tuple.
Returns:Dependent configuration types, container map names, configuration names, and instances.
Return type:collections.Iterable[(unicode | str, unicode | str, unicode | str, unicode | str)]
classmethod get_hostname(container_name, client_name=None)

Determines the host name of a container. In this implementation, replaces all dots and underscores of a container name with a dash; then attaches another dash with the client name, unless there is just one default client.

Parameters:
  • container_name (unicode | str) – Name of the container.
  • client_name (unicode | str) – Name of the client configuration, where applicable.
Returns:

Host name.

Return type:

unicode | str

hostname_replace = [(u'_', u'-'), (u'.', u'-')]
images

Names of images on each client.

Returns:Dictionary of image names per client.
Return type:dict[unicode | str, dockermap.map.policy.cache.CachedImages]
network_names

Names of existing networks on each client.

Returns:Dictionary of network names.
Return type:dict[unicode | str, dockermap.map.policy.cache.CachedNetworkNames]
classmethod nname(map_name, network_name)

Generates a network name that should be used for creating new networks and checking the status of existing networks on the client.

In this implementation, the format will be <map name>.<network name>.

Parameters:
  • map_name (unicode | str) – Container map name.
  • network_name (unicode | str) – Network configuration name.
Returns:

Network name.

Return type:

unicode | str

volume_names

Names of existing volumes on each client.

Returns:Dictionary of volume names.
Return type:dict[unicode | str, dockermap.map.policy.cache.CachedVolumeNames]
volume_permissions

Defined volume names of each map, with a dictionary of the configured permissions per volume alias. Only applies to attached volumes.

Returns:Configured volume permissions.
Return type:dict[unicode | str, dict]
volume_users

Defined volume names of each map, with a dictionary of the configured user per volume alias. Only applies to attached volumes.

Returns:Configured volume paths.
Return type:dict[unicode | str, dict]

dockermap.map.policy.cache module

class dockermap.map.policy.cache.CachedContainerNames(client)

Bases: dockermap.map.policy.cache.CachedItems, dict

refresh()

Fetches all current container names from the client, along with their id.

class dockermap.map.policy.cache.CachedImages(client)

Bases: dockermap.map.policy.cache.CachedItems, dict

Dictionary of image names and ids, which also keeps track of the client object to pull images if necessary.

refresh()

Fetches image and their ids from the client.

refresh_repo(name)
class dockermap.map.policy.cache.CachedItems(client)

Bases: object

Abstract implementation for a caching collection of client names or ids.

Parameters:client (docker.client.Client) – Client object.
refresh()

Forces a refresh of the cached items. Does not need to return anything.

class dockermap.map.policy.cache.CachedNetworkNames(client)

Bases: dockermap.map.policy.cache.CachedItems, dict

refresh()

Fetches all current network names from the client, along with their id.

class dockermap.map.policy.cache.CachedVolumeNames(client)

Bases: dockermap.map.policy.cache.CachedItems, set

refresh()

Fetches all current network names from the client.

class dockermap.map.policy.cache.ContainerCache(clients, *args, **kwargs)

Bases: dockermap.map.policy.cache.DockerHostItemCache

Fetches and caches container names from a Docker host.

item_class

alias of CachedContainerNames

class dockermap.map.policy.cache.DockerHostItemCache(clients, *args, **kwargs)

Bases: dict

Abstract class for implementing caches of items (containers, images) present on the Docker client, so that their existence does not have to be checked separately for every action.

Parameters:clients (dict[unicode | str, dockermap.map.config.client.ClientConfiguration]) – Dictionary of clients with alias and client object.
item_class = None
refresh(item)

Forces a refresh of a cached item.

Parameters:item (unicode | str) – Client name.
Returns:Items in the cache.
Return type:DockerHostItemCache.item_class
class dockermap.map.policy.cache.ImageCache(clients, *args, **kwargs)

Bases: dockermap.map.policy.cache.DockerHostItemCache

Fetches and caches image names and ids from a Docker host.

item_class

alias of CachedImages

class dockermap.map.policy.cache.NetworkCache(clients, *args, **kwargs)

Bases: dockermap.map.policy.cache.DockerHostItemCache

Fetches and caches network names from a Docker host.

item_class

alias of CachedNetworkNames

refresh(item)
class dockermap.map.policy.cache.VolumeCache(clients, *args, **kwargs)

Bases: dockermap.map.policy.cache.DockerHostItemCache

Fetches and caches volume names from a Docker host.

item_class

alias of CachedVolumeNames

refresh(item)

dockermap.map.policy.dep module

class dockermap.map.policy.dep.ContainerDependencyMergeMixin

Bases: object

Resolves dependencies between ContainerConfiguration instances, based on shared and used volumes.

merge_dependency(item, resolve_parent, parents)

Merge dependencies of current configuration with further dependencies; in this instance, it means that in case of container configuration first parent dependencies are checked, and then immediate dependencies of the current configuration should be added to the list, but without duplicating any entries.

Parameters:
  • item ((unicode | str, unicode | str, unicode | str, unicode | str)) – Configuration item.
  • resolve_parent (function) – Function to resolve parent dependencies.
Returns:

List of recursively resolved dependencies of this container.

Return type:

list[(unicode | str, unicode | str, unicode | str, unicode | str)]

Raises:

CircularDependency – If the current element depends on one found deeper in the hierarchy.

class dockermap.map.policy.dep.ContainerDependencyResolver(initial=None)

Bases: dockermap.map.policy.dep.ContainerDependencyMergeMixin, dockermap.dep.MultiForwardDependencyResolver

class dockermap.map.policy.dep.ContainerDependentsResolver(initial=None)

Bases: dockermap.map.policy.dep.ContainerDependencyMergeMixin, dockermap.dep.MultiReverseDependencyResolver

dockermap.map.policy.utils module

dockermap.map.policy.utils.extract_user(user_value)

Extract the user for running a container from the following possible input formats:

  • Integer (UID)
  • User name string
  • Tuple of user, group
  • String in the format user:group
Parameters:user_value (int | tuple | unicode | str) – User name, uid, user-group tuple, or user:group string.
Returns:User name or id.
Return type:unicode | str
dockermap.map.policy.utils.get_instance_volumes(instance_detail, check_names)

Extracts the mount points and mapped directories or names of a Docker container.

Parameters:
  • instance_detail (dict) – Result from a container inspection.
  • check_names (bool) – Whether to check for named volumes.
Returns:

Dictionary of volumes, with the destination (inside the container) as a key, and the source (external to the container) as values. If check_names is True, the value contains the mounted volume name instead.

Return type:

dict[unicode | str, unicode | str]

dockermap.map.policy.utils.get_shared_volume_path(container_map, vol, instance=None)

Resolves a volume alias of a container configuration or a tuple of two paths to the host and container paths.

Parameters:
  • container_map (dockermap.map.config.main.ContainerMap) – Container map.
  • vol (dockermap.map.input.HostVolume | dockermap.map.input.SharedVolume) – SharedVolume or HostVolume tuple.
  • instance (unicode | str) – Optional instance name.
Returns:

Tuple of host path and container bind path.

Return type:

tuple[unicode | str]

dockermap.map.policy.utils.init_options(options)

Initialize create_options or start_options of a container configuration. If options is a callable, it is run to initialize the values, otherwise it simply returns options or an empty dictionary.

Parameters:options (callable or dict) – Options as a dictionary.
Returns:Initial keyword arguments.
Return type:dict

Module contents

class dockermap.map.policy.ABCPolicyUtilMeta(name, bases, dct)

Bases: abc.ABCMeta, dockermap.map.policy.PolicyUtilMeta

class dockermap.map.policy.ConfigFlags

Bases: dockermap.map.Flags

DEPENDENT = ConfigFlags(DEPENDENT)
NONE = ConfigFlags()
fields = {'DEPENDENT': 1, 'NONE': 0}
class dockermap.map.policy.PolicyUtil(policy, kwargs)

Bases: object

Base class for utility objects used by a policy and referring back to it.

Parameters:policy (dockermap.map.policy.base.BasePolicy) – Policy object instance.
get_options()
policy_options = []
class dockermap.map.policy.PolicyUtilMeta(name, bases, dct)

Bases: type