def edit_server(db: Session, server_id: int, server: ServerEdit) -> Server: db_server = get_server(db, server_id) if not db_server: raise HTTPException(status_code=404, detail="Server not found") updated = server.dict(exclude_unset=True) for key, val in updated.items(): setattr(db_server, key, val) db.add(db_server) db.commit() db.refresh(db_server) return get_server(db, db_server.id)
def edit_server(db: Session, server_id: int, server: ServerEdit, reset_system: bool = False) -> Server: db_server = get_server(db, server_id) if not db_server: raise HTTPException(status_code=404, detail="Server not found") updated = server.dict(exclude_unset=True) for key, val in updated.items(): setattr(db_server, key, val) if (reset_system or server.sudo_password or server.ssh_password or server.ansible_host or server.ansible_user or server.ansible_port): db_server.config["system"] = None db.add(db_server) db.commit() db.refresh(db_server) return get_server(db, db_server.id)