Esempio n. 1
0
 def setUp(self, mrapi):
     self.backend = mfactory.BackendFactory()
     log = logging.getLogger()
     options = {
         "fix_unsynced": True,
         "fix_stale": True,
         "fix_orphans": True,
         "fix_unsynced_nics": True,
         "fix_unsynced_flavors": True
     }
     self.reconciler = reconciliation.BackendReconciler(self.backend,
                                                        options=options,
                                                        logger=log)
Esempio n. 2
0
    def handle(self, **options):
        backend_id = options['backend-id']
        if backend_id:
            backends = [get_resource("backend", backend_id)]
        else:
            backends = reconciliation.get_online_backends()

        parallel = parse_bool(options["parallel"])
        if parallel and len(backends) > 1:
            cmd = sys.argv
            processes = []
            for backend in backends:
                p = subprocess.Popen(cmd + ["--backend-id=%s" % backend.id])
                processes.append(p)
            for p in processes:
                p.wait()
            return

        verbosity = int(options["verbosity"])

        logger = logging.getLogger("reconcile-servers")
        logger.propagate = 0

        formatter = logging.Formatter("%(message)s")
        log_handler = logging.StreamHandler()
        log_handler.setFormatter(formatter)
        if verbosity == 2:
            formatter =\
                logging.Formatter("%(asctime)s [%(process)d]: %(message)s")
            log_handler.setFormatter(formatter)
            logger.setLevel(logging.DEBUG)
        elif verbosity == 1:
            logger.setLevel(logging.INFO)
        else:
            logger.setLevel(logging.WARNING)

        logger.addHandler(log_handler)

        self._process_args(options)

        for backend in backends:
            r = reconciliation.BackendReconciler(backend=backend,
                                                 logger=logger,
                                                 options=options)
            r.reconcile()