bugraoz93 commented on code in PR #49496: URL: https://github.com/apache/airflow/pull/49496#discussion_r2075851443
########## airflow-ctl/src/airflowctl/ctl/commands/pool_command.py: ########## @@ -0,0 +1,112 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Command functions for managing Airflow pools.""" + +from __future__ import annotations + +import json +from json import JSONDecodeError +from pathlib import Path + +import rich + +from airflowctl.api.client import NEW_API_CLIENT, Client, ClientKind, provide_api_client +from airflowctl.api.datamodels.generated import ( + BulkAction, + BulkActionOnExistence, + BulkBodyPoolBody, + BulkCreateActionPoolBody, + PoolBody, +) + + +@provide_api_client(kind=ClientKind.CLI) +def import_(args, api_client: Client = NEW_API_CLIENT): + """Import pools from file.""" + filepath = Path(args.file) + if not filepath.exists(): + raise SystemExit(f"Missing pools file {args.file}") + + pools, failed = _import_helper(api_client, filepath) + if failed: + raise SystemExit(f"Failed to update pool(s): {', '.join(failed)}") + rich.print(f"Uploaded {len(pools)} pool(s)") + + +@provide_api_client(kind=ClientKind.CLI) +def export(args, api_client: Client = NEW_API_CLIENT): + """ + Export all pools. + + If output is json, write to file. Otherwise print to console. + """ + try: + pools = api_client.pools.list() + pools_dict = { + pool["name"]: { + "slots": pool["slots"], + "description": pool["description"], + "include_deferred": pool["include_deferred"], + } + for pool in pools + } Review Comment: This is returning `PoolCollectionResponse`, we need to parse accordingly. It is list of PoolResponse in the pools key. Something like ```suggestion pools = api_client.pools.list() pools_dict = {} for pool in pools.pools: pool = pool.model_dump() pools_dict[pool["name"]] = { "slots": pool["slots"], "description": pool["description"], "include_deferred": pool["include_deferred"], } ``` You can also do a developer test, run the API, follow `airflowctl auth login --api-url="http://localhost:28080" --username=admin --password`, and then interact with `airflowctl` locally after `uv sync`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
