def add_lab_agent(id, agent_id): lab_agent = models.LabAgent(agent_id=agent_id, lab_id=id) db.session.add(lab_agent) db.session.commit() lab = models.Lab.query.filter_by(id=id).first() schema = schemas.LabSchema() return schema.jsonify(lab), 200
def show_labs(): labs_query = ( models.Lab .query .outerjoin(models.LabAgent) .outerjoin(models.Agent)) labs_query = search_model(models.Lab, labs_query) schema = schemas.LabSchema(many=True) return schema.jsonify(labs_query.all()), 200
def show_lab(id): lab = ( models.Lab .query .filter_by(id=id) .outerjoin(models.LabAgent) .outerjoin(models.Agent) .first()) if not lab: raise exceptions.NotFound('Lab not found') schema = schemas.LabSchema() return schema.jsonify(lab), 200
def new_lab(tag_id=None): req = flask.request.json lab = models.Lab(**req) db.session.add(lab) if tag_id: db.session.flush() tag_lab = models.TagLab( tag_id=tag_id, lab_id=lab.id) db.session.add(tag_lab) db.session.commit() schema = schemas.LabSchema() return schema.jsonify(lab), 201
def del_lab_agent(id, agent_id): lab_agent = ( models .LabAgent .query .filter_by(agent_id=agent_id, lab_id=id) .first()) if not lab_agent: raise exceptions.NotFound('Lab <-> agent binding not found') db.session.delete(lab_agent) db.session.commit() engine = models.Lab.query.filter_by(id=id).first() schema = schemas.LabSchema() return schema.jsonify(engine), 204
def change_lab_power(id, state): lab = ( models.Lab .query .filter_by(id=id) .first()) if not lab: raise exceptions.NotFound('Lab not found') lab.power = state.lower() db.session.commit() lab = models.Lab.query.filter_by(id=id).first() schema = schemas.LabSchema() return schema.jsonify(lab), 200