コード例 #1
0
    def __init__(self, param):
        self.param = param
        self.logger = logging.getLogger(self.__module__ + "." + self.__class__.__name__)

        self.wanConnPluginApi = None
        self.wanConnPlugin = None

        self.ifconfigDict = dict()      # dict<ifname,ifconfig>

        try:
            cfgfile = os.path.join(self.param.etcDir, "wan-connection.json")
            if os.path.exists(cfgfile):
                cfgObj = WrtUtil.loadJsonEtcCfg(cfgfile)
                self.wanConnPluginApi = WanConnectionPluginApi(self, cfgObj["plugin"])
                self.wanConnPlugin = self.param.pluginHub.getPlugin("wconn", cfgObj["plugin"])
                self.wanConnPlugin.start(cfgObj, self.wanConnPluginApi)
                self.logger.info("Internet connection activated, plugin: %s." % (cfgObj["plugin"]))
            else:
                self.logger.info("No internet connection configured.")
        except BaseException:
            if self.wanConnPlugin is not None:
                self.wanConnPlugin.stop()
                self.wanConnPlugin = None
                self.logger.info("Internet connection deactivated.")
            if self.wanConnPluginApi is not None:
                self.wanConnPluginApi.dispose()
                self.wanConnPluginApi = None
            raise
コード例 #2
0
ファイル: wrt_daemon.py プロジェクト: bombyx-netutils/wrtd
    def _loadManagerPlugins(self):
        # load manager plugin
        for name in self.param.pluginHub.getPluginList("manager"):
            assert name not in self.managerPluginDict
            self.managerPluginDict[name] = self.param.pluginHub.getPlugin("manager", name)

        # create manager data
        class _Stub:
            pass
        data = _Stub()
        data.etcDir = self.param.etcDir
        data.tmpDir = self.param.tmpDir
        data.varDir = self.param.varDir
        data.uuid = self.param.uuid
        data.plugin_hub = self.param.pluginHub
        data.prefix_pool = self.param.prefixPool
        data.manager_caller = self.param.managerCaller
        data.managers = {
            "traffic": self.param.trafficManager,
            "wan": self.param.wanManager,
            "lan": self.param.lanManager,
        }
        data.managers.update(self.managerPluginDict)

        # get init order
        tdict = dict()
        for name in self.managerPluginDict:
            tdict[name] = set(self.managerPluginDict[name].init_after)
        tlist = toposort.toposort_flatten(tdict)

        # init manager plugin
        for name in tlist:
            fn = os.path.join(self.param.etcDir, "manager-%s.json" % (name))
            if os.path.exists(fn) and os.path.getsize(fn) > 0:
                cfgObj = WrtUtil.loadJsonEtcCfg(fn)
            else:
                cfgObj = dict()

            p = self.managerPluginDict[name]
            p.init2(cfgObj, self.param.tmpDir, self.param.varDir, data)
            logging.info("Manager plugin \"%s\" activated." % (p.full_name))

            self.param.managerCaller.call("on_manager_init", p)
            self.param.managerCaller.add_manager(name, p)
コード例 #3
0
    def _getInstanceAndInfoFromEtcDir(self, pluginPrefix, cfgfilePrefix, name):
        # Returns (instanceName, cfgobj, tmpdir, vardir)

        ret = []
        for fn in glob.glob(
                os.path.join(self.param.etcDir,
                             "%s-%s*.json" % (cfgfilePrefix, name))):
            bn = os.path.basename(fn)

            instanceName = bn[len("%s-%s" %
                                  (cfgfilePrefix, name)):len(".json") * -1]
            if instanceName != "":
                instanceName = instanceName.lstrip("-")

            if instanceName != "":
                fullName = "%s-%s" % (name, instanceName)
            else:
                fullName = name

            if os.path.getsize(fn) > 0:
                cfgObj = WrtUtil.loadJsonEtcCfg(fn)
            else:
                cfgObj = dict()

            tmpdir = os.path.join(self.param.tmpDir,
                                  "%s-%s" % (pluginPrefix, fullName))
            vardir = os.path.join(self.param.varDir,
                                  "%s-%s" % (pluginPrefix, fullName))

            ret.append((instanceName, cfgObj, tmpdir, vardir))

        if len(ret) == 0:
            instanceName = ""
            fullName = name
            cfgObj = dict()
            tmpdir = os.path.join(self.param.tmpDir,
                                  "%s-%s" % (pluginPrefix, fullName))
            vardir = os.path.join(self.param.varDir,
                                  "%s-%s" % (pluginPrefix, fullName))
            ret.append((instanceName, cfgObj, tmpdir, vardir))

        return ret