import datetime from ..models import Cluster, WrInstallSchedule, WrBatch from django.conf import settings from .helpers import Address, Jinja from .ansibleservice import AnsibleService from .icingapollservice import IcingaPollService import logging logger = logging.getLogger("caas") class WrService(AnsibleService): """ target == ilo_host_address, later becomes cluster_name """ def __init__(self, target, git, branch, playbook, zmq): super().__init__("wr", target, git, branch, playbook, zmq) def schedule_install(self): logger.debug("%s Enter schedule_install" % self.target) try: wrbatch_kwargs = {"ilo_host_address": self.target} wrbatch = WrBatch.objects.get(**wrbatch_kwargs) except WrBatch.DoesNotExist: logger.error("FAILED: while scheduling Wind River installation: cannot find wrbatch with ilo_host_address: %s" % self.target) raise try: cluster_kwargs = {"pk": wrbatch.cluster_id} cluster = Cluster.objects.get(**cluster_kwargs) except Cluster.DoesNotExist: logger.error("FAILED: while scheduling Wind River installation: cannot find cluster associated with wrbatch with ilo_host_address: %s" % wrbatch.ilo_host_address) raise wr_kwargs = {"cluster_id": cluster.pk} wr, wr_created = WrInstallSchedule.objects.get_or_create(**wr_kwargs) if wr.date_scheduled is None: wr.date_scheduled = datetime.datetime.now() if wr.kirke_ticket_number is None: # TODO bealer: create KIRKE ticket pass wr.save() def deploy(self): kirke_inprocess_kwargs = {"kirke_ticket_number__isnull": False, "kirke_ticket_completed__isnull": True} kirke_inprocess = WrInstallSchedule.objects.filter(**kirke_inprocess_kwargs) for rec in kirke_inprocess: # TODO bealer: query KIRKE and update status rec.save() wr_schedule_kwargs = {"kirke_ticket_completed__isnull": False, "date_completed__isnull": True} wr_schedule_ready = WrInstallSchedule.objects.filter(**wr_schedule_kwargs) for sched in wr_schedule_ready: try: wrbatch_kwargs = {"cluster_id": sched.cluster.pk, "intel_nic_firmware_version": settings.INTEL_NIC_FIRMWARE_VERSION} wrbatch_results = WrBatch.objects.filter(**wrbatch_kwargs) except WrBatch.DoesNotExist: logger.error("FAILED: while running WR batch playbook: failed to look up wrbatch") raise # check hardware before wr isntall wrbatch = wrbatch_results[0] icingapoll = IcingaPollService(wrbatch.ilo_host_address, settings.ANSIBLE["icinga_poll"]["git"], settings.ANSIBLE["icinga_poll"]["branch"], settings.ANSIBLE["icinga_poll"]["playbook"], settings.ANSIBLE["icinga_poll"]["zmq"], "wrinstallnow") icingapoll.deploy()