From 5303aaf53cf8813acfefc511c3c22230d5466458 Mon Sep 17 00:00:00 2001
From: Karel van Klink <karel.vanklink@geant.org>
Date: Thu, 1 Aug 2024 15:45:56 +0200
Subject: [PATCH] remove Kentik steps from router creation and termination
 workflows

---
 gso/oss-params-example.json              |  7 +---
 gso/services/kentik_client.py            |  2 +-
 gso/settings.py                          |  3 +-
 gso/workflows/router/create_router.py    | 42 ------------------------
 gso/workflows/router/terminate_router.py |  8 -----
 5 files changed, 3 insertions(+), 59 deletions(-)

diff --git a/gso/oss-params-example.json b/gso/oss-params-example.json
index 7b6c399f..f9523a72 100644
--- a/gso/oss-params-example.json
+++ b/gso/oss-params-example.json
@@ -110,12 +110,7 @@
     "api_key": "kentik_api_key",
     "device_type": "router",
     "minimize_snmp": false,
-    "billing_plans": {
-      "1": "XL license",
-      "2": "L license",
-      "3": "M license",
-      "4": "S license"
-    },
+    "placeholder_license_key": "placeholder license",
     "sample_rate": 100,
     "bgp_type": "device",
     "bgp_lookup_strategy": "lu_global_fallback",
diff --git a/gso/services/kentik_client.py b/gso/services/kentik_client.py
index bb81a826..7f62d169 100644
--- a/gso/services/kentik_client.py
+++ b/gso/services/kentik_client.py
@@ -114,7 +114,7 @@ class KentikClient:
 
     def create_device(self, device: NewKentikDevice) -> dict[str, Any]:
         """Add a new device to Kentik."""
-        plan_id = self.get_plan_by_name(self.config.billing_plans[device.site_tier])["id"]
+        plan_id = self.get_plan_by_name(self.config.placeholder_license_key)["id"]
         request_body = {
             "device": {
                 **device.model_dump(exclude=set("device_name" "site_tier")),
diff --git a/gso/settings.py b/gso/settings.py
index e0a60a3e..c105fffc 100644
--- a/gso/settings.py
+++ b/gso/settings.py
@@ -16,7 +16,6 @@ from pydantic_forms.types import UUIDstr, strEnum
 from pydantic_settings import BaseSettings
 from typing_extensions import Doc
 
-from gso.products.product_blocks.site import SiteTier
 from gso.utils.shared_enums import PortNumber
 
 logger = logging.getLogger(__name__)
@@ -184,7 +183,7 @@ class KentikParams(BaseSettings):
     api_key: str
     device_type: str
     minimize_snmp: bool
-    billing_plans: dict[SiteTier, str]
+    placeholder_license_key: str
     sample_rate: int
     bgp_type: str
     bgp_lookup_strategy: str
diff --git a/gso/workflows/router/create_router.py b/gso/workflows/router/create_router.py
index 8c7fdc06..8382e227 100644
--- a/gso/workflows/router/create_router.py
+++ b/gso/workflows/router/create_router.py
@@ -18,7 +18,6 @@ from gso.products.product_blocks.router import RouterRole
 from gso.products.product_types.router import RouterInactive, RouterProvisioning
 from gso.products.product_types.site import Site
 from gso.services import infoblox, subscriptions
-from gso.services.kentik_client import KentikClient, NewKentikDevice
 from gso.services.lso_client import lso_interaction
 from gso.services.netbox_client import NetboxClient
 from gso.services.partners import get_partner_by_name
@@ -144,46 +143,6 @@ def create_netbox_device(subscription: RouterInactive) -> State:
     return {"subscription": subscription}
 
 
-@step("Create Kentik device")
-def create_kentik_device(subscription: RouterInactive) -> State:
-    """Create a new device in Kentik."""
-    if not (
-        subscription.router.router_site
-        and subscription.router.router_site.site_name
-        and subscription.router.router_site.site_tier
-        and subscription.router.router_fqdn
-    ):
-        msg = "Router object is missing required properties."
-        raise ProcessFailureError(msg)
-
-    kentik_client = KentikClient()
-    kentik_site = kentik_client.get_site_by_name(subscription.router.router_site.site_name)
-
-    if not kentik_site:
-        msg = f"Site could not be found in Kentik: {subscription.router.router_site.site_name}"
-        raise ProcessFailureError(msg)
-
-    site_tier = subscription.router.router_site.site_tier
-    new_device = NewKentikDevice(
-        device_name=subscription.router.router_fqdn,
-        device_description=str(subscription.subscription_id),
-        sending_ips=[str(subscription.router.router_lo_ipv4_address)],
-        site_tier=site_tier,
-        site_id=kentik_site["id"],
-        device_snmp_ip=str(subscription.router.router_lo_ipv4_address),
-        device_bgp_flowspec=False,
-        device_bgp_neighbor_ip=str(subscription.router.router_lo_ipv4_address),
-        device_bgp_neighbor_ip6=str(subscription.router.router_lo_ipv6_address),
-    )
-    kentik_device = kentik_client.create_device(new_device)
-
-    if "error" in kentik_device or "kentik_error" in kentik_device:
-        raise ProcessFailureError(str(kentik_device))
-
-    kentik_device.pop("custom_column_data", None)
-    return {"kentik_device": kentik_device}
-
-
 @step("Verify IPAM resources for loopback interface")
 def verify_ipam_loopback(subscription: RouterInactive) -> None:
     """Validate the :term:`IPAM` resources for the loopback interface.
@@ -313,7 +272,6 @@ def create_router() -> StepList:
         >> prompt_insert_in_ims
         >> prompt_insert_in_radius
         >> router_is_nokia(create_netbox_device)
-        >> create_kentik_device
         >> lso_interaction(run_checks_after_base_config)
         >> set_status(SubscriptionLifecycle.PROVISIONING)
         >> create_new_sharepoint_checklist
diff --git a/gso/workflows/router/terminate_router.py b/gso/workflows/router/terminate_router.py
index cbb3048d..688e3ecc 100644
--- a/gso/workflows/router/terminate_router.py
+++ b/gso/workflows/router/terminate_router.py
@@ -21,7 +21,6 @@ from orchestrator.workflows.utils import wrap_modify_initial_input_form
 from gso.products.product_blocks.router import RouterRole
 from gso.products.product_types.router import Router
 from gso.services import infoblox, lso_client
-from gso.services.kentik_client import KentikClient
 from gso.services.librenms_client import LibreNMSClient
 from gso.services.lso_client import execute_playbook, lso_interaction
 from gso.services.netbox_client import NetboxClient
@@ -238,12 +237,6 @@ def remove_device_from_librenms(subscription: Router) -> dict[str, Router]:
     return {"subscription": subscription}
 
 
-@step("Archive device in Kentik")
-def remove_device_from_kentik(subscription: Router) -> None:
-    """Archive the device in Kentik."""
-    KentikClient().remove_device(subscription.router.router_fqdn, archive=True)
-
-
 @workflow(
     "Terminate router",
     initial_input_form=wrap_modify_initial_input_form(initial_input_form_generator),
@@ -278,7 +271,6 @@ def terminate_router() -> StepList:
         >> run_config_steps(lso_interaction(remove_config_from_router_real))
         >> router_is_nokia(remove_device_from_netbox)
         >> remove_device_from_librenms
-        >> remove_device_from_kentik
         >> set_status(SubscriptionLifecycle.TERMINATED)
         >> resync
         >> done
-- 
GitLab