• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.diff_list_of_dict函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中neutron.common.utils.diff_list_of_dict函数的典型用法代码示例。如果您正苦于以下问题:Python diff_list_of_dict函数的具体用法?Python diff_list_of_dict怎么用?Python diff_list_of_dict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了diff_list_of_dict函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: update_router

 def update_router(self, context, router_id, old_router, new_router):
     old_routes = old_router['routes'][:]
     new_routes = new_router['routes'][:]
     self._process_gw_port(old_router['gw_port'], old_routes)
     self._process_gw_port(new_router['gw_port'], new_routes)
     added, removed = utils.diff_list_of_dict(old_routes, new_routes)
     if added or removed:
         try:
             # NOTE(amotoki): PFC supports one-by-one route update at now.
             # It means there may be a case where some route is updated but
             # some not. To allow the next call of failures to sync routes
             # with Neutron side, we pass the whole new routes here.
             # PFC should support atomic route update in the future.
             self.ofc.update_ofc_router_route(context, router_id,
                                              new_routes)
             new_status = nconst.ROUTER_STATUS_ACTIVE
             self.plugin._update_resource_status(
                 context, "router", router_id, new_status)
             new_router['status'] = new_status
         except (nexc.OFCException, nexc.OFCMappingNotFound) as exc:
             with excutils.save_and_reraise_exception():
                 LOG.error(_LE("_update_ofc_routes() failed due to %s"),
                           exc)
                 new_status = nconst.ROUTER_STATUS_ERROR
                 self.plugin._update_resource_status(
                     context, "router", router_id, new_status)
     return new_router
开发者ID:afori,项目名称:neutron,代码行数:27,代码来源:router_drivers.py


示例2: _routes_updated

    def _routes_updated(self, ri):
        """Update the state of routes in the router.

        Compares the current routes with the (configured) existing routes
        and detect what was removed or added. Then configure the
        logical router in the hosting device accordingly.
        :param ri: RouterInfo corresponding to the router.
        :return: None
        :raises: networking_cisco.plugins.cisco.cfg_agent.cfg_exceptions.
        DriverException if the configuration operation fails.
        """
        new_routes = ri.router['routes']
        old_routes = ri.routes
        adds, removes = common_utils.diff_list_of_dict(old_routes,
                                                       new_routes)
        for route in adds:
            LOG.debug("Added route entry is '%s'", route)
            # remove replaced route from deleted route
            for del_route in removes:
                if route['destination'] == del_route['destination']:
                    removes.remove(del_route)
            driver = self.driver_manager.get_driver(ri.id)
            driver.routes_updated(ri, 'replace', route)

        for route in removes:
            LOG.debug("Removed route entry is '%s'", route)
            driver = self.driver_manager.get_driver(ri.id)
            driver.routes_updated(ri, 'delete', route)
        ri.routes = new_routes
开发者ID:JoelCapitao,项目名称:networking-cisco,代码行数:29,代码来源:routing_svc_helper.py


示例3: process_router_portforwardings

    def process_router_portforwardings(self, ri, ex_gw_port):
        if 'portforwardings' not in ri.router:
            # note(jianingy): return when portforwarding extension
            # is not enabled
            LOG.debug("Portforwarding Extension Not Enabled")
            return None
        if ex_gw_port:
            new_portfwds = ri.router['portforwardings']
            for new_portfwd in new_portfwds:
                new_portfwd['outside_addr'] = (
                    ex_gw_port.get('fixed_ips')[0].get('ip_address'))
                LOG.debug("New Portforwarding: %s" % new_portfwd.values())
            old_portfwds = ri.portforwardings
            for old_portfwd in old_portfwds:
                LOG.debug("Old Portforwarding: %s" % old_portfwd.values())
            adds, removes = common_utils.diff_list_of_dict(old_portfwds,
                            new_portfwds)
            for portfwd in adds:
                LOG.debug("Add Portforwarding: %s" % portfwd.values())
                self._update_portforwardings(ri, 'create', portfwd)
            for portfwd in removes:
                LOG.debug("Del Portforwarding: %s" % portfwd.values())
                self._update_portforwardings(ri, 'delete', portfwd)
            ri.portforwardings = new_portfwds
        else:
            old_portfwds = ri.portforwardings
            for old_portfwd in old_portfwds:
                    LOG.debug("Del Portforwarding: %s" % old_portfwd.values())
                    self._update_portforwardings(ri, 'delete', old_portfwd)
            ri.portforwardings = []

        ri.iptables_manager.apply()
