Example #1
0
    def _update_probe(self, probe):
        old_probes = {probe.mode: probe for probe in self.probes}

        new_probes = []
        add = probe.get("add")
        if add:
            new_probes.extend(add)
        upd = probe.get("upd")
        if upd:
            new_probes.extend(upd)
        # There can only be one probe of the same mode
        # Dedup new probes based on mode
        new_probes = {probe["mode"]: probe for probe in new_probes}

        probes = []
        for key in new_probes:
            probe = new_probes[key]
            old_probe = old_probes.get(probe["mode"])
            if not old_probe:
                # create new probe
                probe["probe_id"] = make_uuid()
                probe["service_id"] = self.component.component_id
                probes.append(ServiceProbe(**probe))
                continue
            # update probe
            probe = ServiceProbe(**probe)
            probe.ID = old_probe.ID
            probe.service_id = self.component.component_id
            probes.append(probe)
        self.probes = probes
        self.update_action_type(ActionType.UPDATE.value)
Example #2
0
 def __save_service_probes(self, service, service_probes):
     service_probe_list = []
     for probe in service_probes:
         probe.pop("ID")
         new_service_probe = ServiceProbe(**probe)
         new_service_probe.service_id = service.service_id
         service_probe_list.append(new_service_probe)
     if service_probe_list:
         ServiceProbe.objects.bulk_create(service_probe_list)
Example #3
0
 def _update_probe(self, probe):
     add = probe.get("add")
     if add:
         add["probe_id"] = make_uuid()
         self.probe = ServiceProbe(**add)
         self.probe.service_id = self.component.component_id
     upd = probe.get("upd", None)
     if upd:
         probe = ServiceProbe(**upd)
         probe.ID = self.probe.ID
         probe.service_id = self.probe.service_id
         self.probe = probe