docs: def get_instances(device_owners=None, vnic_type=None, instance_id=None):
      """Returns filtered list of all instances in the neutron db"""
      session = db.get_reader_session()
      with session.begin():
          port_model = models_v2.Port
          binding_model = ml2_models.PortBinding
          instances = (session
                       .query(port_model,
                              binding_model)
                       .outerjoin(
                           binding_model,
                           port_model.id == binding_model.port_id)
                       .distinct(port_model.device_id)
                       .group_by(port_model.device_id)
                       .filter_unnecessary_ports(device_owners, vnic_type))
          if instance_id:
              instances = instances.filter(port_model.device_id == instance_id)
      return instances.all()