Esempio n. 1
0
 def update_ip_owner(self, ip_owner_info):
     ports_to_update = set()
     port_id = ip_owner_info.get('port')
     ipv4 = ip_owner_info.get('ip_address_v4')
     ipv6 = ip_owner_info.get('ip_address_v6')
     network_id = ip_owner_info.get('network_id')
     if not port_id or (not ipv4 and not ipv6):
         return ports_to_update
     LOG.debug("Got IP owner update: %s", ip_owner_info)
     # REVISIT: Just use SQLAlchemy session and models_v2.Port?
     port = self.plugin.get_port(n_context.get_admin_context(), port_id)
     if not port:
         LOG.debug("Ignoring update for non-existent port: %s", port_id)
         return ports_to_update
     ports_to_update.add(port_id)
     for ipa in [ipv4, ipv6]:
         if not ipa:
             continue
         try:
             # REVISIT: Why isn't this a single transaction at the
             # top-level, so that the port itself is guaranteed to
             # still exist.
             session = db_api.get_writer_session()
             with session.begin(subtransactions=True):
                 old_owner = self.get_port_for_ha_ipaddress(
                     ipa, network_id or port['network_id'], session=session)
                 self.set_port_id_for_ha_ipaddress(port_id, ipa, session)
                 if old_owner and old_owner['port_id'] != port_id:
                     self.delete_port_id_for_ha_ipaddress(
                         old_owner['port_id'], ipa, session=session)
                     ports_to_update.add(old_owner['port_id'])
         except db_exc.DBReferenceError as dbe:
             LOG.debug("Ignoring FK error for port %s: %s", port_id, dbe)
     return ports_to_update
Esempio n. 2
0
 def _ml2_md_extend_subnet_dict_bulk(results, _):
     subnetdb = results[0][1] if results else None
     plugin = directory.get_plugin()
     session = db_api.get_session_from_obj(subnetdb)
     if not session:
         session = db_api.get_writer_session()
     with session.begin(subtransactions=True):
         plugin.extension_manager.extend_subnet_dict_bulk(session, results)
Esempio n. 3
0
 def _ml2_md_extend_port_dict(result, portdb):
     plugin = directory.get_plugin()
     session = db_api.get_session_from_obj(portdb)
     if not session:
         session = db_api.get_writer_session()
     # REVISIT: Check if transaction begin is still
     # required here, and if so, if reader pattern
     # can be used instead (will require getting the
     # current context, which should be available in
     # the session.info's dictionary, with a key of
     # 'using_context').
     with session.begin(subtransactions=True):
         plugin.extension_manager.extend_port_dict(session, portdb, result)
Esempio n. 4
0
    def _extend_router_dict_apic(router_res, router_db):
        if router_res.get(api_plus.BULK_EXTENDED):
            return

        LOG.debug("APIC AIM L3 Plugin extending router dict: %s", router_res)
        plugin = directory.get_plugin(constants.L3)
        session = db_api.get_session_from_obj(router_db)
        if not session:
            session = db_api.get_writer_session()
        try:
            plugin._md.extend_router_dict(session, router_db, router_res)
            plugin._include_router_extn_attr(session, router_res)
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.exception("APIC AIM extend_router_dict failed")
Esempio n. 5
0
 def _extend_router_dict_bulk_apic(routers, _):
     LOG.debug("APIC AIM L3 Plugin bulk extending router dict: %s", routers)
     if not routers:
         return
     router_db = routers[0]
     plugin = directory.get_plugin(constants.L3)
     session = db_api.get_session_from_obj(router_db)
     if not session:
         session = db_api.get_writer_session()
     try:
         plugin._md.extend_router_dict_bulk(session, routers)
         plugin._include_router_extn_attr_bulk(session, routers)
     except Exception:
         with excutils.save_and_reraise_exception():
             LOG.exception("APIC AIM _extend_router_dict_bulk failed")
Esempio n. 6
0
 def delete_port_id_for_ha_ipaddress(self, port_id, ipaddress,
                                     session=None):
     session = session or db_api.get_writer_session()
     with session.begin(subtransactions=True):
         try:
             # REVISIT: Can this query be baked? The
             # sqlalchemy.ext.baked.Result class does not have a
             # delete() method, and adding delete() to the baked
             # query before executing it seems to result in the
             # params() not being evaluated.
             return session.query(
                 HAIPAddressToPortAssociation).filter_by(
                     port_id=port_id,
                     ha_ip_address=ipaddress).delete()
         except orm.exc.NoResultFound:
             return
Esempio n. 7
0
 def set_port_id_for_ha_ipaddress(self, port_id, ipaddress, session=None):
     """Stores a Neutron Port Id as owner of HA IP Addr (idempotent API)."""
     session = session or db_api.get_writer_session()
     try:
         with session.begin(subtransactions=True):
             obj = self._get_ha_ipaddress(port_id, ipaddress, session)
             if obj:
                 return obj
             else:
                 obj = HAIPAddressToPortAssociation(
                     port_id=port_id, ha_ip_address=ipaddress)
                 session.add(obj)
                 return obj
     except db_exc.DBDuplicateEntry:
         LOG.debug('Duplicate IP ownership entry for tuple %s',
                   (port_id, ipaddress))
Esempio n. 8
0
 def setUp(self):
     super(NFPDBTestCase, self).setUp()
     self.ctx = context.get_admin_context()
     self.nfp_db = NFPDB()
     self.session = db_api.get_writer_session()
Esempio n. 9
0
 def update_link(self, context, *args, **kwargs):
     context._session = db_api.get_writer_session()
     return self.md.update_link(context, *args, **kwargs)