Example #1
0
    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
Example #2
0
 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
Example #3
0
    def get_cache_details(self):
        try:
            self.authenticate()
            gc = GenericCache()
            cache_info = gc.get_cache_details()
            return dict(success=True, cache_info=cache_info)

        except Exception as ex:
            print_traceback()
            return dict(success=False, msg=to_str(ex).replace("'", ' '))
Example #4
0
 def remove_entity(self, entity):
     try:
         self.remove_rep(entity)
         self.delete_relations(entity)
         gc = GenericCache()
         gc.on_delete_entity(entity.entity_id, entity.type.name)
         DBHelper().delete(entity)
         
     except Exception as e:
         traceback.print_exc()
         raise e
Example #5
0
    def remove_entity_by_id(self, entityId, entityType=None, parent=None):
        try:
            entity = self.get_entity(entityId, entityType, parent)
            self.remove_rep(entity)
            self.delete_relations(entity)
            gc = GenericCache()
            gc.on_delete_entity(entityId, entity.type.name)
            DBHelper().delete(entity)

        except Exception as e:
            traceback.print_exc()
            raise e
Example #6
0
 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