示例#1
0
文件: app_manager.py 项目: xbee/ryu
    def load_apps(self, app_lists):
        app_lists = [app for app
                     in itertools.chain.from_iterable(app.split(',')
                                                      for app in app_lists)]
        while len(app_lists) > 0:
            app_cls_name = app_lists.pop(0)

            LOG.info('loading app %s', app_cls_name)

            cls = self.load_app(app_cls_name)
            if cls is None:
                continue

            self.applications_cls[app_cls_name] = cls

            services = []
            for key, context_cls in cls.context_iteritems():
                cls = self.contexts_cls.setdefault(key, context_cls)
                assert cls == context_cls

                if issubclass(context_cls, RyuApp):
                    services.extend(get_dependent_services(context_cls))

            services.extend(get_dependent_services(cls))
            if services:
                app_lists.extend(services)
示例#2
0
    def load_apps(self, app_lists):
        app_lists = [
            app for app in itertools.chain.from_iterable(
                app.split(',') for app in app_lists)
        ]
        while len(app_lists) > 0:
            app_cls_name = app_lists.pop(0)

            LOG.info('loading app %s', app_cls_name)

            cls = self.load_app(app_cls_name)
            if cls is None:
                continue

            self.applications_cls[app_cls_name] = cls

            services = []
            for key, context_cls in cls.context_iteritems():
                v = self.contexts_cls.setdefault(key, context_cls)
                assert v == context_cls

                if issubclass(context_cls, RyuApp):
                    services.extend(get_dependent_services(context_cls))

            # we can't load an app that will be initiataed for
            # contexts.
            context_modules = map(lambda x: x.__module__,
                                  self.contexts_cls.values())
            for i in get_dependent_services(cls):
                if not i in context_modules:
                    services.append(i)
            if services:
                app_lists.extend(services)
示例#3
0
    def load_apps(self, app_lists):
        app_lists = [
            app for app in itertools.chain.from_iterable(
                app.split(',') for app in app_lists)
        ]
        while len(app_lists) > 0:
            app_cls_name = app_lists.pop(0)

            LOG.info('loading app %s', app_cls_name)

            cls = self.load_app(app_cls_name)
            if cls is None:
                continue

            self.applications_cls[app_cls_name] = cls

            services = []
            for key, context_cls in cls.context_iteritems():
                cls = self.contexts_cls.setdefault(key, context_cls)
                assert cls == context_cls

                if issubclass(context_cls, RyuApp):
                    services.extend(get_dependent_services(context_cls))

            services.extend(get_dependent_services(cls))
            if services:
                app_lists.extend(services)
示例#4
0
    def load_apps(self, app_lists):
        app_lists = [app for app
                     in itertools.chain.from_iterable(app.split(',')
                                                      for app in app_lists)]
        while len(app_lists) > 0:
            app_cls_name = app_lists.pop(0)

            LOG.info('loading app %s', app_cls_name)

            cls = self.load_app(app_cls_name)
            if cls is None:
                continue

            self.applications_cls[app_cls_name] = cls

            services = []
            for key, context_cls in cls.context_iteritems():
                v = self.contexts_cls.setdefault(key, context_cls)
                assert v == context_cls

                if issubclass(context_cls, RyuApp):
                    services.extend(get_dependent_services(context_cls))

            # we can't load an app that will be initiataed for
            # contexts.
            context_modules = map(lambda x: x.__module__,
                                  self.contexts_cls.values())
            for i in get_dependent_services(cls):
                if not i in context_modules:
                    services.append(i)
            if services:
                app_lists.extend(services)
示例#5
0
    def load_apps(self, app_lists):
        app_lists = [app for app in itertools.chain.from_iterable(app.split(",") for app in app_lists)]
        while len(app_lists) > 0:
            app_cls_name = app_lists.pop(0)

            context_modules = [x.__module__ for x in self.contexts_cls.values()]
            if app_cls_name in context_modules:
                continue

            LOG.info("loading app %s", app_cls_name)

            cls = self.load_app(app_cls_name)
            if cls is None:
                continue

            self.applications_cls[app_cls_name] = cls

            services = []
            for key, context_cls in cls.context_iteritems():
                v = self.contexts_cls.setdefault(key, context_cls)
                assert v == context_cls
                context_modules.append(context_cls.__module__)

                if issubclass(context_cls, RyuApp):
                    services.extend(get_dependent_services(context_cls))

            # we can't load an app that will be initiataed for
            # contexts.
            for i in get_dependent_services(cls):
                if i not in context_modules:
                    services.append(i)
            if services:
                app_lists.extend([s for s in set(services) if s not in app_lists])
