예제 #1
0
파일: base.py 프로젝트: akaKuruma/simplenet
 def _generic_info_(self, model_name, value):
     model, name = new_model(model_name)
     self.logger.debug("Getting %s info by %s" % (name, value))
     ss = self.session.query(model).filter_by(**value).first()
     if not ss:
         raise EntityNotFound(name, value)
     data = ss.to_dict()
     self.logger.debug("Received %s from [%s]" % (data, value))
     return data
예제 #2
0
파일: base.py 프로젝트: akaKuruma/simplenet
 def _generic_list_by_something_(self, model_name, value):
     model, name = new_model(model_name)
     self.logger.debug("Getting %s by %s" % (name, value))
     ss = self.session.query(model).filter_by(**value).all()
     _values = []
     for _value in ss:
         _values.append(
             _value.to_dict()
         )
     self.logger.debug("Received %s: %s from [%s]" % (name, _values, value))
     return _values
예제 #3
0
파일: base.py 프로젝트: akaKuruma/simplenet
 def _generic_list_(self, model_name):
     model, name = new_model(model_name)
     self.logger.debug("Listing %s" % name)
     ss = self.session.query(model).all()
     _values = []
     for _value in ss:
         _values.append(
             _value.to_dict(),
         )
     self.logger.debug("Received %s: %s" % (name, _values))
     return _values
예제 #4
0
 def policy_list_by_owners(self, ids):
     if ids == []:
         return []
     model, _ = new_model("Policy")
     logger.debug("Getting policies by ids %s" % (ids))
     ss = session.query(model).filter(model.owner_id.in_(ids)).all()
     _values = []
     for _value in ss:
         _values.append(
             _value.to_dict()
         )
     logger.debug("Received: %s from [%s]" % (_values, ids))
     return _values
예제 #5
0
 def policy_ack(self, id):
     _model, _ = new_model("Policy")
     ss = session.query(_model).get(id)
     if not ss:
         logger.error("Policy [%s] could not be acked -- Not Found" % id)
     else:
         session.begin(subtransactions=True)
         try:
             ss.status = "INSERTED"
             session.commit()
         except Exception, e:
             session.rollback()
             raise e
예제 #6
0
파일: base.py 프로젝트: akaKuruma/simplenet
 def _generic_delete_(self, model_name, value):
     model, name = new_model(model_name)
     self.logger.debug("Deleting %s from %s" % (value, name))
     ss = self.session.query(model).filter_by(**value).first()
     if ss is None:
         return
     self.session.begin(subtransactions=True)
     try:
         self.session.delete(ss)
         self.session.commit()
     except Exception, e:
         self.session.rollback()
         raise Exception(e)
예제 #7
0
 def policy_delete(self, owner_type, id):
     logger.debug("Deleting policy %s" % id)
     _model, _ = new_model("%sPolicy" % owner_type.capitalize())
     ss = session.query(_model).get(id)
     if not ss:
         return True
     modified = ss.to_dict()
     owner_id = ss.owner_id
     session.begin(subtransactions=True)
     try:
         session.delete(ss)
         session.commit()
     except Exception, e:
         session.rollback()
         raise Exception(e)
예제 #8
0
    def policy_delete_by_owner(self, owner_type, id):
        _model, _ = new_model("%sPolicy" % owner_type.capitalize())
        ss = session.query(_model).filter_by(**{'owner_id': id}).all()
        if ss:
            session.begin(subtransactions=True)
            try:
                entries = []
                for s in ss:
                    entries.append(s.to_dict())
                    session.delete(s)
                session.commit()
            except Exception, e:
                session.rollback()
                raise Exception(e)

            for modified in entries:
                self._enqueue_rules_(owner_type, id, modified)
예제 #9
0
    def policy_create(self, owner_type, owner_id, data):
        logger.debug("Creating rule on %s: %s using data: %s" %
            (owner_type, owner_id, data)
        )
        data.update({'owner_id': owner_id})
        _model, _ = new_model("%sPolicy" % owner_type.capitalize())
        policy = _model(**data)

        session.begin(subtransactions=True)
        try:
            session.add(policy)
            session.commit()
        except IntegrityError:
            session.rollback()
            raise DuplicatedEntryError('Firewall', "%s already exists" % data)
        except Exception, e:
            session.rollback()
            raise Exception(e)