def create(id: str, force_create: bool = False) -> T:
        ValueChecker.validate_id(id)

        period = None if force_create else ConfigBuilder.get_downtime(id)
        if None is period:
            period = ScheduledDowntime(id)
            ConfigBuilder.add_downtime(id, period)

        return period
Esempio n. 2
0
    def remove_downtime(self: T, downtime: Union[ScheduledDowntime, str]) -> T:
        if isinstance(downtime, ScheduledDowntime):
            if downtime in self.__downtimes:
                self.__downtimes.remove(downtime)
        elif isinstance(downtime, str):
            downtime = ConfigBuilder.get_downtime(downtime)
            if downtime in self.__downtimes:
                self.__downtimes.remove(downtime)

        return self
Esempio n. 3
0
    def add_downtime(self: T, downtime: Union[ScheduledDowntime, str]) -> T:
        if isinstance(downtime, ScheduledDowntime):
            if downtime not in self.__downtimes:
                self.__downtimes.append(downtime)
        elif isinstance(downtime, str):
            downtime = ConfigBuilder.get_downtime(downtime)
            if None is downtime:
                raise Exception('Downtime does not exist yet!')
            if downtime not in self.__downtimes:
                self.__downtimes.append(downtime)
        else:
            raise Exception('Can only add Downtime or id of Downtime!')

        return self