1 ##############################################################################
2 # Copyright (c) 2016 Max Breitenfeldt and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 from django.db import models
12 from django.utils import timezone
15 class JenkinsSlave(models.Model):
16 id = models.AutoField(primary_key=True)
17 name = models.CharField(max_length=100, unique=True)
18 status = models.CharField(max_length=30, default='offline')
19 url = models.CharField(max_length=1024)
20 ci_slave = models.BooleanField(default=False)
21 dev_pod = models.BooleanField(default=False)
23 building = models.BooleanField(default=False)
25 last_job_name = models.CharField(max_length=1024, default='')
26 last_job_url = models.CharField(max_length=1024, default='')
27 last_job_scenario = models.CharField(max_length=50, default='')
28 last_job_branch = models.CharField(max_length=50, default='')
29 last_job_installer = models.CharField(max_length=50, default='')
30 last_job_result = models.CharField(max_length=30, default='')
32 active = models.BooleanField(default=False)
34 def get_utilization(self, timedelta):
36 Return a dictionary containing the count of idle, online and offline measurements in the time from
39 utilization = {'idle': 0, 'online': 0, 'offline': 0}
40 statistics = self.jenkinsstatistic_set.filter(timestamp__gte=timezone.now() - timedelta)
41 utilization['idle'] = statistics.filter(idle=True).count()
42 utilization['online'] = statistics.filter(online=True).count()
43 utilization['offline'] = statistics.filter(offline=True).count()
47 db_table = 'jenkins_slave'
53 class JenkinsStatistic(models.Model):
54 id = models.AutoField(primary_key=True)
55 slave = models.ForeignKey(JenkinsSlave, on_delete=models.CASCADE)
56 offline = models.BooleanField(default=False)
57 idle = models.BooleanField(default=False)
58 online = models.BooleanField(default=False)
59 timestamp = models.DateTimeField(auto_now_add=True)
62 db_table = 'jenkins_statistic'