示例#6
0
文件: app_manager.py 项目: wwmm1/MC
    def load_apps(self, app_lists):
        app_lists = [
            app for app in itertools.chain.from_iterable(
                app.split(',') for app in app_lists)
        ]
        # print('3:app_lists:',app_lists)   #('3:app_lists:', ['ryu.controller.ofp_handler'])

        while len(app_lists) > 0:
            app_cls_name = app_lists.pop(0)
            # print('4:app_cls_name:',app_cls_name)  #('4:app_cls_name:', 'ryu.controller.ofp_handler')

            context_modules = [
                x.__module__ for x in self.contexts_cls.values()
            ]

            # print('5:context_modules:',context_modules)  #('5:context_modules:', [])

            if app_cls_name in context_modules:
                continue

            LOG.info('loading app %s', app_cls_name)

            cls = self.load_app(app_cls_name)
            if cls is None:
                continue

            self.applications_cls[app_cls_name] = cls
            # print('9:app_cls_name,cls',app_cls_name,cls)  #('9:app_cls_name,cls', 'ryu.controller.ofp_handler',
            # <class 'ryu.controller.ofp_handler.OFPHandler'>)

            services = []
            # print('10:cls.context_iteritems()',cls.context_iteritems(),services)
            #('10:cls.context_iteritems()', <listiterator object at 0x7ff3d4484a50>, [])

            for key, context_cls in cls.context_iteritems():
                v = self.contexts_cls.setdefault(key, context_cls)
                # print('11:v',v)
                # print('12:key',key)
                # print('13:context_cls',context_cls)

                assert v == context_cls
                context_modules.append(context_cls.__module__)

                if issubclass(context_cls, RyuApp):
                    #get context_cls dependent server and append services
                    services.extend(get_dependent_services(context_cls))

            # we can't load an app that will be initiataed for
            # contexts.
            for i in get_dependent_services(cls):
                if i not in context_modules:
                    services.append(i)
            # print('14:services:',services)  #('14:services:', [])

            if services:
                app_lists.extend(
                    [s for s in set(services) if s not in app_lists])
示例#7
0
    def load_apps(self, app_lists):

        # 注意该app_lists是由命令行中指定,只是名字
        app_lists = [
            app for app in itertools.chain.from_iterable(
                app.split(',') for app in app_lists)
        ]
        while len(app_lists) > 0:
            app_cls_name = app_lists.pop(0)

            # 用于模块间通信,或者避免重复加载服务APP
            context_modules = [
                x.__module__ for x in self.contexts_cls.values()
            ]
            if app_cls_name in context_modules:
                continue

            LOG.info('loading app %s', app_cls_name)

            # 加载APP
            cls = self.load_app(app_cls_name)
            if cls is None:
                continue

            # 字典保存加载的app,key是app名字,value是对应的对象(没有实例化)
            self.applications_cls[app_cls_name] = cls

            services = []

            # 模块间通信,加载其他模块,当前APP可能需要其他模块参与,继承自RyuApp基类
            for key, context_cls in cls.context_iteritems():
                # 将其他模块保存在 contexts_cls 字典中
                v = self.contexts_cls.setdefault(key, context_cls)
                assert v == context_cls
                # 将其他服务模块的模块名保存在context_modules
                context_modules.append(context_cls.__module__)

                # 对其他模块,还需判断是否需要提供服务,是RyuApp继承类就需要。
                if issubclass(context_cls, RyuApp):
                    services.extend(get_dependent_services(context_cls))

            # we can't load an app that will be initiataed for
            # contexts.
            for i in get_dependent_services(cls):
                if i not in context_modules:
                    services.append(i)
            # 每个需要的其他服务,都加入app_lists中
            if services:
                app_lists.extend(
                    [s for s in set(services) if s not in app_lists])
示例#8
0
    def load_apps(self, app_lists):
        #  itertools.chain.from_iterable 为构建迭代器
        app_lists = [
            app for app in itertools.chain.from_iterable(
                app.split(',') for app in app_lists)
        ]

        while len(app_lists) > 0:
            app_cls_name = app_lists.pop(0)

            # contexts_cls 为contexts_cls字典中的实值列表
            context_modules = [
                x.__module__ for x in self.contexts_cls.values()
            ]
            # 如果在列表中,则跳出循环
            if app_cls_name in context_modules:
                continue

            LOG.info('loading app %s', app_cls_name)
            # 调用load_app 函数
            cls = self.load_app(app_cls_name)
            if cls is None:
                continue

            # 填充applications_cls 列表
            self.applications_cls[app_cls_name] = cls

            services = []
            for key, context_cls in cls.context_iteritems():
                # 填入contexts_cls 列表中
                v = self.contexts_cls.setdefault(key, context_cls)
                assert v == context_cls
                # 加入context_modules 列表中
                context_modules.append(context_cls.__module__)
                # 如果其为RyuApp 的子类
                if issubclass(context_cls, RyuApp):
                    services.extend(get_dependent_services(context_cls))

            # we can't load an app that will be initiataed for
            # contexts.
            for i in get_dependent_services(cls):
                if i not in context_modules:
                    services.append(i)
            if services:
                app_lists.extend(
                    [s for s in set(services) if s not in app_lists])