From 65e88e3d30cfb99a837bc1122418ec426c84d66b Mon Sep 17 00:00:00 2001
From: Karel van Klink <karel.vanklink@geant.org>
Date: Thu, 19 Sep 2024 16:47:24 +0200
Subject: [PATCH] Show current license usage when updating Kentik license of a
 router

---
 gso/services/kentik_client.py                 | 37 ++++++++++++++++++-
 gso/services/lso_client.py                    |  2 +
 gso/workflows/router/modify_kentik_license.py |  6 ++-
 3 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/gso/services/kentik_client.py b/gso/services/kentik_client.py
index 95d55e22..7849adee 100644
--- a/gso/services/kentik_client.py
+++ b/gso/services/kentik_client.py
@@ -109,7 +109,42 @@ class KentikClient:
         return {}
 
     def get_plans(self) -> list[dict[str, Any]]:
-        """Get all Kentik plans available."""
+        """Get all Kentik plans available.
+
+        Returns a list of ``plans`` that each have the following shape:
+
+        .. vale off
+        .. code-block:: json
+
+            "plan": {
+                "active": true,
+                "bgp_enabled": true,
+                "cdate" "1970-01-01T01:01:01.000Z",
+                "company_id": 111111,
+                "description": "A description of this plan",
+                "deviceTypes": [
+                    {"device_type": "router"},
+                    {"device_type": "host-nprobe-dns-www"}
+                ],
+                "devices": [
+                    {
+                        "id": "111111",
+                        "device_name": "rt0.city.tld.internal",
+                        "device_type": "router"
+                    },
+                ],
+                "edate": "2999-01-01T09:09:09.000Z",
+                "fast_retention": 10,
+                "full_retention": 5,
+                "id": 11111,
+                "max_bigdata_fps": 100,
+                "max_devices": 9001,
+                "max_fps": 200,
+                "name": "KENTIK-PLAN-01",
+                "metadata": {},
+            }
+        .. vale on
+        """
         return self._send_request("GET", "v5/plans")["plans"]
 
     def get_plan(self, plan_id: int) -> dict[str, Any]:
diff --git a/gso/services/lso_client.py b/gso/services/lso_client.py
index 6eca3f65..77c22647 100644
--- a/gso/services/lso_client.py
+++ b/gso/services/lso_client.py
@@ -60,6 +60,7 @@ def execute_playbook(
     For example, an inventory consisting of two hosts, which each a unique host variable assigned to them looks as
     follows:
 
+    .. vale off
     .. code-block:: json
 
         "inventory": {
@@ -74,6 +75,7 @@ def execute_playbook(
                 }
             }
         }
+    .. vale on
 
     .. warning::
        Note the fact that the collection of all hosts is a dictionary, and not a list of strings. Ansible expects each
diff --git a/gso/workflows/router/modify_kentik_license.py b/gso/workflows/router/modify_kentik_license.py
index 28d9d21f..bd97b9c0 100644
--- a/gso/workflows/router/modify_kentik_license.py
+++ b/gso/workflows/router/modify_kentik_license.py
@@ -22,7 +22,11 @@ logger = logging.getLogger()
 
 def _initial_input_form(subscription_id: UUIDstr) -> FormGenerator:
     router = Router.from_subscription(subscription_id)
-    active_kentik_plans = {str(plan["id"]): plan["name"] for plan in KentikClient().get_plans() if plan["active"]}
+    active_kentik_plans = {
+        str(plan["id"]): f"{plan["name"]} - ({len(plan["devices"])}/{plan["max_devices"]})"
+        for plan in KentikClient().get_plans()
+        if plan["active"]
+    }
     available_kentik_plans = Choice(
         "Select a Kentik license",
         zip(active_kentik_plans.keys(), active_kentik_plans.items(), strict=True),  # type: ignore[arg-type]
-- 
GitLab