开发者ID:adiantum,项目名称:networking-portforwarding,代码行数:32,代码来源:agent.py


示例4: test_diff_list_of_dict

 def test_diff_list_of_dict(self):
     old_list = [{"key1": "value1"},
                 {"key2": "value2"},
                 {"key3": "value3"}]
     new_list = [{"key1": "value1"},
                 {"key2": "value2"},
                 {"key4": "value4"}]
     added, removed = utils.diff_list_of_dict(old_list, new_list)
     self.assertEqual(added, [dict(key4="value4")])
     self.assertEqual(removed, [dict(key3="value3")])
开发者ID:ChengZuo,项目名称:neutron,代码行数:10,代码来源:test_common_utils.py


示例5: routes_updated

 def routes_updated(self, old_routes, new_routes):
     adds, removes = common_utils.diff_list_of_dict(old_routes, new_routes)
     for route in adds:
         LOG.debug("Added route entry is '%s'", route)
         # remove replaced route from deleted route
         for del_route in removes:
             if route["destination"] == del_route["destination"]:
                 removes.remove(del_route)
         # replace success even if there is no existing route
         self.update_routing_table("replace", route)
     for route in removes:
         LOG.debug("Removed route entry is '%s'", route)
         self.update_routing_table("delete", route)
开发者ID:kimcharli,项目名称:neutron,代码行数:13,代码来源:router_info.py


示例6: update_router

    def update_router(self, context, id, router):
        original_router = self.get_router(context, id)
        result = super(OVNL3RouterPlugin, self).update_router(
            context, id, router)

        update = {}
        added = []
        removed = []
        router_name = utils.ovn_name(id)
        if 'admin_state_up' in router['router']:
            enabled = router['router']['admin_state_up']
            if enabled != original_router['admin_state_up']:
                update['enabled'] = enabled

        if 'name' in router['router']:
            if router['router']['name'] != original_router['name']:
                external_ids = {ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY:
                                router['router']['name']}
                update['external_ids'] = external_ids

        """ Update static routes """
        if 'routes' in router['router']:
            routes = router['router']['routes']
            added, removed = n_utils.diff_list_of_dict(
                original_router['routes'], routes)

        if update or added or removed:
            try:
                with self._ovn.transaction(check_error=True) as txn:
                    if update:
                        txn.add(self._ovn.update_lrouter(router_name,
                                **update))

                    for route in added:
                        txn.add(self._ovn.add_static_route(router_name,
                                ip_prefix=route['destination'],
                                nexthop=route['nexthop']))

                    for route in removed:
                        txn.add(self._ovn.delete_static_route(router_name,
                                ip_prefix=route['destination'],
                                nexthop=route['nexthop']))
            except Exception:
                LOG.exception(_LE('Unable to update lrouter for %s'), id)
                super(OVNL3RouterPlugin, self).update_router(context,
                                                             id,
                                                             original_router)
                raise n_exc.ServiceUnavailable()

        return result
开发者ID:bigclouds,项目名称:networking-ovn,代码行数:50,代码来源:l3_ovn.py


示例7: _update_extra_routes

    def _update_extra_routes(self, context, router, routes):
        self._validate_routes(context, router["id"], routes)
        old_routes, routes_dict = self._get_extra_routes_dict_by_router_id(context, router["id"])
        added, removed = utils.diff_list_of_dict(old_routes, routes)
        LOG.debug("Added routes are %s", added)
        for route in added:
            router_routes = RouterRoute(
                router_id=router["id"], destination=route["destination"], nexthop=route["nexthop"]
            )
            context.session.add(router_routes)

        LOG.debug("Removed routes are %s", removed)
        for route in removed:
            context.session.delete(routes_dict[(route["destination"], route["nexthop"])])
开发者ID:cisco-openstack,项目名称:neutron,代码行数:14,代码来源:extraroute_db.py


