'Create a segment.'

@log_helpers.log_method_call
def create_segment(self, context, segment):

    segment = segment['segment']
    segment_id = (segment.get('id') or uuidutils.generate_uuid())
    try:
        new_segment = self._create_segment_db(context, segment_id, segment)
    except db_exc.DBReferenceError:
        raise n_exc.NetworkNotFound(net_id=segment['network_id'])
    registry.notify(resources.SEGMENT, events.AFTER_CREATE, self, context=context, segment=new_segment)
    return self._make_segment_dict(new_segment)
