def _update_fip_assoc(self, context, fip, floatingip_db, external_port): port_id = internal_ip_address = router_id = None if (('fixed_ip_address' in fip and fip['fixed_ip_address']) and not ('port_id' in fip and fip['port_id'])): msg = _("fixed_ip_address cannot be specified without a port_id") raise q_exc.BadRequest(resource='floatingip', msg=msg) if 'port_id' in fip and fip['port_id']: port_id, internal_ip_address, router_id = self.get_assoc_data( context, fip, floatingip_db['floating_network_id']) fip_qry = context.session.query(FloatingIP) try: fip_qry.filter_by( fixed_port_id=fip['port_id'], floating_network_id=floatingip_db['floating_network_id'], fixed_ip_address=internal_ip_address).one() raise l3.FloatingIPPortAlreadyAssociated( port_id=fip['port_id'], fip_id=floatingip_db['id'], floating_ip_address=floatingip_db['floating_ip_address'], fixed_ip=internal_ip_address, net_id=floatingip_db['floating_network_id']) except exc.NoResultFound: pass floatingip_db.update({ 'fixed_ip_address': internal_ip_address, 'fixed_port_id': port_id, 'router_id': router_id })
def _update_fip_assoc(self, context, fip, floatingip_db, external_port): LOG.debug(_("update_fip_assoc called in l3_db.py context: %s"), context) LOG.debug(_("update_fip_assoc called in l3_db.py fip: %s"), fip) LOG.debug(_("update_fip_assoc called in l3_db.py floatingip_db: %s"), floatingip_db) LOG.debug(_("update_fip_assoc called in l3_db.py external_port: %s"), external_port) port_id = internal_ip_address = router_id = None if (('fixed_ip_address' in fip and fip['fixed_ip_address']) and not ('port_id' in fip and fip['port_id'])): msg = _("fixed_ip_address cannot be specified without a port_id") raise q_exc.BadRequest(resource='floatingip', msg=msg) if 'port_id' in fip and fip['port_id']: port_id, internal_ip_address, router_id = self.get_assoc_data( context, fip, floatingip_db['floating_network_id']) fip_qry = context.session.query(FloatingIP) try: fip_qry.filter_by( fixed_port_id=fip['port_id'], floating_network_id=floatingip_db['floating_network_id'], fixed_ip_address=internal_ip_address).one() raise l3.FloatingIPPortAlreadyAssociated( port_id=fip['port_id'], fip_id=floatingip_db['id'], floating_ip_address=floatingip_db['floating_ip_address'], fixed_ip=internal_ip_address, net_id=floatingip_db['floating_network_id']) except exc.NoResultFound: pass floatingip_db.update({ 'fixed_ip_address': internal_ip_address, 'fixed_port_id': port_id, 'router_id': router_id }) LOG.debug( _("update_fip_assoc called in l3_db.py internal_ip_address: %s"), internal_ip_address) LOG.debug(_("update_fip_assoc called in l3_db.py port_id: %s"), port_id) LOG.debug(_("update_fip_assoc called in l3_db.py router_id: %s"), router_id) # Call update_fip_assoc() in ML2 plugin if fip['port_id'] and internal_ip_address: LOG.debug(_("Floating IP associated with a fixed IP")) fixed_port = self._core_plugin._get_port(context.elevated(), fip['port_id']) LOG.debug(_("update_fip_assoc called fixed_port: %s"), fixed_port) floatingip_port = self._core_plugin._get_port( context.elevated(), floatingip_db['floating_port_id']) LOG.debug(_("update_fip_assoc called floatingip_port: %s"), floatingip_port) self._core_plugin._update_fip_assoc( context, internal_ip_address, floatingip_db['floating_ip_address'], fixed_port['mac_address'], fixed_port['network_id'], floatingip_port['network_id'], router_id, floatingip_port['id'], floatingip_port['mac_address'])