示例#1
0
    def _load_config(self):
        """Load Gauge config."""
        try:
            new_confs = watcher_parser(self.config_file, self.logname,
                                       self.prom_client)
        except InvalidConfigError as err:
            self.logger.error('invalid config: %s', err)
            return

        for old_watchers in self.watchers.values():
            self._stop_watchers(old_watchers)

        new_watchers = {}

        for conf in new_confs:
            watcher = watcher_factory(conf)(conf, self.logname,
                                            self.prom_client)
            watcher_dpid = watcher.dp.dp_id
            watcher_type = watcher.conf.type
            if watcher_dpid not in new_watchers:
                new_watchers[watcher_dpid] = {}
            if watcher_type not in new_watchers[watcher_dpid]:
                new_watchers[watcher_dpid][watcher_type] = []
            new_watchers[watcher_dpid][watcher_type].append(watcher)

        timestamp = time.time()
        for watcher_dpid, watchers in new_watchers.items():
            ryu_dp = self.dpset.get(watcher_dpid)
            if ryu_dp:
                self._start_watchers(ryu_dp, watchers, timestamp)

        self.watchers = new_watchers
        self.config_watcher.update(self.config_file)
        self.logger.info('config complete')
示例#2
0
    def _load_config(self):
        """Load Gauge config."""
        for watcher_dpid, old_watchers in list(self.watchers.items()):
            self._stop_watchers(watcher_dpid, old_watchers)

        new_confs = watcher_parser(self.config_file, self.logname, self.prom_client)
        new_watchers = {}

        for conf in new_confs:
            watcher = watcher_factory(conf)(conf, self.logname, self.prom_client)
            watcher_dpid = watcher.dp.dp_id
            watcher_type = watcher.conf.type
            if watcher_dpid not in new_watchers:
                new_watchers[watcher_dpid] = {}
            if watcher_type not in new_watchers[watcher_dpid]:
                new_watchers[watcher_dpid][watcher_type] = []
            new_watchers[watcher_dpid][watcher_type].append(watcher)

        for watcher_dpid, watchers in list(new_watchers.items()):
            ryu_dp = self.dpset.get(watcher_dpid)
            if ryu_dp:
                self._start_watchers(ryu_dp, watcher_dpid, watchers)

        self.watchers = new_watchers
        self.config_watcher.update(self.config_file)
        self.logger.info('config complete')
示例#3
0
文件: gauge.py 项目: anarkiwi/faucet
    def _load_config(self):
        """Load Gauge config."""
        try:
            new_confs = watcher_parser(self.config_file, self.logname, self.prom_client)
        except InvalidConfigError as err:
            self.logger.error('invalid config: %s', err)
            return

        for old_watchers in self.watchers.values():
            self._stop_watchers(old_watchers)

        new_watchers = {}

        for conf in new_confs:
            watcher = watcher_factory(conf)(conf, self.logname, self.prom_client)
            watcher_dpid = watcher.dp.dp_id
            watcher_type = watcher.conf.type
            if watcher_dpid not in new_watchers:
                new_watchers[watcher_dpid] = {}
            if watcher_type not in new_watchers[watcher_dpid]:
                new_watchers[watcher_dpid][watcher_type] = []
            new_watchers[watcher_dpid][watcher_type].append(watcher)

        timestamp = time.time()
        for watcher_dpid, watchers in new_watchers.items():
            ryu_dp = self.dpset.get(watcher_dpid)
            if ryu_dp:
                self._start_watchers(ryu_dp, watchers, timestamp)

        self.watchers = new_watchers
        self.config_watcher.update(self.config_file)
        self.logger.info('config complete')
