예제 #1
0
def bump_revision(resource, resource_type):
    session = db_api.get_writer_session()
    revision_number = utils.get_revision_number(resource, resource_type)
    with session.begin():
        _ensure_revision_row_exist(session, resource, resource_type)
        std_attr_id = _get_standard_attr_id(session, resource['id'],
                                            resource_type)
        row = session.merge(
            models.OVNRevisionNumbers(standard_attr_id=std_attr_id,
                                      resource_uuid=resource['id']))
        if revision_number < row.revision_number:
            LOG.debug(
                'Skip bumping the revision number for %(res_uuid)s (type: '
                '%(res_type)s) to %(rev_num)d. A higher version is already '
                'registered in the database (%(new_rev)d)', {
                    'res_type': resource_type,
                    'res_uuid': resource['id'],
                    'rev_num': revision_number,
                    'new_rev': row.revision_number
                })
            return
        row.revision_number = revision_number
        session.merge(row)
    LOG.info(
        'Successfully bumped revision number for resource '
        '%(res_uuid)s (type: %(res_type)s) to %(rev_num)d', {
            'res_uuid': resource['id'],
            'res_type': resource_type,
            'rev_num': revision_number
        })
예제 #2
0
def create_initial_revision(resource_uuid,
                            resource_type,
                            session,
                            revision_number=ovn_const.INITIAL_REV_NUM):
    with session.begin(subtransactions=True):
        std_attr_id = _get_standard_attr_id(session, resource_uuid,
                                            resource_type)
        row = models.OVNRevisionNumbers(resource_uuid=resource_uuid,
                                        resource_type=resource_type,
                                        standard_attr_id=std_attr_id,
                                        revision_number=revision_number)
        session.add(row)
예제 #3
0
def create_initial_revision(resource_uuid,
                            resource_type,
                            session,
                            revision_number=ovn_const.INITIAL_REV_NUM,
                            may_exist=False):
    LOG.debug('create_initial_revision uuid=%s, type=%s, rev=%s',
              resource_uuid, resource_type, revision_number)
    db_func = session.merge if may_exist else session.add
    with session.begin(subtransactions=True):
        std_attr_id = _get_standard_attr_id(session, resource_uuid,
                                            resource_type)
        row = models.OVNRevisionNumbers(resource_uuid=resource_uuid,
                                        resource_type=resource_type,
                                        standard_attr_id=std_attr_id,
                                        revision_number=revision_number)
        db_func(row)