seaworthy.helpers

Classes that track resource creation and removal to ensure that all resources are namespaced and cleaned up after use.

class ContainerHelper(client, namespace, image_helper, network_helper, volume_helper)[source]

Todo

Document this properly.

create(name, image, fetch_image=False, network=None, volumes={}, **kwargs)[source]

Create a new container.

Parameters:
  • name – The name for the container. This will be prefixed with the namespace.
  • image – The image tag or image object to create the container from.
  • network – The network to connect the container to. The container will be given an alias with the name parameter. Note that, unlike the Docker Python client, this parameter can be a Network model object, and not just a network ID or name.
  • volumes

    A mapping of volumes to bind parameters. The keys to this mapping can be any of three types of objects:

    • A Volume model object
    • The name of a volume (str)
    • A path on the host to bind mount into the container (str)

    The bind parameters, i.e. the values in the mapping, can be of two types:

    • A full bind specifier (dict), for example {'bind': '/mnt', 'mode': 'rw'}
    • A “short-form” bind specifier (str), for example /mnt:rw
  • fetch_image – Whether to attempt to pull the image if it is not found locally.
  • kwargs – Other parameters to create the container with.
remove(container, force=True, volumes=True)[source]

Remove a container.

Parameters:
  • container – The container to remove.
  • force – Whether to force the removal of the container, even if it is running. Note that this defaults to True, unlike the Docker default.
  • volumes – Whether to remove any volumes that were created implicitly with this container, i.e. any volumes that were created due to VOLUME directives in the Dockerfile. External volumes that were manually created will not be removed. Note that this defaults to True, unlike the Docker default (where the equivalent parameter, v, defaults to False).
class DockerHelper(namespace='test', client=None)[source]

Todo

Document this properly.

teardown()[source]

Clean up all resources when we’re done with them.

class ImageHelper(client)[source]

Todo

Document this properly.

fetch(tag)[source]

Fetch this image if it isn’t already present.

class NetworkHelper(client, namespace)[source]

Todo

Document this properly.

create(name, check_duplicate=True, **kwargs)[source]

Create a new network.

Parameters:
  • name – The name for the network. This will be prefixed with the namespace.
  • check_duplicate – Whether or not to check for networks with the same name. Docker allows the creation of multiple networks with the same name (unlike containers). This seems to cause problems sometimes for some reason (?). The Docker Python client _claims_ (as of 2.5.1) that check_duplicate defaults to True but it actually doesn’t. We default it to True ourselves here.
  • kwargs – Other parameters to create the network with.
get_default(create=True)[source]

Get the default bridge network that containers are connected to if no other network options are specified.

Parameters:create – Whether or not to create the network if it doesn’t already exist.
remove(resource, **kwargs)

Remove an instance of this resource type.

class VolumeHelper(client, namespace)[source]

Todo

Document this properly.

create(name, **kwargs)[source]

Create a new volume.

Parameters:
  • name – The name for the volume. This will be prefixed with the namespace.
  • kwargs – Other parameters to create the volume with.
remove(resource, **kwargs)

Remove an instance of this resource type.

fetch_image(client, name)[source]

Fetch an image if it isn’t already present.

This works like docker pull and will pull the tag latest if no tag is specified in the image name.

fetch_images(client, images)[source]

Fetch images if they aren’t already present.