示例8: process_router_portforwardings

 def process_router_portforwardings(self, ri, ex_gw_port):
     if 'portforwardings' not in ri.router:
         # return when portforwarding extension is not enabled
         return
     new_portfwds = ri.router['portforwardings']
     for new_portfwd in new_portfwds:
         new_portfwd['outside_addr'] = (
             ex_gw_port.get('fixed_ips')[0].get('ip_address'))
     old_portfwds = ri.portforwardings
     adds, removes = common_utils.diff_list_of_dict(old_portfwds,
                                                    new_portfwds)
     for portfwd in adds:
         self._update_portforwardings(ri, 'create', portfwd)
     for portfwd in removes:
         self._update_portforwardings(ri, 'delete', portfwd)
     ri.portforwardings = new_portfwds
开发者ID:CingHu,项目名称:neutron-ustack,代码行数:16,代码来源:uos_l3.py


示例9: routes_updated

 def routes_updated(self, ri):
     new_routes = ri.router['routes']
     old_routes = ri.routes
     adds, removes = common_utils.diff_list_of_dict(old_routes,
                                                    new_routes)
     for route in adds:
         LOG.debug(_("Added route entry is '%s'"), route)
         # remove replaced route from deleted route
         for del_route in removes:
             if route['destination'] == del_route['destination']:
                 removes.remove(del_route)
         #replace success even if there is no existing route
         self._update_routing_table(ri, 'replace', route)
     for route in removes:
         LOG.debug(_("Removed route entry is '%s'"), route)
         self._update_routing_table(ri, 'delete', route)
     ri.routes = new_routes
开发者ID:674009287,项目名称:neutron,代码行数:17,代码来源:l3_agent.py


示例10: update_ofc_router_route

 def update_ofc_router_route(self, context, router_id, new_routes):
     ofc_router_id = self._get_ofc_id(context, "ofc_router", router_id)
     ofc_routes = self.driver.list_router_routes(ofc_router_id)
     route_dict = {}
     cur_routes = []
     for r in ofc_routes:
         key = ','.join((r['destination'], r['nexthop']))
         route_dict[key] = r['id']
         del r['id']
         cur_routes.append(r)
     added, removed = utils.diff_list_of_dict(cur_routes, new_routes)
     for r in removed:
         key = ','.join((r['destination'], r['nexthop']))
         route_id = route_dict[key]
         self.driver.delete_router_route(route_id)
     for r in added:
         self.driver.add_router_route(ofc_router_id, r['destination'],
                                      r['nexthop'])
开发者ID:50infivedays,项目名称:neutron,代码行数:18,代码来源:ofc_manager.py


示例11: update_router

 def update_router(self, context, id, router):
     r = router['router']
     with context.session.begin(subtransactions=True):
         if 'routes' in r:
             old_routes = self._get_extra_routes_by_router_id(context,
                                                              id)
             added, removed = utils.diff_list_of_dict(old_routes,
                                                      r['routes'])
             self._validate_nuage_staticroutes(old_routes, added, removed)
             ent_rtr_mapping = nuagedb.get_ent_rtr_mapping_by_rtrid(
                 context.session, id)
             if not ent_rtr_mapping:
                 msg = (_("Router %s does not hold net-partition "
                          "assoc on VSD. extra-route failed") % id)
                 raise n_exc.BadRequest(resource='router', msg=msg)
             # Let it do internal checks first and verify it.
             router_updated = super(NuagePlugin,
                                    self).update_router(context,
                                                        id,
                                                        router)
             for route in removed:
                 rtr_rt_mapping = nuagedb.get_router_route_mapping(
                     context.session, id, route)
                 if rtr_rt_mapping:
                     self.nuageclient.delete_nuage_staticroute(
                         rtr_rt_mapping['nuage_route_id'])
                     nuagedb.delete_static_route(context.session,
                                                 rtr_rt_mapping)
             for route in added:
                 params = {
                     'parent_id': ent_rtr_mapping['nuage_router_id'],
                     'net': netaddr.IPNetwork(route['destination']),
                     'nexthop': route['nexthop']
                 }
                 nuage_rt_id = self.nuageclient.create_nuage_staticroute(
                     params)
                 nuagedb.add_static_route(context.session,
                                          id, nuage_rt_id,
                                          route['destination'],
                                          route['nexthop'])
         else:
             router_updated = super(NuagePlugin, self).update_router(
                 context, id, router)
     return router_updated
开发者ID:PFZheng,项目名称:neutron,代码行数:44,代码来源:plugin.py


