From 640ff61422bc0ee3966941b93d9889ddbbd38d77 Mon Sep 17 00:00:00 2001 From: ckonstanski Date: Thu, 30 Jul 2026 18:17:14 -0600 Subject: more files --- src/caas/services/patchservice.py | 106 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/caas/services/patchservice.py (limited to 'src/caas/services/patchservice.py') diff --git a/src/caas/services/patchservice.py b/src/caas/services/patchservice.py new file mode 100644 index 0000000..c986051 --- /dev/null +++ b/src/caas/services/patchservice.py @@ -0,0 +1,106 @@ +import datetime +from ..models import Cluster, WrInstallSchedule, PatchSchedule, WrBatch +from django.conf import settings +from .helpers import Jinja +from .ansibleservice import AnsibleService + + +class PatchService(AnsibleService): + """ + target == ilo_host_address, later becomes cluster_name + """ + def __init__(self, target, git, branch, playbook, zmq): + super().__init__("patch", target, git, branch, playbook, zmq) + + def schedule_install(self): + pass + # try: + # patchbatch_kwargs = {"ilo_host_address": self.target} + # # repurpose WrBatch + # patchbatch = WrBatch.objects.get(**patchbatch_kwargs) + # except WrBatch.DoesNotExist: + # return "FAILED: while scheduling Wind River installation: cannot find wrbatch with ilo_host_address: %s" % self.target + # try: + # cluster_kwargs = {"pk": patchbatch.cluster_id} + # cluster = Cluster.objects.get(**cluster_kwargs) + # except Cluster.DoesNotExist: + # return "FAILED: while scheduling Wind River installation: cannot find cluster associated with wrbatch with ilo_host_address: %s" % patchbatch.ilo_host_address + # patch_kwargs = {"cluster_id": cluster.pk} + # patch, patch_created = PatchSchedule.objects.get_or_create(**patch_kwargs) + # if patch.date_scheduled is None: + # patch.date_scheduled = datetime.datetime.now() + # if patch.kirke_ticket_number is None: + # # TODO bealer: create KIRKE ticket + # pass + # patch.save() + # # one playbook per cluster + # self.target = cluster.cluster_name + # with tempfile.TemporaryDirectory() as tempdir: + # builddir = "%s/%s" % (tempdir, self.repo_name) + # self.clone_repo(builddir) + # # host_vars file + # patch_config = {"wr_vendor_name": patchbatch.vendor_name, + # "wr_region_name": cluster.cluster_name, + # "wr_central_p": False if patchbatch.parent_oam_vip_hostname else True, + # "wr_bmc_controller_0_address": patchbatch.ilo_host_address, + # "wr_mgmt_controller_0_mac": patchbatch.pxe_mac_address, + # "wr_oam_floating_address": patchbatch.oam_vip_address, + # "wr_oam_node_0_address": patchbatch.oam_host_address, + # "wr_oam_gateway_address": patchbatch.oam_default_gateway, + # "wr_mgmt_start_address": patchbatch.mgmt_address_range_start, + # "wr_mgmt_end_address": patchbatch.mgmt_address_range_end, + # "wr_mgmt_gateway_address": patchbatch.mgmt_default_gateway, + # "wr_mgmt_subnet": patchbatch.mgmt_subnet, + # "wr_central_mgmt_start_address": patchbatch.parent_mgmt_address_range_start, + # "wr_central_mgmt_default_gateway": patchbatch.parent_mgmt_default_gateway, + # "wr_host_vlan": patchbatch.host_vlan, + # "wr_oam_vlan": patchbatch.oam_vlan, + # "wr_mgmt_vlan": patchbatch.mgmt_vlan, + # "wr_bmc_username": patchbatch.bmc_username, + # "wr_bmc_password": patchbatch.bmc_password, + # "wr_dns_servers": settings.DNS_SERVERS, + # "wr_ntp_servers": settings.NTP_SERVERS, + # "wr_registry_server": settings.WR_REGISTRY_SERVER, + # "wr_registry_username": settings.WR_REGISTRY_USERNAME, + # "wr_registry_password": settings.WR_REGISTRY_PASSWORD, + # "wr_webdav_server": settings.WR_WEBDAV_SERVER, + # "wr_webdav_username": settings.WR_WEBDAV_USERNAME, + # "wr_webdav_password": settings.WR_WEBDAV_PASSWORD, + # "wr_docker_http_proxy": settings.WR_DOCKER_HTTP_PROXY, + # "wr_docker_https_proxy": settings.WR_DOCKER_HTTPS_PROXY, + # "wr_docker_no_proxy": settings.WR_DOCKER_NO_PROXY, + # "wr_ssl_ca_cert": settings.WR_SSL_CA_CERT} + # content = Jinja.render("patch_host_vars.j2", **patch_config) + # filename = "%s/host_vars/%s" % (builddir, patchbatch.oam_hostname) + # with AnsibleVaultFile(filename) as f: + # f.write(content) + # # inventory file + # patch_config = {"central_target": patchbatch.parent_cluster_name, + # "central_target_ip": patchbatch.parent_oam_vip_address, + # "remote_target": patchbatch.oam_hostname, + # "remote_target_ip": patchbatch.oam_vip_address} + # content = Jinja.render("patch_inventory.j2", **patch_config) + # filename = "%s/inventory/%s.yaml" % (builddir, cluster.cluster_name) + # with open(filename, "w") as f: + # f.write(content) + # self.push() + + def deploy(self): + pass + # kirke_inprocess = PatchSchedule.objects.filter(kirke_ticket_number__isnull = False, + # kirke_ticket_completed__isnull = True) + # for rec in kirke_inprocess: + # # TODO bealer: query KIRKE and update status + # rec.save() + # patch_schedule_kwargs = {"kirke_ticket_completed__isnull": False, + # "date_completed__isnull": True} + # patch_schedule_ready = PatchSchedule.objects.filter(**patch_schedule_kwargs) + # for sched in patch_schedule_ready: + # try: + # patchbatch_kwargs = {"cluster_id": sched.cluster.pk, + # "intel_nic_firmware_version": settings.INTEL_NIC_FIRMWARE_VERSION} + # patchbatch = WrBatch.objects.filter(**patchbatch_kwargs) + # except WrBatch.DoesNotExist: + # return "FAILED: while running PATCH batch playbook: failed to look up wrbatch" + # self.target = patchbatch.cluster_name + # self.run_playbook() -- cgit v1.3