Esempio n. 1
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from nuvla.job.base import main
from nuvla.job.executor import Executor

if __name__ == '__main__':
    main(Executor)
class NuvlaBoxStatusOfflineDistributor(Distributor):
    ACTION_NAME = 'update_nuvlabox_online'

    def __init__(self):
        super(NuvlaBoxStatusOfflineDistributor, self).__init__()
        self.collect_interval = 30

    @override
    def _get_jobs_type(self):
        return NuvlaBoxStatusOfflineDistributor.ACTION_NAME

    def collect_offline(self):
        filters = f"online = true and next-heartbeat < 'now'"
        select = 'id'
        last = 10000
        offline = self.api.search('nuvlabox-status', filter=filters, select=select, last=last)
        logging.info(f'Nuvlabox offline: {offline.count}')
        return offline.resources

    @override
    def job_generator(self):
        # we don't generate a job because it's a simple edit on each nuvlabox status
        for nuvlabox_status in self.collect_offline():
            self.api.edit(nuvlabox_status.id, {'online': False})
        return []


if __name__ == '__main__':
    main(NuvlaBoxStatusOfflineDistributor)
Esempio n. 3
0
    def job_exists(self, job):
        filters = "(state='QUEUED' or state='RUNNING')" \
                  " and action='{0}'" \
                  " and target-resource/href='{1}'"\
            .format(job['action'], job['target-resource']['href'])
        jobs = self.api.search('job', filter=filters, select='', last=0)
        return jobs.count > 0

    @override
    def job_generator(self):
        while True:
            for component_id in self.user_components():
                job = {
                    'action': self._get_jobs_type(),
                    'target-resource': {
                        'href': component_id
                    }
                }
                if self.job_exists(job):
                    continue
                yield job
            time.sleep(self.collect_interval)

    @override
    def _get_jobs_type(self):
        return self.ACTION_NAME


if __name__ == '__main__':
    main(ServiceImageStateJobsDistributor)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import time
from nuvla.job.base import main
from nuvla.job.distributor import Distributor
from nuvla.job.util import override


class CleanupJobsDistributor(Distributor):
    ACTION_NAME = 'cleanup_jobs'

    def __init__(self):
        super(CleanupJobsDistributor, self).__init__()
        self.collect_interval = 86400.0  # 1 day

    @override
    def job_generator(self):
        job = {'action': CleanupJobsDistributor.ACTION_NAME,
               'target-resource': {'href': 'job'}}
        yield job

    @override
    def _get_jobs_type(self):
        return CleanupJobsDistributor.ACTION_NAME


if __name__ == '__main__':
    main(CleanupJobsDistributor)
Esempio n. 5
0
from nuvla.job.base import main
from nuvla.job.distributor import Distributor
from nuvla.job.util import override


class NuvlaBoxClusterCleanupDistributor(Distributor):
    ACTION_NAME = 'nuvlabox_cluster_cleanup'

    def __init__(self):
        super(NuvlaBoxClusterCleanupDistributor, self).__init__()
        self.collect_interval = 86400.0  # 1 day
        self.exit_on_failure = True

    @override
    def job_generator(self):
        job = {
            'action': NuvlaBoxClusterCleanupDistributor.ACTION_NAME,
            'target-resource': {
                'href': 'job'
            }
        }
        yield job

    @override
    def _get_jobs_type(self):
        return NuvlaBoxClusterCleanupDistributor.ACTION_NAME


if __name__ == '__main__':
    main(NuvlaBoxClusterCleanupDistributor)
Esempio n. 6
0
from nuvla.job.base import main
from nuvla.job.distributor import Distributor
from nuvla.job.util import override


class VulnerabilitiesDatabaseDistributor(Distributor):
    ACTION_NAME = 'update_vulnerabilities_database'

    def __init__(self):
        super(VulnerabilitiesDatabaseDistributor, self).__init__()
        self.collect_interval = 86400.0  # 1 day
        self.exit_on_failure = True

    @override
    def job_generator(self):
        job = {
            'action': VulnerabilitiesDatabaseDistributor.ACTION_NAME,
            'target-resource': {
                'href': 'job'
            }
        }
        yield job

    @override
    def _get_jobs_type(self):
        return VulnerabilitiesDatabaseDistributor.ACTION_NAME


if __name__ == '__main__':
    main(VulnerabilitiesDatabaseDistributor)
                                                        " and state = 'STARTED'"
                                                        " and subscription-id != null",
                                   select='id,module').resources
        except Exception as ex:
            logging.error(f'Failed to search for deployments: {ex}')
            return []

    def job_exists(self, job):
        filters = f"(state='QUEUED' or state='RUNNING')" \
                  f" and action='{job['action']}'" \
                  f" and target-resource/href='{job['target-resource']['href']}'"
        jobs = self.api.search('job', filter=filters, select='', last=0)
        return jobs.count > 0

    @override
    def job_generator(self):
        for resource in self.customers() + self.deployments():
            job = {'action': self._get_jobs_type(),
                   'target-resource': {'href': resource.id}}
            if self.job_exists(job):
                continue
            yield job

    @override
    def _get_jobs_type(self):
        return self.ACTION_NAME


if __name__ == '__main__':
    main(UsageReportJobsDistributor)