Exemple #1
0
 def update_tag(self, context, resource, resource_id, tag):
     res = self._get_resource(context, resource, resource_id)
     if any(tag == tag_db.tag for tag_db in res.standard_attr.tags):
         return
     try:
         tag_obj.Tag(context, standard_attr_id=res.standard_attr_id,
             tag=tag).create()
     except obj_exc.NeutronDbObjectDuplicateEntry:
         pass
Exemple #2
0
 def _save_tag(self, tags, standard_attr_id):
     ctx = context.get_admin_context()
     ret = []
     for tag in tags:
         _tag_obj = tag_obj.Tag(ctx,
                                standard_attr_id=standard_attr_id,
                                tag=tag)
         _tag_obj.create()
         ret.append(_tag_obj)
     return ret
Exemple #3
0
 def update_tags(self, context, resource, resource_id, body):
     with db_api.context_manager.writer.using(context):
         # We get and do all operations with objects in one session
         res = self._get_resource(context, resource, resource_id)
         new_tags = set(body['tags'])
         old_tags = {tag_db.tag for tag_db in res.standard_attr.tags}
         tags_added = new_tags - old_tags
         tags_removed = old_tags - new_tags
         tag_obj.Tag.delete_objects(context, tag=[
             tag_db.tag
             for tag_db in res.standard_attr.tags
             if tag_db.tag in tags_removed
         ])
         for tag in tags_added:
             tag_obj.Tag(context, standard_attr_id=res.standard_attr_id,
                         tag=tag).create()
     return body
Exemple #4
0
 def _save_tag(self, tags, standard_attr_id):
     ctx = context.get_admin_context()
     for tag in tags:
         tag_obj.Tag(ctx, standard_attr_id=standard_attr_id,
                     tag=tag).create()
Exemple #5
0
 def add_tags(self, context, standard_attr_id, tags):
     for tag in tags:
         tag_obj.Tag(context, standard_attr_id=standard_attr_id,
                     tag=tag).create()