当前位置: 首页>>代码示例>>Python>>正文


Python utils.diff_list_of_dict函数代码示例

本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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