示例12: _update_extra_routes

    def _update_extra_routes(self, context, router, routes):
        self._validate_routes(context, router['id'],
                              routes)
        old_routes = self._get_extra_routes_by_router_id(
            context, router['id'])
        added, removed = utils.diff_list_of_dict(old_routes,
                                                 routes)
        LOG.debug(_('Added routes are %s'), added)
        for route in added:
            router_routes = RouterRoute(
                router_id=router['id'],
                destination=route['destination'],
                nexthop=route['nexthop'])
            context.session.add(router_routes)

        LOG.debug(_('Removed routes are %s'), removed)
        for route in removed:
            del_context = context.session.query(RouterRoute)
            del_context.filter_by(router_id=router['id'],
                                  destination=route['destination'],
                                  nexthop=route['nexthop']).delete()
开发者ID:CampHarmony,项目名称:neutron,代码行数:21,代码来源:extraroute_db.py


示例13: routes_updated

    def routes_updated(self, ri):
        LOG.debug("Enter routes updated function")
        data = {}
        data['id'] = ri.router_id
        data['subnets'] = self._get_engine_subnets(ri.router.get(l3_constants.SNAT_ROUTER_INTF_KEY, []))
        ex_gw_port = self._get_ex_gw_port(ri)
        data['ext_net_info'] = {
            'vlan': ex_gw_port['vlan'],
            'ip': ex_gw_port['fixed_ips'][0]['ip_address']
        }
        new_routes = ri.router['routes']
        old_routes = ri.routes
        adds, removes = common_utils.diff_list_of_dict(old_routes,
                                                       new_routes)

        if removes:
            data['routes'] = self._get_engine_routes(removes, ex_gw_port)
            self.dataengine_rpc.router_route_delete(data)
        
        if adds:
            data['routes'] = self._get_engine_routes(adds, ex_gw_port)
            self.dataengine_rpc.router_route_add(data)
开发者ID:HybridCloud-dew,项目名称:hws,代码行数:22,代码来源:l3_highperformance_agent.py


示例14: update_router

 def update_router(self, context, router_id, router):
     """Update the router with static route"""
     r = router['router']
     old_routes, routes_dict = self._get_extra_routes_dict_by_router_id(
         context, router_id)
     added, removed = neutron_utils.diff_list_of_dict(old_routes,
                                                      r['routes'])
     try:
         updated_router = super(BrocadeSVIPlugin, self).\
             update_router(context, router_id, router)
         if 'routes' in r:
             self._invoke_nos_driver_api('update_router',
                                         router_id,
                                         None,
                                         None,
                                         None,
                                         None,
                                         added,
                                         removed)
     except Exception as e:
         LOG.error(_LE("Failed to modify route %s"), str(e))
         raise e
     return updated_router
开发者ID:denismakogon,项目名称:networking-brocade,代码行数:23,代码来源:l3_router_plugin.py


示例15: _update_extra_portfwds

    def _update_extra_portfwds(self, context, router, portfwds):
        old_fwds = self._get_extra_portfwds_by_router_id(
            context, router['id'])
        added, removed = utils.diff_list_of_dict(old_fwds, portfwds)

        LOG.debug(_('Removed port forwarding rules are %s'), removed)
        for portfwd in removed:
            del_context = context.session.query(PortForwardingRule)
            del_context.filter_by(router_id=router['id'],
                                  outside_port=portfwd['outside_port'],
                                  inside_addr=portfwd['inside_addr'],
                                  inside_port=portfwd['inside_port'],
                                  protocol=portfwd['protocol']).delete()

        LOG.debug(_('Added port forwarding rules are %s'), added)
        for portfwd in added:
            router_fwds = PortForwardingRule(
                router_id=router['id'],
                outside_port=portfwd['outside_port'],
                inside_addr=portfwd['inside_addr'],
                inside_port=portfwd['inside_port'],
                protocol=portfwd['protocol'])

            context.session.add(router_fwds)
开发者ID:CingHu,项目名称:neutron-ustack,代码行数:24,代码来源:portforwardings_db.py


