Example #1
0
    def _validate(self, value):
        super()._validate(value)

        try:
            valuespec.Hostname().validate_value(value, self.name)
        except MKUserError as e:
            raise self.make_error("invalid_name", host_name=value, invalid_reason=str(e))

        if self._should_exist is not None:
            host = watolib.Host.host(value)
            if self._should_exist and not host:
                raise self.make_error("should_exist", host_name=value)

            if not self._should_exist and host:
                raise self.make_error("should_not_exist", host_name=value)

        if self._should_be_cluster is not None:
            host = watolib.Host.host(value)
            if self._should_be_cluster and not host.is_cluster():
                raise self.make_error("should_be_cluster", host_name=value)

            if not self._should_be_cluster and host.is_cluster():
                raise self.make_error("should_not_be_cluster", host_name=value)

        if self._should_be_monitored is not None:
            monitored = host_is_monitored(value)
            if self._should_be_monitored and not monitored:
                raise self.make_error("should_be_monitored", host_name=value)

            if not self._should_be_monitored and monitored:
                raise self.make_error("should_not_be_monitored", host_name=value)
Example #2
0
    def _validate(self, value):
        super()._validate(value)

        host = watolib.Host.host(value)
        if self._should_exist and not host:
            self.fail("should_exist", host_name=value)
        elif not self._should_exist and host:
            self.fail("should_not_exist", host_name=value)

        try:
            valuespec.Hostname().validate_value(value, self.name)
        except MKUserError as e:
            self.fail("invalid_name", host_name=value, invalid_reason=str(e))