def submit(cls, object, chassis_mac=None, hostname=None, router_id=None, additional_macs=None): # Process ranges macs = cls._macs_as_ints(chassis_mac, additional_macs) ranges = cls._macs_to_ranges(macs) # Update database o = cls.objects.filter(object=object.id).first() if o: old_macs = set(m.first_mac for m in o.chassis_mac) o.chassis_mac = ranges o.hostname = hostname o.router_id = router_id old_macs -= set(m.first_mac for m in o.chassis_mac) if old_macs: cache.delete_many(["discoveryid-mac-%s" % m for m in old_macs]) # MAC index o.macs = macs o.save() else: cls(object=object, chassis_mac=ranges, hostname=hostname, router_id=router_id, macs=macs).save()
def on_save(self): from .managedobject import CREDENTIAL_CACHE_VERSION if not self.enable_suggest: cache.delete_many( [ "cred-%s" % x for x in self.managedobject_set.values_list("id", flat=True) ], version=CREDENTIAL_CACHE_VERSION, )
def on_save(self): from .managedobject import CREDENTIAL_CACHE_VERSION from noc.inv.models.link import Link box_changed = self.initial_data[ "enable_box_discovery"] != self.enable_box_discovery periodic_changed = (self.initial_data["enable_periodic_discovery"] != self.enable_periodic_discovery) access_changed = ( (self.initial_data["access_preference"] != self.access_preference) or (self.initial_data["cli_privilege_policy"] != self.cli_privilege_policy) or (self.initial_data["beef_storage"] != self.beef_storage) or (self.initial_data["beef_path_template"] != self.beef_path_template) or (self.initial_data["snmp_rate_limit"] != self.snmp_rate_limit)) if box_changed or periodic_changed: call_later( "noc.sa.models.managedobjectprofile.apply_discovery_jobs", profile_id=self.id, box_changed=box_changed, periodic_changed=periodic_changed, ) if access_changed: cache.delete_many( [ "cred-%s" % x for x in self.managedobject_set.values_list("id", flat=True) ], version=CREDENTIAL_CACHE_VERSION, ) if (self.initial_data["enable_rca_downlink_merge"] != self.enable_rca_downlink_merge or self.initial_data["rca_downlink_merge_window"] != self.rca_downlink_merge_window): for x in set( chain.from_iterable( Link.objects.filter(linked_objects__in=list( set( self.managedobject_set.values_list( "id", flat=True)))).scalar( "linked_segments"))): call_later("noc.core.topology.segment.update_uplinks", 60, segment_id=x)
def save(self, *args, **kwargs): from noc.core.cache.base import cache from noc.sa.models.managedobject import ManagedObject, MANAGEDOBJECT_CACHE_VERSION invalidate_mo_cache = ( not hasattr(self, "_changed_fields") or "alarm_consequence_policy" in self._changed_fields ) # After save changed_fields will be empty super().save(*args, **kwargs) # Invalidate ManagedObject cache if invalidate_mo_cache: deleted_cache_keys = [ "managedobject-id-%s" % mo_id for mo_id in ManagedObject.objects.filter(tt_system=self.id).values_list( "id", flat=True ) ] cache.delete_many(deleted_cache_keys, version=MANAGEDOBJECT_CACHE_VERSION)
def on_save(self): box_changed = self.initial_data["enable_box_discovery"] != self.enable_box_discovery periodic_changed = self.initial_data["enable_periodic_discovery"] != self.enable_periodic_discovery access_changed = ( (self.initial_data["access_preference"] != self.access_preference) or (self.initial_data["cli_privilege_policy"] != self.cli_privilege_policy) ) if box_changed or periodic_changed: call_later( "noc.sa.models.managedobjectprofile.apply_discovery_jobs", profile_id=self.id, box_changed=box_changed, periodic_changed=periodic_changed ) if access_changed: cache.delete_many([ "cred-%s" % x for x in self.managedobject_set.values_list("id", flat=True) ])
def invalidate_neighbor_cache(self, obj=None): """ Reset cached neighbors for object. NB: May be called by non-topology checks :param obj: Managed Object instance, jobs object if ommited :return: """ obj = obj or self.object if not obj.object_profile.neighbor_cache_ttl: # Disabled cache return keys = [ "mo-neighbors-%s-%s" % (x, obj.id) for x in obj.segment.profile.get_topology_methods() ] if keys: self.logger.info("Invalidating neighor cache: %s" % ", ".join(keys)) cache.delete_many(keys, TopologyDiscoveryCheck.NEIGHBOR_CACHE_VERSION)
def on_delete(self): # Reset cache macs = set(m.first_mac for m in self.chassis_mac) if macs: cache.delete_many(["discoveryid-mac-%s" % m for m in macs])
def on_save(self): if not self.enable_suggest: cache.delete_many([ "cred-%s" % x for x in self.managedobject_set.values_list("id", flat=True) ])