def due(self, name, schedulers, fields): schedulers = [ s.strip() for s in list(csv.reader(StringIO(schedulers)))[0] ] backy = self.backy() versions = backy.ls() if not name: names = set([v.name for v in versions]) else: names = [name] due_backups = {} # name: list of tags for name in names: _due_schedulers = set() _due_backup_expire_date = datetime.utcnow() _due_backup_due_since = datetime.utcnow() for scheduler in schedulers: interval = convert_to_timedelta( self.Config(section=scheduler).get('interval')) keep = self.Config(section=scheduler).getint('keep') sla = convert_to_timedelta( self.Config(section=scheduler).get('sla')) _due_backup = backy.get_due_backups(name, scheduler, interval, keep, sla) # True/False if _due_backup: _due_schedulers.add(scheduler) _due_backup_expire_date = max( _due_backup_expire_date, datetime.utcnow() + (keep + 1) * interval) _due_backup_due_since = min(_due_backup_due_since, _due_backup) if _due_schedulers: due_backups[name] = { 'schedulers': _due_schedulers, 'due_backup_expire_date': _due_backup_expire_date, 'due_backup_since': _due_backup_due_since, } field_names = [ f.strip() for f in list(csv.reader(StringIO(fields)))[0] ] values = [] for name, backup_info in due_backups.items(): values.append({ 'name': name, 'schedulers': ",".join(backup_info['schedulers']), 'expire_date': backup_info['due_backup_expire_date'], 'due_since': backup_info['due_backup_since'], }) values.sort(key=lambda v: v['due_since']) if self.machine_output: self._machine_output(field_names, values) else: self._tbl_output(field_names, values, alignments={ 'name': 'l', 'schedulers': 'l' })
def sla(self, name, schedulers, fields): schedulers = [ s.strip() for s in list(csv.reader(StringIO(schedulers)))[0] ] backy = self.backy() versions = backy.ls() if not name: names = set([v.name for v in versions]) else: names = [name] sla_breaches = {} # name: list of breaches for name in names: for scheduler in schedulers: interval = convert_to_timedelta( self.Config(section=scheduler).get('interval')) keep = self.Config(section=scheduler).getint('keep') sla = convert_to_timedelta( self.Config(section=scheduler).get('sla')) _sla_breaches = backy.get_sla_breaches(name, scheduler, interval, keep, sla) # list of strings sla_breaches.setdefault(name, []).extend(_sla_breaches) field_names = [ f.strip() for f in list(csv.reader(StringIO(fields)))[0] ] values = [] for name, breaches in sla_breaches.items(): for breach in breaches: values.append({'name': name, 'breach': breach}) if self.machine_output: self._machine_output(field_names, values) else: self._tbl_output(field_names, values, alignments={ 'name': 'l', 'breach': 'l' })