'Allocate a dynamic segment using a partial or full segment dict.'

def allocate_dynamic_segment(self, context, network_id, segment):

    dynamic_segment = segments_db.get_dynamic_segment(context, network_id, segment.get(ml2_api.PHYSICAL_NETWORK), segment.get(ml2_api.SEGMENTATION_ID))
    if dynamic_segment:
        return dynamic_segment
    driver = self.drivers.get(segment.get(ml2_api.NETWORK_TYPE))
    if isinstance(driver.obj, api.TypeDriver):
        dynamic_segment = driver.obj.reserve_provider_segment(context.session, segment)
    else:
        dynamic_segment = driver.obj.reserve_provider_segment(context, segment)
    segments_db.add_network_segment(context, network_id, dynamic_segment, is_dynamic=True)
    return dynamic_segment
