Ejemplo n.º 1
0
def schedule_meta_create(schedule_id, values):
    session = get_session()
    _schedule_get_by_id(schedule_id, session)
    meta_ref = models.ScheduleMetadata()
    values['schedule_id'] = schedule_id
    meta_ref.update(values)

    try:
        meta_ref.save(session=session)
    except sqlalchemy.exc.IntegrityError:
        raise exception.Duplicate()

    return _schedule_meta_get(schedule_id, values['key'])
Ejemplo n.º 2
0
def _schedule_metadata_update_in_place(schedule, metadata):
    new_meta = {}
    for item in metadata:
        new_meta[item['key']] = item['value']
    to_delete = []
    for meta in schedule.schedule_metadata:
        if not meta['key'] in new_meta:
            to_delete.append(meta)
        else:
            meta['value'] = new_meta[meta['key']]
            del new_meta[meta['key']]

    for key, value in new_meta.iteritems():
        meta_ref = models.ScheduleMetadata()
        meta_ref.key = key
        meta_ref.value = value
        schedule.schedule_metadata.append(meta_ref)

    for meta in to_delete:
        schedule['schedule_metadata'].remove(meta)
Ejemplo n.º 3
0
def _set_schedule_metadata(schedule_ref, metadata):
    for metadatum in metadata:
        metadata_ref = models.ScheduleMetadata()
        metadata_ref.update(metadatum)
        schedule_ref.schedule_metadata.append(metadata_ref)