예제 #1
0
 def get(self, session_id):
     session_obj = self.Core.DB.session.query(
         models.Session).get(session_id)
     if session_obj is None:
         raise exceptions.InvalidSessionReference("No session with id: " +
                                                  str(session_id))
     return (self.derive_session_dict(session_obj))
예제 #2
0
 def set_session(self, session_id):
     query = self.db.session.query(models.Session)
     session_obj = query.get(session_id)
     if session_obj is None:
         raise exceptions.InvalidSessionReference("No session with session_id: %s" % str(session_id))
     query.update({'active': False})
     session_obj.active = True
     self.db.session.commit()
예제 #3
0
 def add_target_to_session(self, target_id, session_id=None):
     session_obj = self.db.session.query(models.Session).get(session_id)
     target_obj = self.db.session.query(models.Target).get(target_id)
     if session_obj is None:
         raise exceptions.InvalidSessionReference("No session with id: %s" % str(session_id))
     if target_obj is None:
         raise exceptions.InvalidTargetReference("No target with id: %s" % str(target_id))
     if session_obj not in target_obj.sessions:
         session_obj.targets.append(target_obj)
         self.db.session.commit()
예제 #4
0
 def delete_session(self, session_id):
     session_obj = self.db.session.query(models.Session).get(session_id)
     if session_obj is None:
         raise exceptions.InvalidSessionReference("No session with id: %s" % str(session_id))
     for target in session_obj.targets:
         # Means attached to only this session obj
         if len(target.sessions) == 1:
             self.db.Target.DeleteTarget(ID=target.id)
     self.db.session.delete(session_obj)
     self._ensure_default_session()  # i.e if there are no sessions, add one
     self.db.session.commit()
예제 #5
0
 def remove_target_from_session(self, target_id, session_id=None):
     session_obj = self.db.session.query(models.Session).get(session_id)
     target_obj = self.db.session.query(models.Target).get(target_id)
     if session_obj is None:
         raise exceptions.InvalidSessionReference("No session with id: %s" % str(session_id))
     if target_obj is None:
         raise exceptions.InvalidTargetReference("No target with id: %s" % str(target_id))
     session_obj.targets.remove(target_obj)
     # Delete target whole together if present in this session alone
     if len(target_obj.sessions) == 0:
         self.db.Target.DeleteTarget(ID=target_obj.id)
     self.db.session.commit()