INSTRUCTION
stringlengths
1
46.3k
RESPONSE
stringlengths
75
80.2k
No-op state to support state config via the stateconf renderer.
def _no_op(name, **kwargs): ''' No-op state to support state config via the stateconf renderer. ''' return dict(name=name, result=True, changes={}, comment='')
Helper for deriving the current state of the container from the inspect results.
def _get_state(inspect_results): ''' Helper for deriving the current state of the container from the inspect results. ''' if inspect_results.get('State', {}).get('Paused', False): return 'paused' elif inspect_results.get('State', {}).get('Running', False): return 'running' el...
Decorator to run a function that requires the use of a docker.Client() instance.
def _docker_client(wrapped): ''' Decorator to run a function that requires the use of a docker.Client() instance. ''' @functools.wraps(wrapped) def wrapper(*args, **kwargs): ''' Ensure that the client is present ''' kwargs = __utils__['args.clean_kwargs'](**kwargs...
Decorator to trigger a refresh of salt mine data.
def _refresh_mine_cache(wrapped): ''' Decorator to trigger a refresh of salt mine data. ''' @functools.wraps(wrapped) def wrapper(*args, **kwargs): ''' refresh salt mine on exit. ''' returned = wrapped(*args, **__utils__['args.clean_kwargs'](**kwargs)) if _che...
Change the state of a container
def _change_state(name, action, expected, *args, **kwargs): ''' Change the state of a container ''' pre = state(name) if action != 'restart' and pre == expected: return {'result': False, 'state': {'old': expected, 'new': expected}, 'comment': ('Container \'{0}...
Get the MD5 checksum of a file from a container
def _get_md5(name, path): ''' Get the MD5 checksum of a file from a container ''' output = run_stdout(name, 'md5sum {0}'.format(pipes.quote(path)), ignore_retcode=True) try: return output.split()[0] except IndexError: # Destination ...
Get the method to be used in shell commands
def _get_exec_driver(): ''' Get the method to be used in shell commands ''' contextkey = 'docker.exec_driver' if contextkey not in __context__: from_config = __salt__['config.get'](contextkey, None) # This if block can be removed once we make docker-exec a default # option, a...
Returns a list of the top-level images (those which are not parents). If ``subset`` (an iterable) is passed, the top-level images in the subset will be returned, otherwise all top-level images will be returned.
def _get_top_level_images(imagedata, subset=None): ''' Returns a list of the top-level images (those which are not parents). If ``subset`` (an iterable) is passed, the top-level images in the subset will be returned, otherwise all top-level images will be returned. ''' try: parents = [im...
Format bytes as human-readable file sizes
def _size_fmt(num): ''' Format bytes as human-readable file sizes ''' try: num = int(num) if num < 1024: return '{0} bytes'.format(num) num /= 1024.0 for unit in ('KiB', 'MiB', 'GiB', 'TiB', 'PiB'): if num < 1024.0: return '{0:3.1f}...
Common functionality for running low-level API calls
def _client_wrapper(attr, *args, **kwargs): ''' Common functionality for running low-level API calls ''' catch_api_errors = kwargs.pop('catch_api_errors', True) func = getattr(__context__['docker.client'], attr, None) if func is None or not hasattr(func, '__call__'): raise SaltInvocation...
Process a status update from a docker build, updating the data structure
def _build_status(data, item): ''' Process a status update from a docker build, updating the data structure ''' stream = item['stream'] if 'Running in' in stream: data.setdefault('Intermediate_Containers', []).append( stream.rstrip().split()[-1]) if 'Successfully built' in st...
Process a status update from docker import, updating the data structure
def _import_status(data, item, repo_name, repo_tag): ''' Process a status update from docker import, updating the data structure ''' status = item['status'] try: if 'Downloading from' in status: return elif all(x in string.hexdigits for x in status): # Status ...
Process a status update from a docker pull, updating the data structure. For containers created with older versions of Docker, there is no distinction in the status updates between layers that were already present (and thus not necessary to download), and those which were actually downloaded. Because o...
def _pull_status(data, item): ''' Process a status update from a docker pull, updating the data structure. For containers created with older versions of Docker, there is no distinction in the status updates between layers that were already present (and thus not necessary to download), and those whi...
Process a status update from a docker push, updating the data structure
def _push_status(data, item): ''' Process a status update from a docker push, updating the data structure ''' status = item['status'].lower() if 'id' in item: if 'already pushed' in status or 'already exists' in status: # Layer already exists already_pushed = data.set...
Process an API error, updating the data structure
def _error_detail(data, item): ''' Process an API error, updating the data structure ''' err = item['errorDetail'] if 'code' in err: try: msg = ': '.join(( item['errorDetail']['code'], item['errorDetail']['message'] )) except Ty...
Take input kwargs and return a kwargs dict to pass to docker-py's create_container() function.
def _get_create_kwargs(skip_translate=None, ignore_collisions=False, validate_ip_addrs=True, client_args=None, **kwargs): ''' Take input kwargs and return a kwargs dict to pass to docker-py's create_container() funct...
.. versionadded:: 2017.7.0 .. versionchanged:: 2018.3.0 Renamed from ``docker.compare_container`` to ``docker.compare_containers`` (old function name remains as an alias) Compare two containers' Config and and HostConfig and return any differences between the two. first Name or...
def compare_containers(first, second, ignore=None): ''' .. versionadded:: 2017.7.0 .. versionchanged:: 2018.3.0 Renamed from ``docker.compare_container`` to ``docker.compare_containers`` (old function name remains as an alias) Compare two containers' Config and and HostConfig and return...
.. versionadded:: 2018.3.0 Returns the differences between two containers' networks. When a network is only present one of the two containers, that network's diff will simply be represented with ``True`` for the side of the diff in which the network is present) and ``False`` for the side of the diff in...
def compare_container_networks(first, second): ''' .. versionadded:: 2018.3.0 Returns the differences between two containers' networks. When a network is only present one of the two containers, that network's diff will simply be represented with ``True`` for the side of the diff in which the networ...
.. versionadded:: 2018.3.0 Compare two networks and return any differences between the two first Name or ID of first container second Name or ID of second container ignore : Name,Id,Created,Containers A comma-separated list (or Python list) of keys to ignore when comp...
def compare_networks(first, second, ignore='Name,Id,Created,Containers'): ''' .. versionadded:: 2018.3.0 Compare two networks and return any differences between the two first Name or ID of first container second Name or ID of second container ignore : Name,Id,Created,Containe...
.. versionadded:: 2018.3.0 Return a list of running containers attached to the specified network name Network name verbose : False If ``True``, return extended info about each container (IP configuration, etc.) CLI Example: .. code-block:: bash salt myminion doc...
def connected(name, verbose=False): ''' .. versionadded:: 2018.3.0 Return a list of running containers attached to the specified network name Network name verbose : False If ``True``, return extended info about each container (IP configuration, etc.) CLI Example: ...
.. versionadded:: 2016.3.7,2016.11.4,2017.7.0 Performs a ``docker login`` to authenticate to one or more configured repositories. See the documentation at the top of this page to configure authentication credentials. Multiple registry URLs (matching those configured in Pillar) can be passed, and S...
def login(*registries): ''' .. versionadded:: 2016.3.7,2016.11.4,2017.7.0 Performs a ``docker login`` to authenticate to one or more configured repositories. See the documentation at the top of this page to configure authentication credentials. Multiple registry URLs (matching those configured...
Returns the containers and images, if any, which depend on the given image name Name or ID of image **RETURN DATA** A dictionary containing the following keys: - ``Containers`` - A list of containers which depend on the specified image - ``Images`` - A list of IDs of images which depend...
def depends(name): ''' Returns the containers and images, if any, which depend on the given image name Name or ID of image **RETURN DATA** A dictionary containing the following keys: - ``Containers`` - A list of containers which depend on the specified image - ``Images`` - A lis...
Get information on changes made to container's filesystem since it was created. Equivalent to running the ``docker diff`` Docker CLI command. name Container name or ID **RETURN DATA** A dictionary containing any of the following keys: - ``Added`` - A list of paths that were added. -...
def diff(name): ''' Get information on changes made to container's filesystem since it was created. Equivalent to running the ``docker diff`` Docker CLI command. name Container name or ID **RETURN DATA** A dictionary containing any of the following keys: - ``Added`` - A list of ...
Check if a given container exists name Container name or ID **RETURN DATA** A boolean (``True`` if the container exists, otherwise ``False``) CLI Example: .. code-block:: bash salt myminion docker.exists mycontainer
def exists(name): ''' Check if a given container exists name Container name or ID **RETURN DATA** A boolean (``True`` if the container exists, otherwise ``False``) CLI Example: .. code-block:: bash salt myminion docker.exists mycontainer ''' contextkey = 'dock...
Return the history for an image. Equivalent to running the ``docker history`` Docker CLI command. name Container name or ID quiet : False If ``True``, the return data will simply be a list of the commands run to build the container. .. code-block:: bash $ salt...
def history(name, quiet=False): ''' Return the history for an image. Equivalent to running the ``docker history`` Docker CLI command. name Container name or ID quiet : False If ``True``, the return data will simply be a list of the commands run to build the container. ...
Returns information about the Docker images on the Minion. Equivalent to running the ``docker images`` Docker CLI command. all : False If ``True``, untagged images will also be returned verbose : False If ``True``, a ``docker inspect`` will be run on each image returned. **RETURN DAT...
def images(verbose=False, **kwargs): ''' Returns information about the Docker images on the Minion. Equivalent to running the ``docker images`` Docker CLI command. all : False If ``True``, untagged images will also be returned verbose : False If ``True``, a ``docker inspect`` will ...
.. versionchanged:: 2017.7.0 Volumes and networks are now checked, in addition to containers and images. This is a generic container/image/volume/network inspecton function. It will run the following functions in order: - :py:func:`docker.inspect_container <salt.modules.dockermod.ins...
def inspect(name): ''' .. versionchanged:: 2017.7.0 Volumes and networks are now checked, in addition to containers and images. This is a generic container/image/volume/network inspecton function. It will run the following functions in order: - :py:func:`docker.inspect_container ...
Retrieves image information. Equivalent to running the ``docker inspect`` Docker CLI command, but will only look for image information. .. note:: To inspect an image, it must have been pulled from a registry or built locally. Images on a Docker registry which have not been pulled cannot ...
def inspect_image(name): ''' Retrieves image information. Equivalent to running the ``docker inspect`` Docker CLI command, but will only look for image information. .. note:: To inspect an image, it must have been pulled from a registry or built locally. Images on a Docker registry whic...
Returns a list of containers by name. This is different from :py:func:`docker.ps <salt.modules.dockermod.ps_>` in that :py:func:`docker.ps <salt.modules.dockermod.ps_>` returns its results organized by container ID. all : False If ``True``, stopped containers will be included in return data ...
def list_containers(**kwargs): ''' Returns a list of containers by name. This is different from :py:func:`docker.ps <salt.modules.dockermod.ps_>` in that :py:func:`docker.ps <salt.modules.dockermod.ps_>` returns its results organized by container ID. all : False If ``True``, stopped con...
Returns a list of tagged images CLI Example: .. code-block:: bash salt myminion docker.list_tags
def list_tags(): ''' Returns a list of tagged images CLI Example: .. code-block:: bash salt myminion docker.list_tags ''' ret = set() for item in six.itervalues(images()): if not item.get('RepoTags'): continue ret.update(set(item['RepoTags'])) retur...
.. versionadded:: 2018.3.0 Given an image name (or partial image ID), return the full image ID. If no match is found among the locally-pulled images, then ``False`` will be returned. CLI Examples: .. code-block:: bash salt myminion docker.resolve_image_id foo salt myminion docker...
def resolve_image_id(name): ''' .. versionadded:: 2018.3.0 Given an image name (or partial image ID), return the full image ID. If no match is found among the locally-pulled images, then ``False`` will be returned. CLI Examples: .. code-block:: bash salt myminion docker.resolve_i...
.. versionadded:: 2017.7.2 .. versionchanged:: 2018.3.0 Instead of matching against pulled tags using :py:func:`docker.list_tags <salt.modules.dockermod.list_tags>`, this function now simply inspects the passed image name using :py:func:`docker.inspect_image <salt.modules.dockermod.i...
def resolve_tag(name, **kwargs): ''' .. versionadded:: 2017.7.2 .. versionchanged:: 2018.3.0 Instead of matching against pulled tags using :py:func:`docker.list_tags <salt.modules.dockermod.list_tags>`, this function now simply inspects the passed image name using :py:func:`d...
.. versionchanged:: 2018.3.0 Support for all of docker-py's `logs()`_ function's arguments, with the exception of ``stream``. Returns the logs for the container. An interface to docker-py's `logs()`_ function. name Container name or ID stdout : True Return stdout lines...
def logs(name, **kwargs): ''' .. versionchanged:: 2018.3.0 Support for all of docker-py's `logs()`_ function's arguments, with the exception of ``stream``. Returns the logs for the container. An interface to docker-py's `logs()`_ function. name Container name or ID std...
Returns port mapping information for a given container. Equivalent to running the ``docker port`` Docker CLI command. name Container name or ID .. versionchanged:: 2019.2.0 This value can now be a pattern expression (using the pattern-matching characters defined in fnma...
def port(name, private_port=None): ''' Returns port mapping information for a given container. Equivalent to running the ``docker port`` Docker CLI command. name Container name or ID .. versionchanged:: 2019.2.0 This value can now be a pattern expression (using the ...
Returns information about the Docker containers on the Minion. Equivalent to running the ``docker ps`` Docker CLI command. all : False If ``True``, stopped containers will also be returned host: False If ``True``, local host's network topology will be included verbose : False ...
def ps_(filters=None, **kwargs): ''' Returns information about the Docker containers on the Minion. Equivalent to running the ``docker ps`` Docker CLI command. all : False If ``True``, stopped containers will also be returned host: False If ``True``, local host's network topology w...
Returns the state of the container name Container name or ID **RETURN DATA** A string representing the current state of the container (either ``running``, ``paused``, or ``stopped``) CLI Example: .. code-block:: bash salt myminion docker.state mycontainer
def state(name): ''' Returns the state of the container name Container name or ID **RETURN DATA** A string representing the current state of the container (either ``running``, ``paused``, or ``stopped``) CLI Example: .. code-block:: bash salt myminion docker.state...
Searches the registry for an image name Search keyword official : False Limit results to official builds trusted : False Limit results to `trusted builds`_ **RETURN DATA** A dictionary with each key being the name of an image, and the following information for each i...
def search(name, official=False, trusted=False): ''' Searches the registry for an image name Search keyword official : False Limit results to official builds trusted : False Limit results to `trusted builds`_ **RETURN DATA** A dictionary with each key being the n...
Runs the `docker top` command on a specific container name Container name or ID CLI Example: **RETURN DATA** A list of dictionaries containing information about each process .. code-block:: bash salt myminion docker.top mycontainer salt myminion docker.top 0123456789a...
def top(name): ''' Runs the `docker top` command on a specific container name Container name or ID CLI Example: **RETURN DATA** A list of dictionaries containing information about each process .. code-block:: bash salt myminion docker.top mycontainer salt mymi...
Returns a dictionary of Docker version information. Equivalent to running the ``docker version`` Docker CLI command. CLI Example: .. code-block:: bash salt myminion docker.version
def version(): ''' Returns a dictionary of Docker version information. Equivalent to running the ``docker version`` Docker CLI command. CLI Example: .. code-block:: bash salt myminion docker.version ''' ret = _client_wrapper('version') version_re = re.compile(VERSION_RE) i...
Create a new container image Image from which to create the container name Name for the new container. If not provided, Docker will randomly generate one for you (it will be included in the return data). start : False If ``True``, start container after creating it ...
def create(image, name=None, start=False, skip_translate=None, ignore_collisions=False, validate_ip_addrs=True, client_timeout=salt.utils.docker.CLIENT_TIMEOUT, **kwargs): ''' Create a new container image Image from which ...
.. versionadded:: 2018.3.0 Equivalent to ``docker run`` on the Docker CLI. Runs the container, waits for it to exit, and returns the container's logs when complete. .. note:: Not to be confused with :py:func:`docker.run <salt.modules.dockermod.run>`, which provides a :py:func:`cmd.run ...
def run_container(image, name=None, skip_translate=None, ignore_collisions=False, validate_ip_addrs=True, client_timeout=salt.utils.docker.CLIENT_TIMEOUT, bg=False, replace=False, ...
Copy a file from inside a container to the Minion name Container name source Path of the file on the container's filesystem dest Destination on the Minion. Must be an absolute path. If the destination is a directory, the file will be copied into that directory. overwr...
def copy_from(name, source, dest, overwrite=False, makedirs=False): ''' Copy a file from inside a container to the Minion name Container name source Path of the file on the container's filesystem dest Destination on the Minion. Must be an absolute path. If the destination ...
Copy a file from the host into a container name Container name source File to be copied to the container. Can be a local path on the Minion or a remote file from the Salt fileserver. dest Destination on the container. Must be an absolute path. If the destination is...
def copy_to(name, source, dest, exec_driver=None, overwrite=False, makedirs=False): ''' Copy a file from the host into a container name Container name source File to be copied to the container. Can be a local path on the Minio...
Exports a container to a tar archive. It can also optionally compress that tar archive, and push it up to the Master. name Container name or ID path Absolute path on the Minion where the container will be exported overwrite : False Unless this option is set to ``True``, then i...
def export(name, path, overwrite=False, makedirs=False, compression=None, **kwargs): ''' Exports a container to a tar archive. It can also optionally compress that tar archive, and push it up to the Master. name Container name or ID pa...
Removes a container name Container name or ID force : False If ``True``, the container will be killed first before removal, as the Docker API will not permit a running container to be removed. This option is set to ``False`` by default to prevent accidental removal of a...
def rm_(name, force=False, volumes=False, **kwargs): ''' Removes a container name Container name or ID force : False If ``True``, the container will be killed first before removal, as the Docker API will not permit a running container to be removed. This option is set t...
.. versionadded:: 2017.7.0 Renames a container. Returns ``True`` if successful, and raises an error if the API returns one. If unsuccessful and the API returns no error (should not happen), then ``False`` will be returned. name Name or ID of existing container new_name New name to...
def rename(name, new_name): ''' .. versionadded:: 2017.7.0 Renames a container. Returns ``True`` if successful, and raises an error if the API returns one. If unsuccessful and the API returns no error (should not happen), then ``False`` will be returned. name Name or ID of existing con...
.. versionchanged:: 2018.3.0 If the built image should be tagged, then the repository and tag must now be passed separately using the ``repository`` and ``tag`` arguments, rather than together in the (now deprecated) ``image`` argument. Builds a docker image from a Dockerfile or a U...
def build(path=None, repository=None, tag=None, cache=True, rm=True, api_response=False, fileobj=None, dockerfile=None, buildargs=None, network_mode=None, labels=None, cache_from=None, target=None): ...
.. versionchanged:: 2018.3.0 The repository and tag must now be passed separately using the ``repository`` and ``tag`` arguments, rather than together in the (now deprecated) ``image`` argument. Commits a container, thereby promoting it to an image. Equivalent to running the ``docker co...
def commit(name, repository, tag='latest', message=None, author=None): ''' .. versionchanged:: 2018.3.0 The repository and tag must now be passed separately using the ``repository`` and ``tag`` arguments, rather than together in the (now deprec...
Return top-level images (those on which no other images depend) which do not have a tag assigned to them. These include: - Images which were once tagged but were later untagged, such as those which were superseded by committing a new copy of an existing tagged image. - Images which were loaded ...
def dangling(prune=False, force=False): ''' Return top-level images (those on which no other images depend) which do not have a tag assigned to them. These include: - Images which were once tagged but were later untagged, such as those which were superseded by committing a new copy of an existing...
.. versionchanged:: 2018.3.0 The repository and tag must now be passed separately using the ``repository`` and ``tag`` arguments, rather than together in the (now deprecated) ``image`` argument. Imports content from a local tarball or a URL as a new docker image source Content ...
def import_(source, repository, tag='latest', api_response=False): ''' .. versionchanged:: 2018.3.0 The repository and tag must now be passed separately using the ``repository`` and ``tag`` arguments, rather than together in the (now deprecated) ``imag...
.. versionchanged:: 2018.3.0 If the loaded image should be tagged, then the repository and tag must now be passed separately using the ``repository`` and ``tag`` arguments, rather than together in the (now deprecated) ``image`` argument. Load a tar archive that was created using :py...
def load(path, repository=None, tag=None): ''' .. versionchanged:: 2018.3.0 If the loaded image should be tagged, then the repository and tag must now be passed separately using the ``repository`` and ``tag`` arguments, rather than together in the (now deprecated) ``image`` argum...
Returns a list of the IDs of layers belonging to the specified image, with the top-most layer (the one correspnding to the passed name) appearing last. name Image name or ID CLI Example: .. code-block:: bash salt myminion docker.layers centos:7
def layers(name): ''' Returns a list of the IDs of layers belonging to the specified image, with the top-most layer (the one correspnding to the passed name) appearing last. name Image name or ID CLI Example: .. code-block:: bash salt myminion docker.layers centos:7 '...
.. versionchanged:: 2018.3.0 If no tag is specified in the ``image`` argument, all tags for the image will be pulled. For this reason is it recommended to pass ``image`` using the ``repo:tag`` notation. Pulls an image from a Docker registry image Image to be pulled insecur...
def pull(image, insecure_registry=False, api_response=False, client_timeout=salt.utils.docker.CLIENT_TIMEOUT): ''' .. versionchanged:: 2018.3.0 If no tag is specified in the ``image`` argument, all tags for the image will be pulled. For this reason is it recommended to...
.. versionchanged:: 2015.8.4 The ``Id`` and ``Image`` keys are no longer present in the return data. This is due to changes in the Docker Remote API. Pushes an image to a Docker registry. See the documentation at top of this page to configure authentication credentials. image Image...
def push(image, insecure_registry=False, api_response=False, client_timeout=salt.utils.docker.CLIENT_TIMEOUT): ''' .. versionchanged:: 2015.8.4 The ``Id`` and ``Image`` keys are no longer present in the return data. This is due to changes in the Docker Remote API. ...
Removes an image name Name (in ``repo:tag`` notation) or ID of image. force : False If ``True``, the image will be removed even if the Minion has containers created from that image prune : True If ``True``, untagged parent image layers will be removed as well, set ...
def rmi(*names, **kwargs): ''' Removes an image name Name (in ``repo:tag`` notation) or ID of image. force : False If ``True``, the image will be removed even if the Minion has containers created from that image prune : True If ``True``, untagged parent image layer...
.. versionchanged:: 2018.3.0 The repository and tag must now be passed separately using the ``repository`` and ``tag`` arguments, rather than together in the (now deprecated) ``image`` argument. Tag an image into a repository and return ``True``. If the tag was unsuccessful, an error wi...
def tag_(name, repository, tag='latest', force=False): ''' .. versionchanged:: 2018.3.0 The repository and tag must now be passed separately using the ``repository`` and ``tag`` arguments, rather than together in the (now deprecated) ``image`` argument. Tag an image into a repositor...
.. versionchanged:: 2017.7.0 The ``names`` and ``ids`` can be passed as a comma-separated list now, as well as a Python list. .. versionchanged:: 2018.3.0 The ``Containers`` key for each network is no longer always empty. List existing networks names Filter by name ids...
def networks(names=None, ids=None): ''' .. versionchanged:: 2017.7.0 The ``names`` and ``ids`` can be passed as a comma-separated list now, as well as a Python list. .. versionchanged:: 2018.3.0 The ``Containers`` key for each network is no longer always empty. List existing net...
.. versionchanged:: 2018.3.0 Support added for network configuration options other than ``driver`` and ``driver_opts``, as well as IPAM configuration. Create a new network .. note:: This function supports all arguments for network and IPAM pool configuration which are available...
def create_network(name, skip_translate=None, ignore_collisions=False, validate_ip_addrs=True, client_timeout=salt.utils.docker.CLIENT_TIMEOUT, **kwargs): ''' .. versionchanged:: 2018.3.0 Support added for net...
.. versionadded:: 2015.8.3 .. versionchanged:: 2017.7.0 Support for ``ipv4_address`` argument added .. versionchanged:: 2018.3.0 All arguments are now passed through to `connect_container_to_network()`_, allowing for any new arguments added to this function to be supported automa...
def connect_container_to_network(container, net_id, **kwargs): ''' .. versionadded:: 2015.8.3 .. versionchanged:: 2017.7.0 Support for ``ipv4_address`` argument added .. versionchanged:: 2018.3.0 All arguments are now passed through to `connect_container_to_network()`_, allowing ...
.. versionadded:: 2015.8.3 Disconnect container from network container Container name or ID network_id Network name or ID CLI Examples: .. code-block:: bash salt myminion docker.disconnect_container_from_network web-1 mynet salt myminion docker.disconnect_contai...
def disconnect_container_from_network(container, network_id): ''' .. versionadded:: 2015.8.3 Disconnect container from network container Container name or ID network_id Network name or ID CLI Examples: .. code-block:: bash salt myminion docker.disconnect_contain...
.. versionadded:: 2018.3.0 Runs :py:func:`docker.disconnect_container_from_network <salt.modules.dockermod.disconnect_container_from_network>` on all containers connected to the specified network, and returns the names of all containers that were disconnected. network_id Network name or ID...
def disconnect_all_containers_from_network(network_id): ''' .. versionadded:: 2018.3.0 Runs :py:func:`docker.disconnect_container_from_network <salt.modules.dockermod.disconnect_container_from_network>` on all containers connected to the specified network, and returns the names of all container...
Create a new volume .. versionadded:: 2015.8.4 name name of volume driver Driver of the volume driver_opts Options for the driver volume CLI Example: .. code-block:: bash salt myminion docker.create_volume my_volume driver=local
def create_volume(name, driver=None, driver_opts=None): ''' Create a new volume .. versionadded:: 2015.8.4 name name of volume driver Driver of the volume driver_opts Options for the driver volume CLI Example: .. code-block:: bash salt myminion dock...
Pauses a container name Container name or ID **RETURN DATA** A dictionary will be returned, containing the following keys: - ``status`` - A dictionary showing the prior state of the container as well as the new state - ``result`` - A boolean noting whether or not the action was su...
def pause(name): ''' Pauses a container name Container name or ID **RETURN DATA** A dictionary will be returned, containing the following keys: - ``status`` - A dictionary showing the prior state of the container as well as the new state - ``result`` - A boolean noting whe...
Restarts a container name Container name or ID timeout : 10 Timeout in seconds after which the container will be killed (if it has not yet gracefully shut down) **RETURN DATA** A dictionary will be returned, containing the following keys: - ``status`` - A dictionary sho...
def restart(name, timeout=10): ''' Restarts a container name Container name or ID timeout : 10 Timeout in seconds after which the container will be killed (if it has not yet gracefully shut down) **RETURN DATA** A dictionary will be returned, containing the following...
Start a container name Container name or ID **RETURN DATA** A dictionary will be returned, containing the following keys: - ``status`` - A dictionary showing the prior state of the container as well as the new state - ``result`` - A boolean noting whether or not the action was succ...
def start_(name): ''' Start a container name Container name or ID **RETURN DATA** A dictionary will be returned, containing the following keys: - ``status`` - A dictionary showing the prior state of the container as well as the new state - ``result`` - A boolean noting whet...
Stops a running container name Container name or ID unpause : False If ``True`` and the container is paused, it will be unpaused before attempting to stop the container. timeout Timeout in seconds after which the container will be killed (if it has not yet graceful...
def stop(name, timeout=None, **kwargs): ''' Stops a running container name Container name or ID unpause : False If ``True`` and the container is paused, it will be unpaused before attempting to stop the container. timeout Timeout in seconds after which the containe...
Unpauses a container name Container name or ID **RETURN DATA** A dictionary will be returned, containing the following keys: - ``status`` - A dictionary showing the prior state of the container as well as the new state - ``result`` - A boolean noting whether or not the action was ...
def unpause(name): ''' Unpauses a container name Container name or ID **RETURN DATA** A dictionary will be returned, containing the following keys: - ``status`` - A dictionary showing the prior state of the container as well as the new state - ``result`` - A boolean noting...
Wait for the container to exit gracefully, and return its exit code .. note:: This function will block until the container is stopped. name Container name or ID ignore_already_stopped Boolean flag that prevents execution to fail, if a container is already stopped. fa...
def wait(name, ignore_already_stopped=False, fail_on_exit_status=False): ''' Wait for the container to exit gracefully, and return its exit code .. note:: This function will block until the container is stopped. name Container name or ID ignore_already_stopped Boolean fla...
.. versionadded:: 2019.2.0 Prune Docker's various subsystems .. note:: This requires docker-py version 2.1.0 or later. containers : False If ``True``, prunes stopped containers (documentation__) .. __: https://docs.docker.com/engine/reference/commandline/container_prune/#filterin...
def prune(containers=False, networks=False, images=False, build=False, volumes=False, system=None, **filters): ''' .. versionadded:: 2019.2.0 Prune Docker's various subsystems .. note:: This requires docker-py version 2.1.0 or later. containers : False If ``True``, prune...
Common logic for docker.run functions
def _run(name, cmd, exec_driver=None, output=None, stdin=None, python_shell=True, output_loglevel='debug', ignore_retcode=False, use_vt=False, keep_env=None): ''' Common logic for docker.run functions ''' if exec_driver is ...
Common logic to run a script on a container
def _script(name, source, saltenv='base', args=None, template=None, exec_driver=None, stdin=None, python_shell=True, output_loglevel='debug', ignore_retcode=False, use_vt=False, keep_env=N...
Run :py:func:`cmd.script <salt.modules.cmdmod.script>` within a container .. note:: While the command is run within the container, it is initiated from the host. Therefore, the PID in the return dict is from the host, not from the container. name Container name or ID sour...
def script(name, source, saltenv='base', args=None, template=None, exec_driver=None, stdin=None, python_shell=True, output_loglevel='debug', ignore_retcode=False, use_vt=False, keep_env=None): ''...
Prepares a self contained tarball that has the state to be applied in the container
def _prepare_trans_tar(name, sls_opts, mods=None, pillar=None, extra_filerefs=''): ''' Prepares a self contained tarball that has the state to be applied in the container ''' chunks = _compile_state(sls_opts, mods) # reuse it from salt.ssh, however this function should ...
Generates the chunks of lowdata from the list of modules
def _compile_state(sls_opts, mods=None): ''' Generates the chunks of lowdata from the list of modules ''' st_ = HighState(sls_opts) if not mods: return st_.compile_low_chunks() high_data, errors = st_.render_highstate({sls_opts['saltenv']: mods}) high_data, ext_errors = st_.state.r...
Executes a Salt function inside a running container .. versionadded:: 2016.11.0 The container does not need to have Salt installed, but Python is required. name Container name or ID function Salt execution module function CLI Example: .. code-block:: bash salt mymi...
def call(name, function, *args, **kwargs): ''' Executes a Salt function inside a running container .. versionadded:: 2016.11.0 The container does not need to have Salt installed, but Python is required. name Container name or ID function Salt execution module function CL...
.. versionadded:: 2019.2.0 Apply states! This function will call highstate or state.sls based on the arguments passed in, ``apply`` is intended to be the main gateway for all state executions. CLI Example: .. code-block:: bash salt 'docker' docker.apply web01 salt 'docker' docker...
def apply_(name, mods=None, **kwargs): ''' .. versionadded:: 2019.2.0 Apply states! This function will call highstate or state.sls based on the arguments passed in, ``apply`` is intended to be the main gateway for all state executions. CLI Example: .. code-block:: bash salt 'dock...
Apply the states defined by the specified SLS modules to the running container .. versionadded:: 2016.11.0 The container does not need to have Salt installed, but Python is required. name Container name or ID mods : None A string containing comma-separated list of SLS with define...
def sls(name, mods=None, **kwargs): ''' Apply the states defined by the specified SLS modules to the running container .. versionadded:: 2016.11.0 The container does not need to have Salt installed, but Python is required. name Container name or ID mods : None A string co...
.. versionchanged:: 2018.3.0 The repository and tag must now be passed separately using the ``repository`` and ``tag`` arguments, rather than together in the (now deprecated) ``image`` argument. Build a Docker image using the specified SLS modules on top of base image .. versionadded::...
def sls_build(repository, tag='latest', base='opensuse/python', mods=None, dryrun=False, **kwargs): ''' .. versionchanged:: 2018.3.0 The repository and tag must now be passed separately using the ``repository`` and ``tag`` arg...
Checks whether the input is a valid list of peers and transforms domain names into IP Addresses
def _check(peers): '''Checks whether the input is a valid list of peers and transforms domain names into IP Addresses''' if not isinstance(peers, list): return False for peer in peers: if not isinstance(peer, six.string_types): return False if not HAS_NETADDR: # if does ...
Manages the configuration of NTP peers and servers on the device, as specified in the state SLS file. NTP entities not specified in these lists will be removed whilst entities not configured on the device will be set. SLS Example: .. code-block:: yaml netntp_example: netntp.managed: ...
def managed(name, peers=None, servers=None): ''' Manages the configuration of NTP peers and servers on the device, as specified in the state SLS file. NTP entities not specified in these lists will be removed whilst entities not configured on the device will be set. SLS Example: .. code-block:: y...
Add a virtual service. protocol The service protocol(only support tcp, udp and fwmark service). service_address The LVS service address. scheduler Algorithm for allocating TCP connections and UDP datagrams to real servers. CLI Example: .. code-block:: bash salt...
def add_service(protocol=None, service_address=None, scheduler='wlc'): ''' Add a virtual service. protocol The service protocol(only support tcp, udp and fwmark service). service_address The LVS service address. scheduler Algorithm for allocating TCP connections and UDP da...
Ensure the kinesis stream is properly configured and scaled. name (string) Stream name retention_hours (int) Retain data for this many hours. AWS allows minimum 24 hours, maximum 168 hours. enhanced_monitoring (list of string) Turn on enhanced monitoring for the specified ...
def present(name, retention_hours=None, enhanced_monitoring=None, num_shards=None, do_reshard=True, region=None, key=None, keyid=None, profile=None): ''' Ensure the kinesis stream is properly configured and scaled. ...
Return information for the specified user CLI Example: .. code-block:: bash salt '*' shadow.info someuser
def info(name): ''' Return information for the specified user CLI Example: .. code-block:: bash salt '*' shadow.info someuser ''' try: data = pwd.getpwnam(name) ret = { 'name': data.pw_name, 'passwd': data.pw_passwd} except KeyError: ...
Sets the time at which the password expires (in seconds since the UNIX epoch). See ``man 8 usermod`` on NetBSD and OpenBSD or ``man 8 pw`` on FreeBSD. A value of ``0`` sets the password to never expire. CLI Example: .. code-block:: bash salt '*' shadow.set_change username 1419980400
def set_change(name, change): ''' Sets the time at which the password expires (in seconds since the UNIX epoch). See ``man 8 usermod`` on NetBSD and OpenBSD or ``man 8 pw`` on FreeBSD. A value of ``0`` sets the password to never expire. CLI Example: .. code-block:: bash salt '*' ...
Sets the time at which the account expires (in seconds since the UNIX epoch). See ``man 8 usermod`` on NetBSD and OpenBSD or ``man 8 pw`` on FreeBSD. A value of ``0`` sets the account to never expire. CLI Example: .. code-block:: bash salt '*' shadow.set_expire username 1419980400
def set_expire(name, expire): ''' Sets the time at which the account expires (in seconds since the UNIX epoch). See ``man 8 usermod`` on NetBSD and OpenBSD or ``man 8 pw`` on FreeBSD. A value of ``0`` sets the account to never expire. CLI Example: .. code-block:: bash salt '*' sh...
Set the password for a named user. The password must be a properly defined hash. The password hash can be generated with this command: ``python -c "import crypt; print crypt.crypt('password', ciphersalt)"`` .. note:: When constructing the ``ciphersalt`` string, you must escape any dollar s...
def set_password(name, password): ''' Set the password for a named user. The password must be a properly defined hash. The password hash can be generated with this command: ``python -c "import crypt; print crypt.crypt('password', ciphersalt)"`` .. note:: When constructing the ``ciphersalt`...
Check the token, returns a 401 if the token is invalid. Else open the websocket connection
def get(self, token): ''' Check the token, returns a 401 if the token is invalid. Else open the websocket connection ''' log.debug('In the websocket get method') self.token = token # close the connection, if not authenticated if not self.application.auth....
Listens for a "websocket client ready" message. Once that message is received an asynchronous job is stated that yields messages to the client. These messages make up salt's "real time" event stream.
def on_message(self, message): """Listens for a "websocket client ready" message. Once that message is received an asynchronous job is stated that yields messages to the client. These messages make up salt's "real time" event stream. """ log.debug('Got websocket m...
If cors is enabled, check that the origin is allowed
def check_origin(self, origin): """ If cors is enabled, check that the origin is allowed """ mod_opts = self.application.mod_opts if mod_opts.get('cors_origin'): return bool(_check_cors_origin(origin, mod_opts['cors_origin'])) else: return super(...
Listens for a "websocket client ready" message. Once that message is received an asynchronous job is stated that yields messages to the client. These messages make up salt's "real time" event stream.
def on_message(self, message): """Listens for a "websocket client ready" message. Once that message is received an asynchronous job is stated that yields messages to the client. These messages make up salt's "real time" event stream. """ log.debug('Got websocket m...
Return supervisorctl command to call, either from a virtualenv, an argument passed in, or from the global modules options
def _get_supervisorctl_bin(bin_env): ''' Return supervisorctl command to call, either from a virtualenv, an argument passed in, or from the global modules options ''' cmd = 'supervisorctl' if not bin_env: which_result = __salt__['cmd.which_bin']([cmd]) if which_result is None: ...
Return the command list to use
def _ctl_cmd(cmd, name, conf_file, bin_env): ''' Return the command list to use ''' ret = [_get_supervisorctl_bin(bin_env)] if conf_file is not None: ret += ['-c', conf_file] ret.append(cmd) if name: ret.append(name) return ret
Start the named service. Process group names should not include a trailing asterisk. user user to run supervisorctl as conf_file path to supervisord config file bin_env path to supervisorctl bin or path to virtualenv with supervisor installed CLI Example: .. co...
def start(name='all', user=None, conf_file=None, bin_env=None): ''' Start the named service. Process group names should not include a trailing asterisk. user user to run supervisorctl as conf_file path to supervisord config file bin_env path to supervisorctl bin or path ...
Reload the daemon's configuration files user user to run supervisorctl as conf_file path to supervisord config file bin_env path to supervisorctl bin or path to virtualenv with supervisor installed CLI Example: .. code-block:: bash salt '*' supervisord.rer...
def reread(user=None, conf_file=None, bin_env=None): ''' Reload the daemon's configuration files user user to run supervisorctl as conf_file path to supervisord config file bin_env path to supervisorctl bin or path to virtualenv with supervisor installed CLI Exa...
Reload config and add/remove/update as necessary user user to run supervisorctl as conf_file path to supervisord config file bin_env path to supervisorctl bin or path to virtualenv with supervisor installed name name of the process group to update. if none then u...
def update(user=None, conf_file=None, bin_env=None, name=None): ''' Reload config and add/remove/update as necessary user user to run supervisorctl as conf_file path to supervisord config file bin_env path to supervisorctl bin or path to virtualenv with supervisor in...
List programs and its state user user to run supervisorctl as conf_file path to supervisord config file bin_env path to supervisorctl bin or path to virtualenv with supervisor installed CLI Example: .. code-block:: bash salt '*' supervisord.status
def status(name=None, user=None, conf_file=None, bin_env=None): ''' List programs and its state user user to run supervisorctl as conf_file path to supervisord config file bin_env path to supervisorctl bin or path to virtualenv with supervisor installed CLI Exam...
Display the raw output of status user user to run supervisorctl as conf_file path to supervisord config file bin_env path to supervisorctl bin or path to virtualenv with supervisor installed CLI Example: .. code-block:: bash salt '*' supervisord.status_raw
def status_raw(name=None, user=None, conf_file=None, bin_env=None): ''' Display the raw output of status user user to run supervisorctl as conf_file path to supervisord config file bin_env path to supervisorctl bin or path to virtualenv with supervisor installed ...
Run any custom supervisord command user user to run supervisorctl as conf_file path to supervisord config file bin_env path to supervisorctl bin or path to virtualenv with supervisor installed CLI Example: .. code-block:: bash salt '*' supervisord.custom "...
def custom(command, user=None, conf_file=None, bin_env=None): ''' Run any custom supervisord command user user to run supervisorctl as conf_file path to supervisord config file bin_env path to supervisorctl bin or path to virtualenv with supervisor installed CLI...
Reads the config file using configparser
def _read_config(conf_file=None): ''' Reads the config file using configparser ''' if conf_file is None: paths = ('/etc/supervisor/supervisord.conf', '/etc/supervisord.conf') for path in paths: if os.path.exists(path): conf_file = path break ...
.. versionadded:: 2014.1.0 Read the config file and return the config options for a given process name Name of the configured process conf_file path to supervisord config file CLI Example: .. code-block:: bash salt '*' supervisord.options foo
def options(name, conf_file=None): ''' .. versionadded:: 2014.1.0 Read the config file and return the config options for a given process name Name of the configured process conf_file path to supervisord config file CLI Example: .. code-block:: bash salt '*' super...