Ejemplo n.º 1
0
def bump_revision(context, resource, resource_type):
    revision_number = ovn_utils.get_revision_number(resource, resource_type)
    with context.session.begin(subtransactions=True):
        _ensure_revision_row_exist(context, resource, resource_type)
        std_attr_id = _get_standard_attr_id(context, resource['id'],
                                            resource_type)
        row = context.session.merge(
            ovn_models.OVNRevisionNumbers(standard_attr_id=std_attr_id,
                                          resource_uuid=resource['id'],
                                          resource_type=resource_type))
        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
        context.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
        })
Ejemplo n.º 2
0
def create_initial_revision(context,
                            resource_uuid,
                            resource_type,
                            revision_number=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 = context.session.merge if may_exist else context.session.add
    with context.session.begin(subtransactions=True):
        std_attr_id = _get_standard_attr_id(context, resource_uuid,
                                            resource_type)
        row = ovn_models.OVNRevisionNumbers(resource_uuid=resource_uuid,
                                            resource_type=resource_type,
                                            standard_attr_id=std_attr_id,
                                            revision_number=revision_number)
        db_func(row)
Ejemplo n.º 3
0
def create_initial_revision(context,
                            resource_uuid,
                            resource_type,
                            revision_number=INITIAL_REV_NUM,
                            may_exist=False,
                            std_attr_id=None):
    LOG.debug('create_initial_revision uuid=%s, type=%s, rev=%s',
              resource_uuid, resource_type, revision_number)
    db_func = context.session.merge if may_exist else context.session.add
    with db_api.CONTEXT_WRITER.using(context):
        std_attr_id = std_attr_id or _get_standard_attr_id(
            context, resource_uuid, resource_type)
        row = ovn_models.OVNRevisionNumbers(resource_uuid=resource_uuid,
                                            resource_type=resource_type,
                                            standard_attr_id=std_attr_id,
                                            revision_number=revision_number)
        db_func(row)
Ejemplo n.º 4
0
def bump_revision(context, resource, resource_type):
    revision_number = ovn_utils.get_revision_number(resource, resource_type)
    with db_api.CONTEXT_WRITER.using(context):
        # NOTE(ralonsoh): "resource" could be a dict or an OVO.
        try:
            std_attr_id = resource.db_obj.standard_attr.id
        except AttributeError:
            std_attr_id = resource.get('standard_attr_id', None)
        _ensure_revision_row_exist(context, resource, resource_type,
                                   std_attr_id)
        std_attr_id = (std_attr_id or _get_standard_attr_id(
            context, resource['id'], resource_type))
        row = context.session.merge(
            ovn_models.OVNRevisionNumbers(standard_attr_id=std_attr_id,
                                          resource_uuid=resource['id'],
                                          resource_type=resource_type))
        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
        context.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
        })