def add_interface(session, attribs):
    network = attribs.get("network")
    ipaddr = attribs["ipaddr"]
    attribs["interface_type"] = get_interface_type(session)
    q = session.query(models.Interface).filter(models.and_(
                models.Interface.network==network,
                models.Interface.ipaddr==ipaddr)
                )
    # try to find equipment by matching name.
    hostname = attribs.get("description")
    if hostname:
        eq = get_equipment(session, hostname)
        del attribs["description"]
    else:
        eq = None
    attribs["equipment"] = eq

    try:
        intf = q.one()
    except models.NoResultFound:
        intf = models.create(models.Interface, **attribs)
        session.add(intf)
        session.commit()
    else:
        models.update(intf, **attribs)
        session.commit()
Add new interface, don't duplicate existing one.
dataset/ETHPy150Open kdart/pycopia/storage/pycopia/db/importers/nmap.py/add_interface