def post(self): claims = get_jwt_claims() if not claims['is_admin']: return {'message': 'Admin privilege required.'}, 401 data = _cluster_parser.parse_args() cluster_name = data["cluster_name"] if ClusterModel.find_by_cluster_name(cluster_name): return {'message': f"A cluster with name '{cluster_name}' already exists."}, 400 cluster = ClusterModel(**data) try: cluster.save_to_db() except Exception as e: return {"message": f"An error occurred inserting the cluster. Error: {repr(e)}"}, 500 return cluster.json(), 201
def post(self, name): if ClusterModel.find_by_name(name): return { "message": f"A cluster with name {name} already exists." }, 400 data = Cluster.parser.parse_args() data.update({'name': name}) cluster = ClusterModel(**data) try: cluster.save_to_db() except: return { "message": "An error occurred while creating the cluster." }, 500 return cluster.json(), 201
def put(self): claims = get_jwt_claims() if not claims['is_admin']: return {'message': 'Admin privilege required.'}, 401 data = _cluster_parser.parse_args() for key in data.keys(): if str(data[key]).lower() in ('none', 'null', ''): data[key] = None cluster_name = data["cluster_name"] cluster = ClusterModel.find_by_cluster_name(cluster_name) if cluster: cluster.set_attribute(data) else: cluster = ClusterModel(**data) cluster.save_to_db() return cluster.json()