From cf7fb0aecee58460a5582401535ce73a2d2642c0 Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Fri, 6 Oct 2023 15:11:43 +0200 Subject: [PATCH] restructure customer selector and ISO calculation --- gso/services/crm.py | 10 ++++++++++ gso/{workflows/utils.py => utils/functions.py} | 0 gso/workflows/iptrunk/create_iptrunk.py | 2 ++ gso/workflows/router/create_router.py | 3 ++- gso/workflows/site/create_site.py | 2 +- test/workflows/iptrunk/test_create_iptrunk.py | 3 +-- 6 files changed, 16 insertions(+), 4 deletions(-) rename gso/{workflows/utils.py => utils/functions.py} (100%) diff --git a/gso/services/crm.py b/gso/services/crm.py index 8c2af469..5ccd3e45 100644 --- a/gso/services/crm.py +++ b/gso/services/crm.py @@ -1,5 +1,7 @@ from typing import Any +from pydantic_forms.validators import Choice + class CustomerNotFoundError(Exception): """Exception raised when a customer is not found.""" @@ -22,3 +24,11 @@ def get_customer_by_name(name: str) -> dict[str, Any]: return customer raise CustomerNotFoundError(f"Customer {name} not found") + + +def customer_selector() -> Choice: + customers = {} + for customer in all_customers(): + customers[customer["id"]] = customer["name"] + + return Choice("Select a customer", zip(customers.keys(), customers.items())) # type: ignore[arg-type] diff --git a/gso/workflows/utils.py b/gso/utils/functions.py similarity index 100% rename from gso/workflows/utils.py rename to gso/utils/functions.py diff --git a/gso/workflows/iptrunk/create_iptrunk.py b/gso/workflows/iptrunk/create_iptrunk.py index a8331d06..154c89dd 100644 --- a/gso/workflows/iptrunk/create_iptrunk.py +++ b/gso/workflows/iptrunk/create_iptrunk.py @@ -14,6 +14,7 @@ from gso.products.product_types.iptrunk import IptrunkInactive, IptrunkProvision from gso.products.product_types.router import Router from gso.services import infoblox, provisioning_proxy, subscriptions from gso.services.netbox_client import NetboxClient +from gso.services.crm import customer_selector from gso.services.provisioning_proxy import pp_interaction from gso.workflows.utils import ( available_interfaces_choices, @@ -22,6 +23,7 @@ from gso.workflows.utils import ( get_router_vendor, validate_router_in_netbox, ) +from gso.utils.types.phy_port import PhyPortCapacity def initial_input_form_generator(product_name: str) -> FormGenerator: diff --git a/gso/workflows/router/create_router.py b/gso/workflows/router/create_router.py index ca9b4868..38519163 100644 --- a/gso/workflows/router/create_router.py +++ b/gso/workflows/router/create_router.py @@ -10,6 +10,7 @@ from orchestrator.workflow import StepList, conditional, done, init, step, workf from orchestrator.workflows.steps import resync, set_status, store_process_subscription from orchestrator.workflows.utils import wrap_create_initial_input_form from pydantic import validator +from services.crm import customer_selector from gso.products.product_blocks.router import RouterRole, RouterVendor, generate_fqdn from gso.products.product_types.router import RouterInactive, RouterProvisioning @@ -18,7 +19,7 @@ from gso.services import infoblox, provisioning_proxy, subscriptions from gso.services.netbox_client import NetboxClient from gso.services.provisioning_proxy import pp_interaction from gso.utils.types.ip_port import PortNumber -from gso.workflows.utils import customer_selector, iso_from_ipv4 +from utils.functions import iso_from_ipv4 def _site_selector() -> Choice: diff --git a/gso/workflows/site/create_site.py b/gso/workflows/site/create_site.py index 18aada8f..c00856ef 100644 --- a/gso/workflows/site/create_site.py +++ b/gso/workflows/site/create_site.py @@ -12,8 +12,8 @@ from pydantic import validator from gso.products.product_blocks import site as site_pb from gso.products.product_types import site +from gso.services.crm import customer_selector from gso.utils.types.snmp import LatitudeCoordinate, LongitudeCoordinate -from gso.workflows.utils import customer_selector def initial_input_form_generator(product_name: str) -> FormGenerator: # noqa: C901 diff --git a/test/workflows/iptrunk/test_create_iptrunk.py b/test/workflows/iptrunk/test_create_iptrunk.py index 886c26d5..c72329d7 100644 --- a/test/workflows/iptrunk/test_create_iptrunk.py +++ b/test/workflows/iptrunk/test_create_iptrunk.py @@ -5,10 +5,9 @@ import pytest from gso.products import Iptrunk, ProductType from gso.products.product_blocks.iptrunk import IptrunkType -from gso.services.crm import get_customer_by_name +from gso.services.crm import customer_selector, get_customer_by_name from gso.services.subscriptions import get_product_id_by_name from gso.utils.types.phy_port import PhyPortCapacity -from gso.workflows.utils import customer_selector from test.workflows import ( assert_aborted, assert_complete, -- GitLab