summaryrefslogtreecommitdiff
path: root/src/automationstatus/crons.py
diff options
context:
space:
mode:
authorckonstanski <kostcarl@isu.edu>2026-07-30 18:17:14 -0600
committerckonstanski <kostcarl@isu.edu>2026-07-30 18:17:14 -0600
commit640ff61422bc0ee3966941b93d9889ddbbd38d77 (patch)
treeabf1c08f5d38ee53ec8b29dc4f425722517505e6 /src/automationstatus/crons.py
parent22dae02a86c1fce71091bfa5289cf99abba1b217 (diff)
more filesHEADmaster
Diffstat (limited to 'src/automationstatus/crons.py')
-rw-r--r--src/automationstatus/crons.py151
1 files changed, 151 insertions, 0 deletions
diff --git a/src/automationstatus/crons.py b/src/automationstatus/crons.py
new file mode 100644
index 0000000..da1d59d
--- /dev/null
+++ b/src/automationstatus/crons.py
@@ -0,0 +1,151 @@
+from .models import DeploymentWorkflow, Summary
+from .models import OrchestrationWorkflow
+from datetime import datetime
+from django.apps import apps
+from django.db import connection
+from django.core import serializers
+from django.utils import timezone
+
+
+def count():
+ queryset = DeploymentWorkflow.objects.all()
+
+ in_progress_clusters = 0
+ failed_clusters = 0
+ completed_clusters = 0
+ ingested = 0
+ online = 0
+ bmc = 0
+ firmware_scheduled = 0
+ firmware_upgraded = 0
+ wr_scheduled = 0
+ wr_installed = 0
+
+ for workflow in queryset:
+ if workflow.wr_installed:
+ completed_clusters = completed_clusters + 1
+ else:
+ in_progress_clusters = in_progress_clusters + 1
+ # summary.failed = failed_clusters
+
+ if workflow.ingested:
+ ingested = ingested + 1
+
+ if workflow.online:
+ online = online + 1
+
+ if workflow.bmc:
+ bmc = bmc + 1
+
+ if workflow.firmware_scheduled and not workflow.firmware_upgraded:
+ firmware_scheduled = firmware_scheduled + 1
+
+ if workflow.firmware_upgraded:
+ firmware_upgraded = firmware_upgraded + 1
+
+ if workflow.wr_scheduled and not workflow.wr_installed:
+ wr_scheduled = wr_scheduled + 1
+
+ if workflow.wr_installed:
+ wr_installed = wr_installed + 1
+
+
+ summary = Summary()
+ summary.clusters = len(queryset)
+ summary.in_progress = in_progress_clusters
+ summary.completed = completed_clusters
+ summary.ingested = ingested
+ summary.online = online
+ summary.bmc = bmc
+ summary.firmware_scheduled = firmware_scheduled
+ summary.firmware_upgraded = firmware_upgraded
+ summary.wr_scheduled = wr_scheduled
+ summary.wr_installed = wr_installed
+ summary.created_at = timezone.now()
+ print(summary)
+ try:
+ summary.save()
+ except Exception as e:
+ print(e)
+
+
+def summary():
+ print("**** running cron: summary **** : {}".format(datetime.now()))
+ servers = apps.get_model('caas', 'Server')
+ query_set = servers.objects.select_related('cluster').select_related('blade')
+ for server in query_set:
+ # Set server id and date
+ status = DeploymentWorkflow()
+ status.cluster = server.cluster
+ status.created_at = timezone.now()
+ # CIQ ingestion
+ status.ingested = True
+ # Server online check
+ status.online = True if server.blade_id else False
+ #BMC done check
+ if server.pxe_mac_address and server.intel_nic_firmware_version:
+ status.bmc = True
+ # Check Firmware schedule and installation status
+ # Get server list from
+ Server = apps.get_model('caas', 'Server')
+ server = Server.objects.get(cluster=server.cluster)
+ FirmwareUpgradeSchedule = apps.get_model('caas', 'FirmwareUpgradeSchedule')
+ try:
+ firmware_schedule = FirmwareUpgradeSchedule.objects.get(server=server)
+ # Firmware installation Scheduled and completiong check
+ status.firmware_scheduled = True if firmware_schedule.date_scheduled else False
+ status.firmware_upgraded = True if firmware_schedule.date_completed else False
+ except FirmwareUpgradeSchedule.DoesNotExist:
+ status.firmware_schedule = False
+ status.firmware_upgraded = False
+ except Exception as e:
+ print(e)
+
+ # Check WindRiver schedule and installation status
+ WrInstallSchedule = apps.get_model('caas', 'WrInstallSchedule')
+ try:
+ wr_schedule = WrInstallSchedule.objects.select_related('cluster').get(cluster=server.cluster)
+ # WindRiver installation Scheduled and completiong check
+ status.wr_scheduled = True if wr_schedule.date_scheduled else False
+ status.wr_installed = True if wr_schedule.date_completed else False
+ except WrInstallSchedule.DoesNotExist:
+ status.wr_scheduled = False
+ status.wr_installed = False
+ except Exception as e:
+ print(e)
+ # Save status object
+ status.save()
+ count()
+
+def orchestration_summary():
+ print("**** running cron: orchestration_summary **** : {}".format(datetime.now()))
+ regions = apps.get_model('orchestration', 'remoteregionsetup')
+ status = OrchestrationWorkflow()
+
+ # Namespace count and Timestamp
+ status.namespaces = regions.objects.count()
+ status.created_at = timezone.now()
+
+ # Service accounts
+ status.orch_service_account = regions.objects.filter(serviceaccount__in=['orchestration-sa', 'SVC-FE-Atlas']).count()
+ status.edge_eng_service_account = regions.objects.filter(serviceaccount='SVC-Edge-Eng').count() + regions.objects.filter(serviceaccount__contains='application-sa-').count()
+ status.samsung_service_account = regions.objects.filter(serviceaccount='samsung-sa').count()
+
+ # Orchestration Kubeconfigs
+ status.orch_kubeconfig = regions.objects.filter(serviceaccount__in=['orchestration-sa', 'SVC-FE-Atlas']).exclude(kubeconfig='').count()
+
+ # Edge engineering Kubeconfigs
+ status.edge_eng_kubeconfig = regions.objects.filter(serviceaccount='SVC-Edge-Eng').exclude(kubeconfig='').count()
+ status.edge_eng_kubeconfig += regions.objects.filter(serviceaccount__contains='application-sa-').exclude(kubeconfig='').count()
+
+ # Samsung Kubeconfigs
+ status.samsung_kubeconfig= regions.objects.filter(serviceaccount__in=['orchestration-sa', 'SVC-FE-Atlas']).exclude(kubeconfig='').count()
+
+ # Uncomment and use once Dev completes tracking on his side
+ # Setting to 0 for now
+ status.data_network_setup = 0
+
+ status.save()
+
+
+