示例#4
0
    def __init__(self, *args, **kwargs):
        super(Gauge, self).__init__(*args, **kwargs)
        sysprefix = get_sys_prefix()
        self.config_file = os.getenv('GAUGE_CONFIG',
                                     sysprefix + '/etc/ryu/faucet/gauge.yaml')
        self.exc_logfile = os.getenv(
            'GAUGE_EXCEPTION_LOG',
            sysprefix + '/var/log/ryu/faucet/gauge_exception.log')
        self.logfile = os.getenv('GAUGE_LOG',
                                 sysprefix + '/var/log/ryu/faucet/gauge.log')

        # Setup logging
        self.logger = get_logger(self.logname, self.logfile, logging.DEBUG, 0)
        # Set up separate logging for exceptions
        self.exc_logger = get_logger(self.exc_logname, self.exc_logfile,
                                     logging.DEBUG, 1)

        # Set the signal handler for reloading config file
        signal.signal(signal.SIGHUP, self.signal_handler)

        # dict of watchers/handlers:
        # indexed by dp_id and then by name
        self.watchers = {}
        confs = watcher_parser(self.config_file, self.logname)
        for conf in confs:
            watcher = watcher_factory(conf)(conf, self.logname)
            self.watchers.setdefault(watcher.dp.dp_id, {})
            self.watchers[watcher.dp.dp_id][watcher.conf.type] = watcher
        # Create dpset object for querying Ryu's DPSet application
        self.dpset = kwargs['dpset']
示例#5
0
    def _load_config(self):
        """Load Gauge config."""
        new_confs = watcher_parser(self.config_file, self.logname, self.prom_client)
        new_watchers = {}

        for conf in new_confs:
            watcher = watcher_factory(conf)(conf, self.logname, self.prom_client)
            watcher_dpid = watcher.dp.dp_id
            ryu_dp = self.dpset.get(watcher_dpid)
            watcher_type = watcher.conf.type
            watcher_msg = '%s %s watcher' % (dpid_log(watcher_dpid), watcher_type)

            if watcher_dpid not in new_watchers:
                new_watchers[watcher_dpid] = {}

            if watcher_type not in new_watchers[watcher_dpid]:

                # remove old watchers for this stat
                if (watcher_dpid in self.watchers and
                        watcher_type in self.watchers[watcher_dpid]):
                    old_watchers = self.watchers[watcher_dpid][watcher_type]
                    for old_watcher in old_watchers:
                        if old_watcher.running():
                            self.logger.info('%s stopped', watcher_msg)
                            old_watcher.stop()
                    del self.watchers[watcher_dpid][watcher_type]

                # start new watcher
                new_watchers[watcher_dpid][watcher_type] = [watcher]
                if ryu_dp is None:
                    watcher.report_dp_status(0)
                    self.logger.info('%s added but DP currently down', watcher_msg)
                else:
                    watcher.report_dp_status(1)
                    watcher.start(ryu_dp, True)
                    self.logger.info('%s started', watcher_msg)
            else:
                new_watchers[watcher_dpid][watcher_type].append(watcher)
                watcher.start(ryu_dp, False)

        for watcher_dpid, leftover_watchers in list(self.watchers.items()):
            for watcher_type, watcher in list(leftover_watchers.items()):
                watcher.report_dp_status(0)
                if watcher.running():
                    self.logger.info(
                        '%s %s deconfigured', dpid_log(watcher_dpid), watcher_type)
                    watcher.stop()

        self.watchers = new_watchers
        self.logger.info('config complete')
