summaryrefslogtreecommitdiffstats
path: root/LabController/cron.daily/expire_distros
blob: 66fb6c2e813165d6b67a2b5ab427d39d515ec228 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/python

import sys, os
import xmlrpclib
from datetime import datetime
from datetime import timedelta
import cobbler.api as capi

if __name__ == '__main__':
    expiredelta = datetime.now() + timedelta(weeks=-1)
    bootapi = capi.BootAPI()
    settings = bootapi.settings()
    inventory = xmlrpclib.ServerProxy('%s/RPC2' % settings.redhat_management_server, allow_none=True)
    distros = bootapi.distros()
    rdistros = []
    for distro in distros:
        if not os.path.exists(distro.kernel):
            bootapi.remove_distro(distro, recursive=True)
            rdistros.append(distro.name)
            continue
        if 'tree' in distro.ks_meta:
            if distro.ks_meta['tree'].find('nightly') == -1:
                continue
            distro_timestamp = datetime.fromtimestamp(float(distro.tree_build_time))
            if distro_timestamp < expiredelta:
                bootapi.remove_distro(distro, recursive=True)
                rdistros.append(distro.name)
    inventory.labcontrollers.removeDistros(settings.server, rdistros)