예제 #1
0
파일: Authorization.py 프로젝트: smarkm/ovm
    def add_entity(self, name, entity_id, entityType, parent, context=None, csep_context=None):
        try:
            etype = DBHelper().find_by_name(EntityType, entityType)
            (context_id, csep_context_id) = (None, None)
            if context:
                context_id = self.add_context(context)
            if csep_context:
                csep_context_id = self.add_csep_context(csep_context)

            e = Entity()
            e.name = name
            e.type = etype
            e.entity_id = entity_id
            e.context_id = context_id
            e.csep_context_id = csep_context_id
            if entityType in [constants.SERVER_POOL, constants.MANAGED_NODE, constants.DOMAIN]:
                e.set_ha(parent.ha_registered())
            DBHelper().add(e)
            DBHelper().add(EntityRelation(parent.entity_id, entity_id, u'Children'))
            self.add_rep(e, parent)
            DBSession.flush()
            gc = GenericCache()
            gc.on_add_entity(e.type.name)

        except Exception as ex:
            raise ex
        return e
예제 #2
0
파일: Authorization.py 프로젝트: smarkm/ovm
 def update_entity_by_id(self, entityId, name=None, parent=None, new_entityId=None):
     try:
         entity = self.get_entity(entityId)
         self.update_entity(entity, name=name, parent=parent, new_entityId=new_entityId)
         gc = GenericCache()
         gc.on_add_entity(entity.type.name)
     except Exception as e:
         raise e
예제 #3
0
파일: Authorization.py 프로젝트: smarkm/ovm
 def update_entity(self, entity, name=None, parent=None, new_entityId=None):
     try:
         update_rep = False
         if name is not None:
             entity.name = name
         if parent is not None:
             old_prnt = entity.parents[0]
             if parent not in entity.parents:
                 update_rep = True
             self.delete_entity_relation(old_prnt.entity_id, entity.entity_id, u'Children')
             DBHelper().add(EntityRelation(parent.entity_id, entity.entity_id, u'Children'))
             entity.set_ha(parent.ha_registered())
         if new_entityId is not None:
             entity.entity_id = new_entityId
         DBHelper().add(entity)
         if update_rep:
             self.update_rep(entity, parent)
         gc = GenericCache()
         gc.on_add_entity(entity.type.name)
     except Exception as e:
         traceback.print_exc()
         raise e