diff --git a/gso/services/crm.py b/gso/services/crm.py index 8c2af4698aa2c16478f372388df88ae6d125c308..5ccd3e45f80b0febf706f001f5e85e71c1c38bd9 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 a8331d06593b59a127b5799c0d30d948195807cf..154c89dd356863ecb3c95faad97df0601c89ed9a 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 ca9b4868c9178edcf522ca2181b90db0ee9a8926..385191637d32de97c028d5953e25afbe1e13980b 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 18aada8f52472b8e103bd9ab7bc88f01474ba979..c00856efd2c9f5fdc194e274ae7624089d22756f 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 886c26d5b0558a8fc1c872abc0dba18b069e961a..c72329d7ca6a20a3ea1e68b6556112c4fadf7232 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,