def extra_hosts(self, value):
        """
        :param value:
        :return None:
        """
        if value is None:
            self._extra_hosts = value
        elif isinstance(value, list):
            # TODO: better validation
            self._extra_hosts = value
        elif isinstance(value, dict):
            converted_extra_hosts = []
            for k, v in sorted(six.iteritems(value)):
                if not is_valid_hostname(k):
                    raise ValueError(
                        "each key in extra hosts is required to be a valid hostname. {0} was passed"
                        .format(k))

                if not is_valid_ip(v):
                    raise ValueError(
                        "each value in extra hosts is required to be a valid ip address. {0} was passed"
                        .format(v))

                converted_extra_hosts.append('{0}:{1}'.format(k, v))

            self._extra_hosts = converted_extra_hosts
        else:
            raise TypeError(
                "extra hosts must be a dict, list, or None. {0} was passed".
                format(value))
    def hostname(self, hostname):
        """ hostname setter

        """
        if not isinstance(hostname, six.string_types):
            raise TypeError("hostname must be a string.  {0} was passed.".format(type(hostname)))

        # if a host name is passed and its not valid raise else set hostname empty strings are the docker default.
        if hostname and not is_valid_hostname(hostname):
            raise ValueError("{0} isn't a valid hostname").format(hostname)
        else:
            self._hostname = hostname
Exemple #3
0
    def hostname(self, hostname):
        """ hostname setter

        """
        if not isinstance(hostname, six.string_types):
            raise TypeError(
                "hostname must be a string.  {0} was passed.".format(
                    type(hostname)))

        # if a host name is passed and its not valid raise else set hostname empty strings are the docker default.
        if hostname and not is_valid_hostname(hostname):
            raise ValueError("{0} isn't a valid hostname").format(hostname)
        else:
            self._hostname = hostname
    def extra_hosts(self, value):
        """
        :param value:
        :return None:
        """
        if value is None:
            self._extra_hosts = value
        elif isinstance(value, list):
            # TODO: better validation
            self._extra_hosts = value
        elif isinstance(value, dict):
            converted_extra_hosts = []
            for k, v in sorted(six.iteritems(value)):
                if not is_valid_hostname(k):
                    raise ValueError("each key in extra hosts is required to be a valid hostname. {0} was passed".format(k))

                if not is_valid_ip(v):
                    raise ValueError("each value in extra hosts is required to be a valid ip address. {0} was passed".format(v))

                converted_extra_hosts.append('{0}:{1}'.format(k, v))

            self._extra_hosts = converted_extra_hosts
        else:
            raise TypeError("extra hosts must be a dict, list, or None. {0} was passed".format(value))