airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] Fokko commented on a change in pull request #3730: [AIRFLOW-2882] Add import and export for pool cli using JSON
Date Wed, 15 Aug 2018 07:04:13 GMT
Fokko commented on a change in pull request #3730: [AIRFLOW-2882] Add import and export for
pool cli using JSON
URL: https://github.com/apache/incubator-airflow/pull/3730#discussion_r210185544
 
 

 ##########
 File path: airflow/bin/cli.py
 ##########
 @@ -283,6 +292,43 @@ def _tabulate(pools):
         log.info(_tabulate(pools=pools))
 
 
+def pool_import_helper(filepath):
+    with open(filepath, 'r') as poolfile:
+        pl = poolfile.read()
+    try:
+        d = json.loads(pl)
+    except Exception:
+        print("Invalid pool file.")
+    else:
+        try:
+            pools = []
+            n = 0
+            for k, v in d.items():
+                if isinstance(v, dict) and len(v) == 2:
+                    pools.append(api_client.create_pool(name=k,
+                                                        slots=v["slots"],
+                                                        description=v["description"]))
+                    n += 1
+                else:
+                    pass
+        except Exception:
+            pass
+        finally:
+            print("{} of {} pool(s) successfully updated.".format(n, len(d)))
+            return pools
+
+
+def pool_export_helper(filepath):
+    pool_dict = {}
+    pools = api_client.get_pools()
+    for pool in pools:
+        pool_dict[pool[0]] = {"slots": pool[1], "description": pool[2]}
 
 Review comment:
   This code makes me a bit sad, I would expect a more descriptive response from the API.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message