示例#6
0
文件: gauge.py 项目: c65sdn/faucet
    def _load_config(self):
        """Load Gauge config."""
        try:
            conf_hash, _faucet_config_files, faucet_conf_hashes, new_confs = watcher_parser(
                self.config_file, self.logname, self.prom_client)
            watchers = [
                watcher_factory(watcher_conf)(watcher_conf, self.logname,
                                              self.prom_client)
                for watcher_conf in new_confs
            ]
            self.prom_client.reregister_nonflow_vars()
        except InvalidConfigError as err:
            self.config_watcher.update(self.config_file)
            self.logger.error('invalid config: %s', err)
            return

        for old_watchers in self.watchers.values():
            self._stop_watchers(old_watchers)
        new_watchers = {}
        for watcher in watchers:
            watcher_dpid = watcher.dp.dp_id
            watcher_type = watcher.conf.type
            if watcher_dpid not in new_watchers:
                new_watchers[watcher_dpid] = {}
            if watcher_type not in new_watchers[watcher_dpid]:
                new_watchers[watcher_dpid][watcher_type] = []
            new_watchers[watcher_dpid][watcher_type].append(watcher)

        timestamp = time.time()
        for watcher_dpid, watchers in new_watchers.items():
            ryu_dp = self.dpset.get(watcher_dpid)
            if ryu_dp:
                self._start_watchers(ryu_dp, watchers, timestamp)

        self.watchers = new_watchers
        self.config_watcher.update(self.config_file,
                                   {self.config_file: conf_hash})
        self.faucet_config_watchers = []
        for faucet_config_file, faucet_conf_hash in faucet_conf_hashes.items():
            faucet_config_watcher = ConfigWatcher()
            faucet_config_watcher.update(faucet_config_file, faucet_conf_hash)
            self.faucet_config_watchers.append(faucet_config_watcher)
            self.logger.info('watching FAUCET config %s', faucet_config_file)
        self.logger.info('config complete')
示例#7
0
    def _load_config(self):
        """Load Gauge config."""
        self.config_file = os.getenv('GAUGE_CONFIG', self.config_file)
        new_confs = watcher_parser(self.config_file, self.logname,
                                   self.prom_client)
        new_watchers = {}

        for conf in new_confs:
            watcher = watcher_factory(conf)(conf, self.logname,
                                            self.prom_client)
            watcher_dpid = watcher.dp.dp_id
            ryu_dp = self.dpset.get(watcher_dpid)
            watcher_type = watcher.conf.type
            watcher_msg = '%s %s watcher' % (dpid_log(watcher_dpid),
                                             watcher_type)

            if watcher_dpid not in new_watchers:
                new_watchers[watcher_dpid] = {}

            if (watcher_dpid in self.watchers
                    and watcher_type in self.watchers[watcher_dpid]):
                old_watcher = self.watchers[watcher_dpid][watcher_type]
                if old_watcher.running():
                    self.logger.info('%s stopped', watcher_msg)
                    old_watcher.stop()
                del self.watchers[watcher_dpid][watcher_type]

            new_watchers[watcher_dpid][watcher_type] = watcher
            if ryu_dp is None:
                self.logger.info('%s added but DP currently down', watcher_msg)
            else:
                new_watchers[watcher_dpid][watcher_type].start(ryu_dp)
                self.logger.info('%s started', watcher_msg)

        for watcher_dpid, leftover_watchers in list(self.watchers.items()):
            for watcher_type, watcher in list(leftover_watchers.items()):
                if watcher.running():
                    self.logger.info('%s %s deconfigured',
                                     dpid_log(watcher_dpid), watcher_type)
                    watcher.stop()

        self.watchers = new_watchers
        self.logger.info('config complete')
示例#8
0
    def reload_config(self, ryu_event):
        self.config_file = os.getenv('GAUGE_CONFIG', self.config_file)

        new_confs = watcher_parser(self.config_file, self.logname)
        new_watchers = {}
        for conf in new_confs:
            watcher = watcher_factory(conf)(conf, self.logname)
            new_watchers.setdefault(watcher.dp.dp_id, {})
            new_watchers[watcher.dp.dp_id][watcher.conf.type] = watcher

        for dp_id, watchers in self.watchers:
            for watcher_type, watcher in watchers:
                try:
                    new_watcher = new_watchers[dp_id][watcher_type]
                    self.watchers[dp_id][watcher_type] = new_watcher
                except KeyError:
                    del self.watchers[dp_id][watcher_type]
                if watcher.running():
                    watcher.stop()
                    new_watcher.start(self.dpset.get(dp_id))