Merge "db: Use context, session args for metadef DB APIs"
This commit is contained in:
commit
8593179896
@ -2092,7 +2092,7 @@ def metadef_namespace_get(context, namespace_name):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_namespace_api.get(
|
||||
context, namespace_name, session)
|
||||
context, session, namespace_name)
|
||||
|
||||
|
||||
@utils.no_4byte_params
|
||||
@ -2100,7 +2100,7 @@ def metadef_namespace_create(context, values):
|
||||
"""Create a namespace or raise if it already exists."""
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_namespace_api.create(context, values, session)
|
||||
return metadef_namespace_api.create(context, session, values)
|
||||
|
||||
|
||||
@utils.no_4byte_params
|
||||
@ -2109,7 +2109,7 @@ def metadef_namespace_update(context, namespace_id, namespace_dict):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_namespace_api.update(
|
||||
context, namespace_id, namespace_dict, session)
|
||||
context, session, namespace_id, namespace_dict)
|
||||
|
||||
|
||||
def metadef_namespace_delete(context, namespace_name):
|
||||
@ -2117,7 +2117,7 @@ def metadef_namespace_delete(context, namespace_name):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_namespace_api.delete_cascade(
|
||||
context, namespace_name, session)
|
||||
context, session, namespace_name)
|
||||
|
||||
|
||||
def metadef_object_get_all(context, namespace_name):
|
||||
@ -2125,7 +2125,7 @@ def metadef_object_get_all(context, namespace_name):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_object_api.get_all(
|
||||
context, namespace_name, session)
|
||||
context, session, namespace_name)
|
||||
|
||||
|
||||
def metadef_object_get(context, namespace_name, object_name):
|
||||
@ -2133,7 +2133,7 @@ def metadef_object_get(context, namespace_name, object_name):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_object_api.get(
|
||||
context, namespace_name, object_name, session)
|
||||
context, session, namespace_name, object_name)
|
||||
|
||||
|
||||
@utils.no_4byte_params
|
||||
@ -2142,7 +2142,7 @@ def metadef_object_create(context, namespace_name, object_dict):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_object_api.create(
|
||||
context, namespace_name, object_dict, session)
|
||||
context, session, namespace_name, object_dict)
|
||||
|
||||
|
||||
@utils.no_4byte_params
|
||||
@ -2151,7 +2151,7 @@ def metadef_object_update(context, namespace_name, object_id, object_dict):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_object_api.update(
|
||||
context, namespace_name, object_id, object_dict, session)
|
||||
context, session, namespace_name, object_id, object_dict)
|
||||
|
||||
|
||||
def metadef_object_delete(context, namespace_name, object_name):
|
||||
@ -2159,7 +2159,7 @@ def metadef_object_delete(context, namespace_name, object_name):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_object_api.delete(
|
||||
context, namespace_name, object_name, session)
|
||||
context, session, namespace_name, object_name)
|
||||
|
||||
|
||||
def metadef_object_delete_namespace_content(context, namespace_name):
|
||||
@ -2167,21 +2167,21 @@ def metadef_object_delete_namespace_content(context, namespace_name):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_object_api.delete_by_namespace_name(
|
||||
context, namespace_name, session)
|
||||
context, session, namespace_name)
|
||||
|
||||
|
||||
def metadef_object_count(context, namespace_name):
|
||||
"""Get count of properties for a namespace, raise if ns doesn't exist."""
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_object_api.count(context, namespace_name, session)
|
||||
return metadef_object_api.count(context, session, namespace_name)
|
||||
|
||||
|
||||
def metadef_property_get_all(context, namespace_name):
|
||||
"""Get a metadef property or raise if it does not exist."""
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_property_api.get_all(context, namespace_name, session)
|
||||
return metadef_property_api.get_all(context, session, namespace_name)
|
||||
|
||||
|
||||
def metadef_property_get(context, namespace_name, property_name):
|
||||
@ -2189,7 +2189,7 @@ def metadef_property_get(context, namespace_name, property_name):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_property_api.get(
|
||||
context, namespace_name, property_name, session)
|
||||
context, session, namespace_name, property_name)
|
||||
|
||||
|
||||
@utils.no_4byte_params
|
||||
@ -2198,7 +2198,7 @@ def metadef_property_create(context, namespace_name, property_dict):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_property_api.create(
|
||||
context, namespace_name, property_dict, session)
|
||||
context, session, namespace_name, property_dict)
|
||||
|
||||
|
||||
@utils.no_4byte_params
|
||||
@ -2208,7 +2208,7 @@ def metadef_property_update(context, namespace_name, property_id,
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_property_api.update(
|
||||
context, namespace_name, property_id, property_dict, session)
|
||||
context, session, namespace_name, property_id, property_dict)
|
||||
|
||||
|
||||
def metadef_property_delete(context, namespace_name, property_name):
|
||||
@ -2216,7 +2216,7 @@ def metadef_property_delete(context, namespace_name, property_name):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_property_api.delete(
|
||||
context, namespace_name, property_name, session)
|
||||
context, session, namespace_name, property_name)
|
||||
|
||||
|
||||
def metadef_property_delete_namespace_content(context, namespace_name):
|
||||
@ -2224,14 +2224,14 @@ def metadef_property_delete_namespace_content(context, namespace_name):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_property_api.delete_by_namespace_name(
|
||||
context, namespace_name, session)
|
||||
context, session, namespace_name)
|
||||
|
||||
|
||||
def metadef_property_count(context, namespace_name):
|
||||
"""Get count of properties for a namespace, raise if ns doesn't exist."""
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_property_api.count(context, namespace_name, session)
|
||||
return metadef_property_api.count(context, session, namespace_name)
|
||||
|
||||
|
||||
def metadef_resource_type_create(context, values):
|
||||
@ -2239,7 +2239,7 @@ def metadef_resource_type_create(context, values):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_resource_type_api.create(
|
||||
context, values, session)
|
||||
context, session, values)
|
||||
|
||||
|
||||
def metadef_resource_type_get(context, resource_type_name):
|
||||
@ -2247,7 +2247,7 @@ def metadef_resource_type_get(context, resource_type_name):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_resource_type_api.get(
|
||||
context, resource_type_name, session)
|
||||
context, session, resource_type_name)
|
||||
|
||||
|
||||
def metadef_resource_type_get_all(context):
|
||||
@ -2262,7 +2262,7 @@ def metadef_resource_type_delete(context, resource_type_name):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_resource_type_api.delete(
|
||||
context, resource_type_name, session)
|
||||
context, session, resource_type_name)
|
||||
|
||||
|
||||
def metadef_resource_type_association_get(
|
||||
@ -2271,7 +2271,7 @@ def metadef_resource_type_association_get(
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_association_api.get(
|
||||
context, namespace_name, resource_type_name, session)
|
||||
context, session, namespace_name, resource_type_name)
|
||||
|
||||
|
||||
def metadef_resource_type_association_create(
|
||||
@ -2280,7 +2280,7 @@ def metadef_resource_type_association_create(
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_association_api.create(
|
||||
context, namespace_name, values, session)
|
||||
context, session, namespace_name, values)
|
||||
|
||||
|
||||
def metadef_resource_type_association_delete(
|
||||
@ -2289,7 +2289,7 @@ def metadef_resource_type_association_delete(
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_association_api.delete(
|
||||
context, namespace_name, resource_type_name, session)
|
||||
context, session, namespace_name, resource_type_name)
|
||||
|
||||
|
||||
def metadef_resource_type_association_get_all_by_namespace(
|
||||
@ -2298,7 +2298,7 @@ def metadef_resource_type_association_get_all_by_namespace(
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_association_api.get_all_by_namespace(
|
||||
context, namespace_name, session)
|
||||
context, session, namespace_name)
|
||||
|
||||
|
||||
def metadef_tag_get_all(
|
||||
@ -2309,7 +2309,7 @@ def metadef_tag_get_all(
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_tag_api.get_all(
|
||||
context, namespace_name, session,
|
||||
context, session, namespace_name,
|
||||
filters, marker, limit, sort_key, sort_dir)
|
||||
|
||||
|
||||
@ -2318,7 +2318,7 @@ def metadef_tag_get(context, namespace_name, name):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_tag_api.get(
|
||||
context, namespace_name, name, session)
|
||||
context, session, namespace_name, name)
|
||||
|
||||
|
||||
@utils.no_4byte_params
|
||||
@ -2327,7 +2327,7 @@ def metadef_tag_create(context, namespace_name, tag_dict):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_tag_api.create(
|
||||
context, namespace_name, tag_dict, session)
|
||||
context, session, namespace_name, tag_dict)
|
||||
|
||||
|
||||
def metadef_tag_create_tags(context, namespace_name, tag_list,
|
||||
@ -2336,7 +2336,7 @@ def metadef_tag_create_tags(context, namespace_name, tag_list,
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_tag_api.create_tags(
|
||||
context, namespace_name, tag_list, can_append, session)
|
||||
context, session, namespace_name, tag_list, can_append)
|
||||
|
||||
|
||||
@utils.no_4byte_params
|
||||
@ -2345,7 +2345,7 @@ def metadef_tag_update(context, namespace_name, id, tag_dict):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_tag_api.update(
|
||||
context, namespace_name, id, tag_dict, session)
|
||||
context, session, namespace_name, id, tag_dict)
|
||||
|
||||
|
||||
def metadef_tag_delete(context, namespace_name, name):
|
||||
@ -2353,7 +2353,7 @@ def metadef_tag_delete(context, namespace_name, name):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_tag_api.delete(
|
||||
context, namespace_name, name, session)
|
||||
context, session, namespace_name, name)
|
||||
|
||||
|
||||
def metadef_tag_delete_namespace_content(context, namespace_name):
|
||||
@ -2361,11 +2361,11 @@ def metadef_tag_delete_namespace_content(context, namespace_name):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_tag_api.delete_by_namespace_name(
|
||||
context, namespace_name, session)
|
||||
context, session, namespace_name)
|
||||
|
||||
|
||||
def metadef_tag_count(context, namespace_name):
|
||||
"""Get count of tags for a namespace, raise if ns doesn't exist."""
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return metadef_tag_api.count(context, namespace_name, session)
|
||||
return metadef_tag_api.count(context, session, namespace_name)
|
||||
|
@ -77,7 +77,7 @@ def _select_namespaces_query(context, session):
|
||||
return query
|
||||
|
||||
|
||||
def _get(context, namespace_id, session):
|
||||
def _get(context, session, namespace_id):
|
||||
"""Get a namespace by id, raise if not found"""
|
||||
|
||||
try:
|
||||
@ -101,7 +101,7 @@ def _get(context, namespace_id, session):
|
||||
return namespace_rec
|
||||
|
||||
|
||||
def _get_by_name(context, name, session):
|
||||
def _get_by_name(context, session, name):
|
||||
"""Get a namespace by name, raise if not found"""
|
||||
|
||||
try:
|
||||
@ -150,7 +150,7 @@ def _get_all(context, session, filters=None, marker=None,
|
||||
|
||||
marker_namespace = None
|
||||
if marker is not None:
|
||||
marker_namespace = _get(context, marker, session)
|
||||
marker_namespace = _get(context, session, marker)
|
||||
|
||||
sort_keys = ['created_at', 'id']
|
||||
sort_keys.insert(0, sort_key) if sort_key not in sort_keys else sort_keys
|
||||
@ -211,13 +211,13 @@ def get_all(context, session, marker=None, limit=None,
|
||||
return [ns.to_dict() for ns in namespaces]
|
||||
|
||||
|
||||
def get(context, name, session):
|
||||
def get(context, session, name):
|
||||
"""Get a namespace by name, raise if not found"""
|
||||
namespace_rec = _get_by_name(context, name, session)
|
||||
namespace_rec = _get_by_name(context, session, name)
|
||||
return namespace_rec.to_dict()
|
||||
|
||||
|
||||
def create(context, values, session):
|
||||
def create(context, session, values):
|
||||
"""Create a namespace, raise if namespace already exists."""
|
||||
|
||||
namespace_name = values['namespace']
|
||||
@ -235,10 +235,10 @@ def create(context, values, session):
|
||||
return namespace.to_dict()
|
||||
|
||||
|
||||
def update(context, namespace_id, values, session):
|
||||
def update(context, session, namespace_id, values):
|
||||
"""Update a namespace, raise if not found/visible or duplicate result"""
|
||||
|
||||
namespace_rec = _get(context, namespace_id, session)
|
||||
namespace_rec = _get(context, session, namespace_id)
|
||||
metadef_api.utils.drop_protected_attrs(models.MetadefNamespace, values)
|
||||
|
||||
try:
|
||||
@ -256,10 +256,10 @@ def update(context, namespace_id, values, session):
|
||||
return namespace_rec.to_dict()
|
||||
|
||||
|
||||
def delete(context, name, session):
|
||||
def delete(context, session, name):
|
||||
"""Raise if not found, has references or not visible"""
|
||||
|
||||
namespace_rec = _get_by_name(context, name, session)
|
||||
namespace_rec = _get_by_name(context, session, name)
|
||||
try:
|
||||
session.delete(namespace_rec)
|
||||
session.flush()
|
||||
@ -275,19 +275,19 @@ def delete(context, name, session):
|
||||
return namespace_rec.to_dict()
|
||||
|
||||
|
||||
def delete_cascade(context, name, session):
|
||||
def delete_cascade(context, session, name):
|
||||
"""Raise if not found, has references or not visible"""
|
||||
|
||||
namespace_rec = _get_by_name(context, name, session)
|
||||
namespace_rec = _get_by_name(context, session, name)
|
||||
try:
|
||||
metadef_api.tag.delete_namespace_content(
|
||||
context, namespace_rec.id, session)
|
||||
context, session, namespace_rec.id)
|
||||
metadef_api.object.delete_namespace_content(
|
||||
context, namespace_rec.id, session)
|
||||
context, session, namespace_rec.id)
|
||||
metadef_api.property.delete_namespace_content(
|
||||
context, namespace_rec.id, session)
|
||||
context, session, namespace_rec.id)
|
||||
metadef_api.resource_type_association.delete_namespace_content(
|
||||
context, namespace_rec.id, session)
|
||||
context, session, namespace_rec.id)
|
||||
session.delete(namespace_rec)
|
||||
session.flush()
|
||||
except db_exc.DBError as e:
|
||||
|
@ -27,7 +27,7 @@ from glance.i18n import _
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _get(context, object_id, session):
|
||||
def _get(context, session, object_id):
|
||||
try:
|
||||
query = session.query(models.MetadefObject).filter_by(id=object_id)
|
||||
metadef_object = query.one()
|
||||
@ -40,8 +40,8 @@ def _get(context, object_id, session):
|
||||
return metadef_object
|
||||
|
||||
|
||||
def _get_by_name(context, namespace_name, name, session):
|
||||
namespace = namespace_api.get(context, namespace_name, session)
|
||||
def _get_by_name(context, session, namespace_name, name):
|
||||
namespace = namespace_api.get(context, session, namespace_name)
|
||||
try:
|
||||
query = session.query(models.MetadefObject).filter_by(
|
||||
name=name, namespace_id=namespace['id'])
|
||||
@ -56,8 +56,8 @@ def _get_by_name(context, namespace_name, name, session):
|
||||
return metadef_object
|
||||
|
||||
|
||||
def get_all(context, namespace_name, session):
|
||||
namespace = namespace_api.get(context, namespace_name, session)
|
||||
def get_all(context, session, namespace_name):
|
||||
namespace = namespace_api.get(context, session, namespace_name)
|
||||
query = session.query(models.MetadefObject).filter_by(
|
||||
namespace_id=namespace['id'])
|
||||
md_objects = query.all()
|
||||
@ -68,8 +68,8 @@ def get_all(context, namespace_name, session):
|
||||
return md_objects_list
|
||||
|
||||
|
||||
def create(context, namespace_name, values, session):
|
||||
namespace = namespace_api.get(context, namespace_name, session)
|
||||
def create(context, session, namespace_name, values):
|
||||
namespace = namespace_api.get(context, session, namespace_name)
|
||||
values.update({'namespace_id': namespace['id']})
|
||||
|
||||
md_object = models.MetadefObject()
|
||||
@ -88,17 +88,17 @@ def create(context, namespace_name, values, session):
|
||||
return md_object.to_dict()
|
||||
|
||||
|
||||
def get(context, namespace_name, name, session):
|
||||
md_object = _get_by_name(context, namespace_name, name, session)
|
||||
def get(context, session, namespace_name, name):
|
||||
md_object = _get_by_name(context, session, namespace_name, name)
|
||||
|
||||
return md_object.to_dict()
|
||||
|
||||
|
||||
def update(context, namespace_name, object_id, values, session):
|
||||
def update(context, session, namespace_name, object_id, values):
|
||||
"""Update an object, raise if ns not found/visible or duplicate result"""
|
||||
namespace_api.get(context, namespace_name, session)
|
||||
namespace_api.get(context, session, namespace_name)
|
||||
|
||||
md_object = _get(context, object_id, session)
|
||||
md_object = _get(context, session, object_id)
|
||||
metadef_utils.drop_protected_attrs(models.MetadefObject, values)
|
||||
# values['updated_at'] = timeutils.utcnow() - done by TS mixin
|
||||
try:
|
||||
@ -118,9 +118,9 @@ def update(context, namespace_name, object_id, values, session):
|
||||
return md_object.to_dict()
|
||||
|
||||
|
||||
def delete(context, namespace_name, object_name, session):
|
||||
namespace_api.get(context, namespace_name, session)
|
||||
md_object = _get_by_name(context, namespace_name, object_name, session)
|
||||
def delete(context, session, namespace_name, object_name):
|
||||
namespace_api.get(context, session, namespace_name)
|
||||
md_object = _get_by_name(context, session, namespace_name, object_name)
|
||||
|
||||
session.delete(md_object)
|
||||
session.flush()
|
||||
@ -128,7 +128,7 @@ def delete(context, namespace_name, object_name, session):
|
||||
return md_object.to_dict()
|
||||
|
||||
|
||||
def delete_namespace_content(context, namespace_id, session):
|
||||
def delete_namespace_content(context, session, namespace_id):
|
||||
"""Use this def only if the ns for the id has been verified as visible"""
|
||||
|
||||
count = 0
|
||||
@ -138,14 +138,14 @@ def delete_namespace_content(context, namespace_id, session):
|
||||
return count
|
||||
|
||||
|
||||
def delete_by_namespace_name(context, namespace_name, session):
|
||||
namespace = namespace_api.get(context, namespace_name, session)
|
||||
return delete_namespace_content(context, namespace['id'], session)
|
||||
def delete_by_namespace_name(context, session, namespace_name):
|
||||
namespace = namespace_api.get(context, session, namespace_name)
|
||||
return delete_namespace_content(context, session, namespace['id'])
|
||||
|
||||
|
||||
def count(context, namespace_name, session):
|
||||
def count(context, session, namespace_name):
|
||||
"""Get the count of objects for a namespace, raise if ns not found"""
|
||||
namespace = namespace_api.get(context, namespace_name, session)
|
||||
namespace = namespace_api.get(context, session, namespace_name)
|
||||
|
||||
query = session.query(func.count(models.MetadefObject.id)).filter_by(
|
||||
namespace_id=namespace['id'])
|
||||
|
@ -27,7 +27,7 @@ from glance.i18n import _
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _get(context, property_id, session):
|
||||
def _get(context, session, property_id):
|
||||
|
||||
try:
|
||||
query = session.query(models.MetadefProperty).filter_by(id=property_id)
|
||||
@ -42,10 +42,10 @@ def _get(context, property_id, session):
|
||||
return property_rec
|
||||
|
||||
|
||||
def _get_by_name(context, namespace_name, name, session):
|
||||
def _get_by_name(context, session, namespace_name, name):
|
||||
"""get a property; raise if ns not found/visible or property not found"""
|
||||
|
||||
namespace = namespace_api.get(context, namespace_name, session)
|
||||
namespace = namespace_api.get(context, session, namespace_name)
|
||||
try:
|
||||
query = session.query(models.MetadefProperty).filter_by(
|
||||
name=name, namespace_id=namespace['id'])
|
||||
@ -61,15 +61,15 @@ def _get_by_name(context, namespace_name, name, session):
|
||||
return property_rec
|
||||
|
||||
|
||||
def get(context, namespace_name, name, session):
|
||||
def get(context, session, namespace_name, name):
|
||||
"""get a property; raise if ns not found/visible or property not found"""
|
||||
|
||||
property_rec = _get_by_name(context, namespace_name, name, session)
|
||||
property_rec = _get_by_name(context, session, namespace_name, name)
|
||||
return property_rec.to_dict()
|
||||
|
||||
|
||||
def get_all(context, namespace_name, session):
|
||||
namespace = namespace_api.get(context, namespace_name, session)
|
||||
def get_all(context, session, namespace_name):
|
||||
namespace = namespace_api.get(context, session, namespace_name)
|
||||
query = session.query(models.MetadefProperty).filter_by(
|
||||
namespace_id=namespace['id'])
|
||||
properties = query.all()
|
||||
@ -80,8 +80,8 @@ def get_all(context, namespace_name, session):
|
||||
return properties_list
|
||||
|
||||
|
||||
def create(context, namespace_name, values, session):
|
||||
namespace = namespace_api.get(context, namespace_name, session)
|
||||
def create(context, session, namespace_name, values):
|
||||
namespace = namespace_api.get(context, session, namespace_name)
|
||||
values.update({'namespace_id': namespace['id']})
|
||||
|
||||
property_rec = models.MetadefProperty()
|
||||
@ -103,11 +103,11 @@ def create(context, namespace_name, values, session):
|
||||
return property_rec.to_dict()
|
||||
|
||||
|
||||
def update(context, namespace_name, property_id, values, session):
|
||||
def update(context, session, namespace_name, property_id, values):
|
||||
"""Update a property, raise if ns not found/visible or duplicate result"""
|
||||
|
||||
namespace_api.get(context, namespace_name, session)
|
||||
property_rec = _get(context, property_id, session)
|
||||
namespace_api.get(context, session, namespace_name)
|
||||
property_rec = _get(context, session, property_id)
|
||||
metadef_utils.drop_protected_attrs(models.MetadefProperty, values)
|
||||
# values['updated_at'] = timeutils.utcnow() - done by TS mixin
|
||||
try:
|
||||
@ -129,9 +129,9 @@ def update(context, namespace_name, property_id, values, session):
|
||||
return property_rec.to_dict()
|
||||
|
||||
|
||||
def delete(context, namespace_name, property_name, session):
|
||||
def delete(context, session, namespace_name, property_name):
|
||||
property_rec = _get_by_name(
|
||||
context, namespace_name, property_name, session)
|
||||
context, session, namespace_name, property_name)
|
||||
if property_rec:
|
||||
session.delete(property_rec)
|
||||
session.flush()
|
||||
@ -139,7 +139,7 @@ def delete(context, namespace_name, property_name, session):
|
||||
return property_rec.to_dict()
|
||||
|
||||
|
||||
def delete_namespace_content(context, namespace_id, session):
|
||||
def delete_namespace_content(context, session, namespace_id):
|
||||
"""Use this def only if the ns for the id has been verified as visible"""
|
||||
|
||||
count = 0
|
||||
@ -149,15 +149,15 @@ def delete_namespace_content(context, namespace_id, session):
|
||||
return count
|
||||
|
||||
|
||||
def delete_by_namespace_name(context, namespace_name, session):
|
||||
namespace = namespace_api.get(context, namespace_name, session)
|
||||
return delete_namespace_content(context, namespace['id'], session)
|
||||
def delete_by_namespace_name(context, session, namespace_name):
|
||||
namespace = namespace_api.get(context, session, namespace_name)
|
||||
return delete_namespace_content(context, session, namespace['id'])
|
||||
|
||||
|
||||
def count(context, namespace_name, session):
|
||||
def count(context, session, namespace_name):
|
||||
"""Get the count of properties for a namespace, raise if ns not found"""
|
||||
|
||||
namespace = namespace_api.get(context, namespace_name, session)
|
||||
namespace = namespace_api.get(context, session, namespace_name)
|
||||
|
||||
query = session.query(func.count(models.MetadefProperty.id)).filter_by(
|
||||
namespace_id=namespace['id'])
|
||||
|
@ -25,7 +25,7 @@ from glance.db.sqlalchemy import models_metadef as models
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get(context, name, session):
|
||||
def get(context, session, name):
|
||||
"""Get a resource type, raise if not found"""
|
||||
|
||||
try:
|
||||
@ -52,7 +52,7 @@ def get_all(context, session):
|
||||
return resource_types_list
|
||||
|
||||
|
||||
def create(context, values, session):
|
||||
def create(context, session, values):
|
||||
"""Create a resource_type, raise if it already exists."""
|
||||
|
||||
resource_type = models.MetadefResourceType()
|
||||
@ -70,22 +70,22 @@ def create(context, values, session):
|
||||
return resource_type.to_dict()
|
||||
|
||||
|
||||
def update(context, values, session):
|
||||
def update(context, session, values):
|
||||
"""Update a resource type, raise if not found"""
|
||||
|
||||
name = values['name']
|
||||
metadef_utils.drop_protected_attrs(models.MetadefResourceType, values)
|
||||
db_rec = get(context, name, session)
|
||||
db_rec = get(context, session, name)
|
||||
db_rec.update(values.copy())
|
||||
db_rec.save(session=session)
|
||||
|
||||
return db_rec.to_dict()
|
||||
|
||||
|
||||
def delete(context, name, session):
|
||||
def delete(context, session, name):
|
||||
"""Delete a resource type or raise if not found or is protected"""
|
||||
|
||||
db_rec = get(context, name, session)
|
||||
db_rec = get(context, session, name)
|
||||
if db_rec.protected is True:
|
||||
LOG.debug("Delete forbidden. Metadata definition resource-type %s is a"
|
||||
" seeded-system type and can not be deleted.", name)
|
||||
|
@ -56,8 +56,8 @@ def _set_model_dict(resource_type_name, properties_target, prefix,
|
||||
return model_dict
|
||||
|
||||
|
||||
def _get(context, namespace_name, resource_type_name,
|
||||
namespace_id, resource_type_id, session):
|
||||
def _get(context, session, namespace_name, resource_type_name,
|
||||
namespace_id, resource_type_id):
|
||||
"""Get a namespace resource_type association"""
|
||||
|
||||
# visibility check assumed done in calling routine via namespace_get
|
||||
@ -79,7 +79,8 @@ def _get(context, namespace_name, resource_type_name,
|
||||
|
||||
|
||||
def _create_association(
|
||||
context, namespace_name, resource_type_name, values, session):
|
||||
context, session, namespace_name, resource_type_name, values,
|
||||
):
|
||||
"""Create an association, raise if it already exists."""
|
||||
|
||||
namespace_resource_type_rec = models.MetadefNamespaceResourceType()
|
||||
@ -102,38 +103,40 @@ def _create_association(
|
||||
return namespace_resource_type_rec.to_dict()
|
||||
|
||||
|
||||
def _delete(context, namespace_name, resource_type_name,
|
||||
namespace_id, resource_type_id, session):
|
||||
def _delete(context, session, namespace_name, resource_type_name,
|
||||
namespace_id, resource_type_id):
|
||||
"""Delete a resource type association or raise if not found."""
|
||||
|
||||
db_rec = _get(context, namespace_name, resource_type_name,
|
||||
namespace_id, resource_type_id, session)
|
||||
db_rec = _get(
|
||||
context, session, namespace_name, resource_type_name,
|
||||
namespace_id, resource_type_id)
|
||||
session.delete(db_rec)
|
||||
session.flush()
|
||||
|
||||
return db_rec.to_dict()
|
||||
|
||||
|
||||
def get(context, namespace_name, resource_type_name, session):
|
||||
def get(context, session, namespace_name, resource_type_name):
|
||||
"""Get a resource_type associations; raise if not found"""
|
||||
namespace = namespace_api.get(
|
||||
context, namespace_name, session)
|
||||
context, session, namespace_name)
|
||||
|
||||
resource_type = resource_type_api.get(
|
||||
context, resource_type_name, session)
|
||||
context, session, resource_type_name)
|
||||
|
||||
found = _get(context, namespace_name, resource_type_name,
|
||||
namespace['id'], resource_type['id'], session)
|
||||
found = _get(
|
||||
context, session, namespace_name, resource_type_name,
|
||||
namespace['id'], resource_type['id'])
|
||||
|
||||
return _to_model_dict(resource_type_name, found)
|
||||
|
||||
|
||||
def get_all_by_namespace(context, namespace_name, session):
|
||||
def get_all_by_namespace(context, session, namespace_name):
|
||||
"""List resource_type associations by namespace, raise if not found"""
|
||||
|
||||
# namespace get raises an exception if not visible
|
||||
namespace = namespace_api.get(
|
||||
context, namespace_name, session)
|
||||
context, session, namespace_name)
|
||||
|
||||
db_recs = (
|
||||
session.query(models.MetadefResourceType)
|
||||
@ -158,11 +161,11 @@ def get_all_by_namespace(context, namespace_name, session):
|
||||
return model_dict_list
|
||||
|
||||
|
||||
def create(context, namespace_name, values, session):
|
||||
def create(context, session, namespace_name, values):
|
||||
"""Create an association, raise if already exists or ns not found."""
|
||||
|
||||
namespace = namespace_api.get(
|
||||
context, namespace_name, session)
|
||||
context, session, namespace_name)
|
||||
|
||||
# if the resource_type does not exist, create it
|
||||
resource_type_name = values['name']
|
||||
@ -170,7 +173,7 @@ def create(context, namespace_name, values, session):
|
||||
models.MetadefNamespaceResourceType, values)
|
||||
try:
|
||||
resource_type = resource_type_api.get(
|
||||
context, resource_type_name, session)
|
||||
context, session, resource_type_name)
|
||||
except exc.NotFound:
|
||||
resource_type = None
|
||||
LOG.debug("Creating resource-type %s", resource_type_name)
|
||||
@ -178,33 +181,35 @@ def create(context, namespace_name, values, session):
|
||||
if resource_type is None:
|
||||
resource_type_dict = {'name': resource_type_name, 'protected': False}
|
||||
resource_type = resource_type_api.create(
|
||||
context, resource_type_dict, session)
|
||||
context, session, resource_type_dict)
|
||||
|
||||
# Create the association record, set the field values
|
||||
ns_resource_type_dict = _to_db_dict(
|
||||
namespace['id'], resource_type['id'], values)
|
||||
new_rec = _create_association(context, namespace_name, resource_type_name,
|
||||
ns_resource_type_dict, session)
|
||||
new_rec = _create_association(
|
||||
context, session, namespace_name, resource_type_name,
|
||||
ns_resource_type_dict)
|
||||
|
||||
return _to_model_dict(resource_type_name, new_rec)
|
||||
|
||||
|
||||
def delete(context, namespace_name, resource_type_name, session):
|
||||
def delete(context, session, namespace_name, resource_type_name):
|
||||
"""Delete an association or raise if not found"""
|
||||
|
||||
namespace = namespace_api.get(
|
||||
context, namespace_name, session)
|
||||
context, session, namespace_name)
|
||||
|
||||
resource_type = resource_type_api.get(
|
||||
context, resource_type_name, session)
|
||||
context, session, resource_type_name)
|
||||
|
||||
deleted = _delete(context, namespace_name, resource_type_name,
|
||||
namespace['id'], resource_type['id'], session)
|
||||
deleted = _delete(
|
||||
context, session, namespace_name, resource_type_name,
|
||||
namespace['id'], resource_type['id'])
|
||||
|
||||
return _to_model_dict(resource_type_name, deleted)
|
||||
|
||||
|
||||
def delete_namespace_content(context, namespace_id, session):
|
||||
def delete_namespace_content(context, session, namespace_id):
|
||||
"""Use this def only if the ns for the id has been verified as visible"""
|
||||
|
||||
count = 0
|
||||
|
@ -28,7 +28,7 @@ from glance.i18n import _LW
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _get(context, id, session):
|
||||
def _get(context, session, id):
|
||||
try:
|
||||
query = (session.query(models.MetadefTag).filter_by(id=id))
|
||||
metadef_tag = query.one()
|
||||
@ -39,8 +39,8 @@ def _get(context, id, session):
|
||||
return metadef_tag
|
||||
|
||||
|
||||
def _get_by_name(context, namespace_name, name, session):
|
||||
namespace = namespace_api.get(context, namespace_name, session)
|
||||
def _get_by_name(context, session, namespace_name, name):
|
||||
namespace = namespace_api.get(context, session, namespace_name)
|
||||
try:
|
||||
query = (session.query(models.MetadefTag).filter_by(
|
||||
name=name, namespace_id=namespace['id']))
|
||||
@ -54,7 +54,7 @@ def _get_by_name(context, namespace_name, name, session):
|
||||
return metadef_tag
|
||||
|
||||
|
||||
def get_all(context, namespace_name, session, filters=None, marker=None,
|
||||
def get_all(context, session, namespace_name, filters=None, marker=None,
|
||||
limit=None, sort_key='created_at', sort_dir='desc'):
|
||||
"""Get all tags that match zero or more filters.
|
||||
|
||||
@ -65,13 +65,13 @@ def get_all(context, namespace_name, session, filters=None, marker=None,
|
||||
:param sort_dir: direction in which results should be sorted (asc, desc)
|
||||
"""
|
||||
|
||||
namespace = namespace_api.get(context, namespace_name, session)
|
||||
namespace = namespace_api.get(context, session, namespace_name)
|
||||
query = (session.query(models.MetadefTag).filter_by(
|
||||
namespace_id=namespace['id']))
|
||||
|
||||
marker_tag = None
|
||||
if marker is not None:
|
||||
marker_tag = _get(context, marker, session)
|
||||
marker_tag = _get(context, session, marker)
|
||||
|
||||
sort_keys = ['created_at', 'id']
|
||||
sort_keys.insert(0, sort_key) if sort_key not in sort_keys else sort_keys
|
||||
@ -89,8 +89,8 @@ def get_all(context, namespace_name, session, filters=None, marker=None,
|
||||
return metadef_tag_list
|
||||
|
||||
|
||||
def create(context, namespace_name, values, session):
|
||||
namespace = namespace_api.get(context, namespace_name, session)
|
||||
def create(context, session, namespace_name, values):
|
||||
namespace = namespace_api.get(context, session, namespace_name)
|
||||
values.update({'namespace_id': namespace['id']})
|
||||
|
||||
metadef_tag = models.MetadefTag()
|
||||
@ -111,11 +111,11 @@ def create(context, namespace_name, values, session):
|
||||
return metadef_tag.to_dict()
|
||||
|
||||
|
||||
def create_tags(context, namespace_name, tag_list, can_append, session):
|
||||
def create_tags(context, session, namespace_name, tag_list, can_append):
|
||||
|
||||
metadef_tags_list = []
|
||||
if tag_list:
|
||||
namespace = namespace_api.get(context, namespace_name, session)
|
||||
namespace = namespace_api.get(context, session, namespace_name)
|
||||
|
||||
try:
|
||||
if not can_append:
|
||||
@ -141,16 +141,16 @@ def create_tags(context, namespace_name, tag_list, can_append, session):
|
||||
return metadef_tags_list
|
||||
|
||||
|
||||
def get(context, namespace_name, name, session):
|
||||
metadef_tag = _get_by_name(context, namespace_name, name, session)
|
||||
def get(context, session, namespace_name, name):
|
||||
metadef_tag = _get_by_name(context, session, namespace_name, name)
|
||||
return metadef_tag.to_dict()
|
||||
|
||||
|
||||
def update(context, namespace_name, id, values, session):
|
||||
def update(context, session, namespace_name, id, values):
|
||||
"""Update an tag, raise if ns not found/visible or duplicate result"""
|
||||
namespace_api.get(context, namespace_name, session)
|
||||
namespace_api.get(context, session, namespace_name)
|
||||
|
||||
metadata_tag = _get(context, id, session)
|
||||
metadata_tag = _get(context, session, id)
|
||||
metadef_utils.drop_protected_attrs(models.MetadefTag, values)
|
||||
# values['updated_at'] = timeutils.utcnow() - done by TS mixin
|
||||
try:
|
||||
@ -168,9 +168,9 @@ def update(context, namespace_name, id, values, session):
|
||||
return metadata_tag.to_dict()
|
||||
|
||||
|
||||
def delete(context, namespace_name, name, session):
|
||||
namespace_api.get(context, namespace_name, session)
|
||||
md_tag = _get_by_name(context, namespace_name, name, session)
|
||||
def delete(context, session, namespace_name, name):
|
||||
namespace_api.get(context, session, namespace_name)
|
||||
md_tag = _get_by_name(context, session, namespace_name, name)
|
||||
|
||||
session.delete(md_tag)
|
||||
session.flush()
|
||||
@ -178,7 +178,7 @@ def delete(context, namespace_name, name, session):
|
||||
return md_tag.to_dict()
|
||||
|
||||
|
||||
def delete_namespace_content(context, namespace_id, session):
|
||||
def delete_namespace_content(context, session, namespace_id):
|
||||
"""Use this def only if the ns for the id has been verified as visible"""
|
||||
count = 0
|
||||
query = (session.query(models.MetadefTag).filter_by(
|
||||
@ -187,14 +187,14 @@ def delete_namespace_content(context, namespace_id, session):
|
||||
return count
|
||||
|
||||
|
||||
def delete_by_namespace_name(context, namespace_name, session):
|
||||
namespace = namespace_api.get(context, namespace_name, session)
|
||||
return delete_namespace_content(context, namespace['id'], session)
|
||||
def delete_by_namespace_name(context, session, namespace_name):
|
||||
namespace = namespace_api.get(context, session, namespace_name)
|
||||
return delete_namespace_content(context, session, namespace['id'])
|
||||
|
||||
|
||||
def count(context, namespace_name, session):
|
||||
def count(context, session, namespace_name):
|
||||
"""Get the count of objects for a namespace, raise if ns not found"""
|
||||
namespace = namespace_api.get(context, namespace_name, session)
|
||||
namespace = namespace_api.get(context, session, namespace_name)
|
||||
query = (session.query(func.count(models.MetadefTag.id)).filter_by(
|
||||
namespace_id=namespace['id']))
|
||||
return query.scalar()
|
||||
|
Loading…
x
Reference in New Issue
Block a user