How to use the docker.errors.InvalidVersion function in docker

To help you get started, we’ve selected a few docker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github docker / docker-py / docker / api / volume.py View on Github external
"""
        Remove a volume. Similar to the ``docker volume rm`` command.

        Args:
            name (str): The volume's name
            force (bool): Force removal of volumes that were already removed
                out of band by the volume driver plugin.

        Raises:
            :py:class:`docker.errors.APIError`
                If volume failed to remove.
        """
        params = {}
        if force:
            if utils.version_lt(self._version, '1.25'):
                raise errors.InvalidVersion(
                    'force removal was introduced in API 1.25'
                )
            params = {'force': force}

        url = self._url('/volumes/{0}', name, params=params)
        resp = self._delete(url)
        self._raise_for_status(resp)
github docker / docker-py / docker / types / containers.py View on Github external
def __init__(
        self, version, image, command, hostname=None, user=None, detach=False,
        stdin_open=False, tty=False, ports=None, environment=None,
        volumes=None, network_disabled=False, entrypoint=None,
        working_dir=None, domainname=None, host_config=None, mac_address=None,
        labels=None, stop_signal=None, networking_config=None,
        healthcheck=None, stop_timeout=None, runtime=None
    ):

        if stop_timeout is not None and version_lt(version, '1.25'):
            raise errors.InvalidVersion(
                'stop_timeout was only introduced in API version 1.25'
            )

        if healthcheck is not None:
            if version_lt(version, '1.24'):
                raise errors.InvalidVersion(
                    'Health options were only introduced in API version 1.24'
                )

            if version_lt(version, '1.29') and 'StartPeriod' in healthcheck:
                raise errors.InvalidVersion(
                    'healthcheck start period was introduced in API '
                    'version 1.29'
                )

        if isinstance(command, six.string_types):
github docker / docker-py / docker / api / image.py View on Github external
data (binary): Image data to be loaded.
            quiet (boolean): Suppress progress details in response.

        Returns:
            (generator): Progress output as JSON objects. Only available for
                         API version >= 1.23

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        """
        params = {}

        if quiet is not None:
            if utils.version_lt(self._version, '1.23'):
                raise errors.InvalidVersion(
                    'quiet is not supported in API version < 1.23'
                )
            params['quiet'] = quiet

        res = self._post(
            self._url("/images/load"), data=data, params=params, stream=True
        )
        if utils.version_gte(self._version, '1.23'):
            return self._stream_helper(res, decode=True)

        self._raise_for_status(res)
github j-bennet / wharfee / wharfee / client.py View on Github external
    @if_exception_return(InvalidVersion, None)
    def volume_ls(self, *args, **kwargs):
        """
        List volumes. Equivalent of docker volume ls.
        :param kwargs:
        :return: Iterable.
        """
        quiet = kwargs.pop('quiet', False)

        kwargs = self._add_filters(kwargs)

        vdict = self.instance.volumes(**kwargs)
        result = vdict.get('Volumes', None)

        if result:
            if quiet:
                result = [volume['Name'] for volume in result]
github docker / docker-py / docker / types / containers.py View on Github external
self, version, image, command, hostname=None, user=None, detach=False,
        stdin_open=False, tty=False, ports=None, environment=None,
        volumes=None, network_disabled=False, entrypoint=None,
        working_dir=None, domainname=None, host_config=None, mac_address=None,
        labels=None, stop_signal=None, networking_config=None,
        healthcheck=None, stop_timeout=None, runtime=None
    ):

        if stop_timeout is not None and version_lt(version, '1.25'):
            raise errors.InvalidVersion(
                'stop_timeout was only introduced in API version 1.25'
            )

        if healthcheck is not None:
            if version_lt(version, '1.24'):
                raise errors.InvalidVersion(
                    'Health options were only introduced in API version 1.24'
                )

            if version_lt(version, '1.29') and 'StartPeriod' in healthcheck:
                raise errors.InvalidVersion(
                    'healthcheck start period was introduced in API '
                    'version 1.29'
                )

        if isinstance(command, six.string_types):
            command = split_command(command)

        if isinstance(entrypoint, six.string_types):
            entrypoint = split_command(entrypoint)

        if isinstance(environment, dict):
github docker / docker-py / docker / types / networks.py View on Github external
if aliases:
            self["Aliases"] = aliases

        if links:
            self["Links"] = normalize_links(links)

        ipam_config = {}
        if ipv4_address:
            ipam_config['IPv4Address'] = ipv4_address

        if ipv6_address:
            ipam_config['IPv6Address'] = ipv6_address

        if link_local_ips is not None:
            if version_lt(version, '1.24'):
                raise errors.InvalidVersion(
                    'link_local_ips is not supported for API version < 1.24'
                )
            ipam_config['LinkLocalIPs'] = link_local_ips

        if ipam_config:
            self['IPAMConfig'] = ipam_config
github docker / docker-py / docker / types / networks.py View on Github external
def __init__(self, version, aliases=None, links=None, ipv4_address=None,
                 ipv6_address=None, link_local_ips=None):
        if version_lt(version, '1.22'):
            raise errors.InvalidVersion(
                'Endpoint config is not supported for API version < 1.22'
            )

        if aliases:
            self["Aliases"] = aliases

        if links:
            self["Links"] = normalize_links(links)

        ipam_config = {}
        if ipv4_address:
            ipam_config['IPv4Address'] = ipv4_address

        if ipv6_address:
            ipam_config['IPv6Address'] = ipv6_address
github docker / docker-py / docker / types / containers.py View on Github external
def host_config_version_error(param, version, less_than=True):
    operator = '<' if less_than else '>'
    error_msg = '{0} param is not supported in API versions {1} {2}'
    return errors.InvalidVersion(error_msg.format(param, operator, version))
github docker / docker-py / docker / api / network.py View on Github external
ipam=ipam_config)
        """
        if options is not None and not isinstance(options, dict):
            raise TypeError('options must be a dictionary')

        data = {
            'Name': name,
            'Driver': driver,
            'Options': options,
            'IPAM': ipam,
            'CheckDuplicate': check_duplicate,
        }

        if labels is not None:
            if version_lt(self._version, '1.23'):
                raise InvalidVersion(
                    'network labels were introduced in API 1.23'
                )
            if not isinstance(labels, dict):
                raise TypeError('labels must be a dictionary')
            data["Labels"] = labels

        if enable_ipv6:
            if version_lt(self._version, '1.23'):
                raise InvalidVersion(
                    'enable_ipv6 was introduced in API 1.23'
                )
            data['EnableIPv6'] = True

        if internal:
            if version_lt(self._version, '1.22'):
                raise InvalidVersion('Internal networks are not '
github docker / docker-py / docker / api / network.py View on Github external
if internal:
            if version_lt(self._version, '1.22'):
                raise InvalidVersion('Internal networks are not '
                                     'supported in API version < 1.22')
            data['Internal'] = True

        if attachable is not None:
            if version_lt(self._version, '1.24'):
                raise InvalidVersion(
                    'attachable is not supported in API version < 1.24'
                )
            data['Attachable'] = attachable

        if ingress is not None:
            if version_lt(self._version, '1.29'):
                raise InvalidVersion(
                    'ingress is not supported in API version < 1.29'
                )

            data['Ingress'] = ingress

        if scope is not None:
            if version_lt(self._version, '1.30'):
                raise InvalidVersion(
                    'scope is not supported in API version < 1.30'
                )
            data['Scope'] = scope

        url = self._url("/networks/create")
        res = self._post_json(url, data=data)
        return self._result(res, json=True)