<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_segments(segment_id=None):
 """Returns list of all network segments that may be relevant on CVX"""

    session = db.get_reader_session()
    with session.begin():
        model = segment_models.NetworkSegment
        segments = session.query(model).filter_unnecessary_segments()
        if segment_id:
            segments = segments.filter(model.id == segment_id)
    return segments.all()