Exemplo n.º 1
0
    def handle(self, *args, **options):
        if len(args) < 1:
            print("USAGE: %s <model> <object id> [.. <object id>]" %
                  sys.argv[0])
            sys.exit(1)
        m = args[0].replace("-", "_")
        connect()
        if m not in self.models:
            raise CommandError("Invalid model '%s'. Valid models are: %s" %
                               (m, ", ".join(self.models)))
        objects = []
        getter = getattr(self, "get_%s" % m)
        wiper = getattr(self, "wipe_%s" % m)
        # Get objects
        for o_id in args[1:]:
            o = getter(o_id)
            if not o:  # Not found
                raise CommandError("Object '%s' is not found" % o_id)
            objects += [o]
        # Wipe objects
        from noc.core.debug import error_report

        with bulk_datastream_changes():
            for o in objects:
                with self.log("Wiping '%s':" % unicode(o), True):
                    try:
                        wiper(o)
                    except KeyboardInterrupt:
                        raise CommandError(
                            "Interrupted. Wiping is not complete")
                    except Exception:
                        error_report()
Exemplo n.º 2
0
 def handler(self, **kwargs):
     with Span(sample=self.object.periodic_telemetry_sample), bulk_datastream_changes():
         if self.object.auth_profile and self.object.auth_profile.type == "S":
             self.logger.info("Invalid credentials. Stopping")
             return
         ResolverCheck(self).run()
         if self.allow_sessions():
             self.logger.debug("Using CLI sessions")
             with self.object.open_session():
                 self.run_checks()
         else:
             self.run_checks()
Exemplo n.º 3
0
 def handler(self, **kwargs):
     with Span(sample=self.object.box_telemetry_sample), bulk_datastream_changes():
         has_cli = "C" in self.object.get_access_preference()
         ResolverCheck(self).run()
         if self.object.auth_profile and self.object.auth_profile.enable_suggest:
             SuggestSNMPCheck(self).run()
         if self.object.object_profile.enable_box_discovery_profile:
             ProfileCheck(self).run()
         if has_cli and self.object.auth_profile and self.object.auth_profile.enable_suggest:
             SuggestCLICheck(self).run()
             if self.object.auth_profile and self.object.auth_profile.enable_suggest:
                 # Still suggest
                 self.logger.info(
                     "Cannot choose valid credentials. Stopping"
                 )
                 return
         # Run remaining checks
         if has_cli and self.allow_sessions():
             self.logger.debug("Using CLI sessions")
             with self.object.open_session():
                 self.run_checks()
         else:
             self.run_checks()