diff options
Diffstat (limited to 'docker/api')
| -rw-r--r-- | docker/api/container.py | 3 | ||||
| -rw-r--r-- | docker/api/daemon.py | 18 | ||||
| -rw-r--r-- | docker/api/plugin.py | 37 | ||||
| -rw-r--r-- | docker/api/service.py | 50 |
4 files changed, 107 insertions, 1 deletions
diff --git a/docker/api/container.py b/docker/api/container.py index 453e378..4e7364b 100644 --- a/docker/api/container.py +++ b/docker/api/container.py @@ -498,6 +498,9 @@ class ContainerApiMixin(object): container, as a mapping of hostname to IP address. group_add (:py:class:`list`): List of additional group names and/or IDs that the container process will run as. + init (bool): Run an init inside the container that forwards + signals and reaps processes + init_path (str): Path to the docker-init binary ipc_mode (str): Set the IPC mode for the container. isolation (str): Isolation technology to use. Default: `None`. links (dict or list of tuples): Either a dictionary mapping name diff --git a/docker/api/daemon.py b/docker/api/daemon.py index d40631f..00367bc 100644 --- a/docker/api/daemon.py +++ b/docker/api/daemon.py @@ -7,6 +7,22 @@ from ..constants import INSECURE_REGISTRY_DEPRECATION_WARNING class DaemonApiMixin(object): + @utils.minimum_version('1.25') + def df(self): + """ + Get data usage information. + + Returns: + (dict): A dictionary representing different resource categories + and their respective data usage. + + Raises: + :py:class:`docker.errors.APIError` + If the server returns an error. + """ + url = self._url('/system/df') + return self._result(self._get(url), True) + def events(self, since=None, until=None, filters=None, decode=None): """ Get real-time events from the server. Similar to the ``docker events`` @@ -54,7 +70,7 @@ class DaemonApiMixin(object): } return self._stream_helper( - self.get(self._url('/events'), params=params, stream=True), + self._get(self._url('/events'), params=params, stream=True), decode=decode ) diff --git a/docker/api/plugin.py b/docker/api/plugin.py index 772d263..ba40c88 100644 --- a/docker/api/plugin.py +++ b/docker/api/plugin.py @@ -195,6 +195,7 @@ class PluginApiMixin(object): return self._stream_helper(res, decode=True) @utils.minimum_version('1.25') + @utils.check_resource def remove_plugin(self, name, force=False): """ Remove an installed plugin. @@ -212,3 +213,39 @@ class PluginApiMixin(object): res = self._delete(url, params={'force': force}) self._raise_for_status(res) return True + + @utils.minimum_version('1.26') + @utils.check_resource + def upgrade_plugin(self, name, remote, privileges): + """ + Upgrade an installed plugin. + + Args: + name (string): Name of the plugin to upgrade. The ``:latest`` + tag is optional and is the default if omitted. + remote (string): Remote reference to upgrade to. The + ``:latest`` tag is optional and is the default if omitted. + privileges (list): A list of privileges the user consents to + grant to the plugin. Can be retrieved using + :py:meth:`~plugin_privileges`. + + Returns: + An iterable object streaming the decoded API logs + """ + + url = self._url('/plugins/{0}/upgrade', name) + params = { + 'remote': remote, + } + + headers = {} + registry, repo_name = auth.resolve_repository_name(remote) + header = auth.get_config_header(self, registry) + if header: + headers['X-Registry-Auth'] = header + response = self._post_json( + url, params=params, headers=headers, data=privileges, + stream=True + ) + self._raise_for_status(response) + return self._stream_helper(response, decode=True) diff --git a/docker/api/service.py b/docker/api/service.py index 0b2abdc..4972c16 100644 --- a/docker/api/service.py +++ b/docker/api/service.py @@ -166,6 +166,56 @@ class ServiceApiMixin(object): url = self._url('/services') return self._result(self._get(url, params=params), True) + @utils.minimum_version('1.25') + @utils.check_resource + def service_logs(self, service, details=False, follow=False, stdout=False, + stderr=False, since=0, timestamps=False, tail='all', + is_tty=None): + """ + Get log stream for a service. + Note: This endpoint works only for services with the ``json-file`` + or ``journald`` logging drivers. + + Args: + service (str): ID or name of the service + details (bool): Show extra details provided to logs. + Default: ``False`` + follow (bool): Keep connection open to read logs as they are + sent by the Engine. Default: ``False`` + stdout (bool): Return logs from ``stdout``. Default: ``False`` + stderr (bool): Return logs from ``stderr``. Default: ``False`` + since (int): UNIX timestamp for the logs staring point. + Default: 0 + timestamps (bool): Add timestamps to every log line. + tail (string or int): Number of log lines to be returned, + counting from the current end of the logs. Specify an + integer or ``'all'`` to output all log lines. + Default: ``all`` + is_tty (bool): Whether the service's :py:class:`ContainerSpec` + enables the TTY option. If omitted, the method will query + the Engine for the information, causing an additional + roundtrip. + + Returns (generator): Logs for the service. + """ + params = { + 'details': details, + 'follow': follow, + 'stdout': stdout, + 'stderr': stderr, + 'since': since, + 'timestamps': timestamps, + 'tail': tail + } + + url = self._url('/services/{0}/logs', service) + res = self._get(url, params=params, stream=True) + if is_tty is None: + is_tty = self.inspect_service( + service + )['Spec']['TaskTemplate']['ContainerSpec'].get('TTY', False) + return self._get_result_tty(True, res, is_tty) + @utils.minimum_version('1.24') def tasks(self, filters=None): """ |