示例16: sync_routers_and_rports

    def sync_routers_and_rports(self, ctx):
        """Sync Routers between neutron and NB.

        @param ctx: neutron context
        @type  ctx: object of type neutron.context.Context
        @var   db_routers: List of Routers from neutron DB
        @var   db_router_ports: List of Router ports from neutron DB
        @var   lrouters: NB dictionary of logical routers and
               the corresponding logical router ports.
               vs list-of-acls
        @var   del_lrouters_list: List of Routers that need to be
               deleted from NB
        @var   del_lrouter_ports_list: List of Router ports that need to be
               deleted from NB
        @return: Nothing
        """
        if not config.is_ovn_l3():
            LOG.debug("OVN L3 mode is disabled, skipping "
                      "sync routers and router ports")
            return

        LOG.debug('OVN-NB Sync Routers and Router ports started')
        db_routers = {}
        db_router_ports = {}
        for router in self.l3_plugin.get_routers(ctx):
            db_routers[router['id']] = router

        interfaces = self.l3_plugin._get_sync_interfaces(ctx,
                                                         db_routers.keys())
        for interface in interfaces:
            db_router_ports[interface['id']] = interface
        lrouters = self.ovn_api.get_all_logical_routers_with_rports()
        del_lrouters_list = []
        del_lrouter_ports_list = []
        update_sroutes_list = []
        for lrouter in lrouters:
            if lrouter['name'] in db_routers:
                for lrport in lrouter['ports']:
                    if lrport in db_router_ports:
                        del db_router_ports[lrport]
                    else:
                        del_lrouter_ports_list.append(
                            {'port': lrport, 'lrouter': lrouter['name']})
                if 'routes' in db_routers[lrouter['name']]:
                    db_routes = db_routers[lrouter['name']]['routes']
                else:
                    db_routes = []
                ovn_routes = lrouter['static_routes']
                add_routes, del_routes = n_utils.diff_list_of_dict(
                    ovn_routes, db_routes)
                update_sroutes_list.append({'id': lrouter['name'],
                                            'add': add_routes,
                                            'del': del_routes})
                del db_routers[lrouter['name']]
            else:
                del_lrouters_list.append(lrouter)

        for r_id, router in db_routers.items():
            LOG.warning(_LW("Router found in Neutron but not in "
                            "OVN DB, router id=%s"), router['id'])
            if self.mode == SYNC_MODE_REPAIR:
                try:
                    LOG.warning(_LW("Creating the router %s in OVN NB DB"),
                                router['id'])
                    self.l3_plugin.create_lrouter_in_ovn(router)
                    if 'routes' in router:
                        update_sroutes_list.append(
                            {'id': router['id'], 'add': router['routes'],
                             'del': []})
                except RuntimeError:
                    LOG.warning(_LW("Create router in OVN NB failed for"
                                    " router %s"), router['id'])

        for rp_id, rrport in db_router_ports.items():
            LOG.warning(_LW("Router Port found in Neutron but not in OVN "
                            "DB, router port_id=%s"), rrport['id'])
            if self.mode == SYNC_MODE_REPAIR:
                try:
                    LOG.warning(_LW("Creating the router port %s in "
                                    "OVN NB DB"), rrport['id'])
                    self.l3_plugin.create_lrouter_port_in_ovn(
                        ctx, rrport['device_id'], rrport)
                except RuntimeError:
                    LOG.warning(_LW("Create router port in OVN "
                                    "NB failed for"
                                    " router port %s"), rrport['id'])

        with self.ovn_api.transaction(check_error=True) as txn:
            for lrouter in del_lrouters_list:
                LOG.warning(_LW("Router found in OVN but not in "
                                "Neutron, router id=%s"), lrouter['name'])
                if self.mode == SYNC_MODE_REPAIR:
                    LOG.warning(_LW("Deleting the router %s from OVN NB DB"),
                                lrouter['name'])
                    txn.add(self.ovn_api.delete_lrouter(
                            utils.ovn_name(lrouter['name'])))

            for lrport_info in del_lrouter_ports_list:
                LOG.warning(_LW("Router Port found in OVN but not in "
                                "Neutron, port_id=%s"), lrport_info['port'])
#.........这里部分代码省略.........
开发者ID:bali2016,项目名称:networking-ovn,代码行数:101,代码来源:ovn_db_sync.py



注:本文中的neutron.common.utils.diff_list_of_dict函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.ensure_dir函数代码示例发布时间:2022-05-27
下一篇:
Python utils.dict2str函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap