def _update_active_port_in_db(self, ip_str, mac, lport): lswitch = lport.lswitch topic = lport.topic found_lport_id = lport.id key = self._get_active_port_id(lswitch, ip_str) old_active_port = self.db_store.get_one( active_port.AllowedAddressPairsActivePort(id=key)) new_active_port = active_port.AllowedAddressPairsActivePort( id=key, topic=topic, network=lswitch.id, ip=ip_str, detected_mac=mac, detected_lport=found_lport_id) if not old_active_port: LOG.info( "Detected new active node. ip=%(ip_str)s, " "mac=%(mac)s, lport_id=%(lport_id)s", { 'ip': ip_str, 'mac': mac, 'lport_id': found_lport_id }) self.nb_api.create(new_active_port) elif old_active_port != new_active_port: LOG.info( "Detected update in active node. ip=%(ip_str)s, " "mac=%(mac)s, lport_id=%(lport_id)s", { 'ip': ip_str, 'mac': mac, 'lport_id': found_lport_id }) self.nb_api.update(new_active_port)
def _remove_active_port_from_db_by_lport(self, lswitch, ip_str, lport): key = self._get_active_port_id(lswitch, ip_str) old_active_port = self.db_store.get_one( active_port.AllowedAddressPairsActivePort(id=key)) if (old_active_port and old_active_port.detected_lport.id == lport.id): self.nb_api.delete(old_active_port)