async def post(self): """ --- summary: Create a new Garden parameters: - name: garden in: body description: The Garden definition to create schema: $ref: '#/definitions/Garden' responses: 201: description: A new Garden has been created schema: $ref: '#/definitions/Garden' 400: $ref: '#/definitions/400Error' 50x: $ref: '#/definitions/50xError' tags: - Garden """ response = await self.client( Operation( operation_type="GARDEN_CREATE", args=[ SchemaParser.parse_garden( self.request.decoded_body, from_string=True ) ], ) ) self.set_status(201) self.set_header("Content-Type", "application/json; charset=UTF-8") self.write(response)
async def patch(self, garden_name): """ --- summary: Partially update a Garden description: | The body of the request needs to contain a set of instructions detailing the updates to apply. Currently the only operations are: * initializing * running * stopped * block * update ```JSON [ { "operation": "" } ] ``` parameters: - name: garden_name in: path required: true description: Garden to use type: string - name: patch in: body required: true description: Instructions for how to update the Garden schema: $ref: '#/definitions/Patch' responses: 200: description: Garden with the given garden_name schema: $ref: '#/definitions/Garden' 400: $ref: '#/definitions/400Error' 404: $ref: '#/definitions/404Error' 50x: $ref: '#/definitions/50xError' tags: - Garden """ patch = SchemaParser.parse_patch(self.request.decoded_body, from_string=True) for op in patch: operation = op.operation.lower() if operation in ["initializing", "running", "stopped", "block"]: response = await self.client( Operation( operation_type="GARDEN_UPDATE_STATUS", args=[garden_name, operation.upper()], ) ) elif operation == "heartbeat": response = await self.client( Operation( operation_type="GARDEN_UPDATE_STATUS", args=[garden_name, "RUNNING"], ) ) elif operation == "config": response = await self.client( Operation( operation_type="GARDEN_UPDATE_CONFIG", args=[SchemaParser.parse_garden(op.value, from_string=False)], ) ) elif operation == "sync": response = await self.client( Operation( operation_type="GARDEN_SYNC", kwargs={"sync_target": garden_name}, ) ) else: raise ModelValidationError(f"Unsupported operation '{op.operation}'") self.set_header("Content-Type", "application/json; charset=UTF-8") self.write(response)