diff --git a/.gitignore b/.gitignore index 0831a3bed5028225205efdd0483f25f5bd0fadff..4d87beab1ae8e9393bccfa744e19c0c801c41f63 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ oss-params.json docs/build docs/vale/styles/* !docs/vale/styles/Vocab/ + +.idea diff --git a/gso/services/crm.py b/gso/services/crm.py new file mode 100644 index 0000000000000000000000000000000000000000..b340dac04bad28e047528e47814fc24897206ea8 --- /dev/null +++ b/gso/services/crm.py @@ -0,0 +1,7 @@ +def all_customers() -> list[dict]: + return [ + { + "id": "8f0df561-ce9d-4d9c-89a8-7953d3ffc961", + "name": "Geant", + }, + ] diff --git a/gso/workflows/device/create_device.py b/gso/workflows/device/create_device.py index 4d3f0cd787a152b9f3325efda2a2a24dba5635f7..78bc5dd2ce78e943789d37c66b059213583c43c1 100644 --- a/gso/workflows/device/create_device.py +++ b/gso/workflows/device/create_device.py @@ -1,6 +1,5 @@ import ipaddress import re -from uuid import uuid4 from orchestrator.db.models import ProductTable, SubscriptionTable @@ -19,6 +18,7 @@ from gso.products.product_types.device import DeviceInactive, DeviceProvisioning from gso.products.product_types.site import Site from gso.services import ipam, provisioning_proxy from gso.services.provisioning_proxy import pp_interaction +from gso.workflows.utils import customer_selector def site_selector() -> Choice: @@ -43,6 +43,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: class Config: title = product_name + customer: customer_selector() # type: ignore device_site: site_selector() # type: ignore hostname: str ts_port: int @@ -56,8 +57,8 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: @step("Create subscription") -def create_subscription(product: UUIDstr) -> State: - subscription = DeviceInactive.from_product_id(product, uuid4()) +def create_subscription(product: UUIDstr, customer: UUIDstr) -> State: + subscription = DeviceInactive.from_product_id(product, customer) return { "subscription": subscription, diff --git a/gso/workflows/iptrunk/create_iptrunk.py b/gso/workflows/iptrunk/create_iptrunk.py index 2b70dc70a0562078c3fa7a08770b600d0e64bc42..89cca024113363d79690004f49bd8c373a28115f 100644 --- a/gso/workflows/iptrunk/create_iptrunk.py +++ b/gso/workflows/iptrunk/create_iptrunk.py @@ -1,5 +1,3 @@ -from uuid import uuid4 - from orchestrator.db.models import ProductTable, SubscriptionTable from orchestrator.forms import FormPage from orchestrator.forms.validators import Choice, UniqueConstrainedList @@ -15,6 +13,7 @@ from gso.products.product_types.device import Device from gso.products.product_types.iptrunk import IptrunkInactive, IptrunkProvisioning from gso.services import ipam, provisioning_proxy from gso.services.provisioning_proxy import pp_interaction +from gso.workflows.utils import customer_selector def initial_input_form_generator(product_name: str) -> FormGenerator: @@ -37,6 +36,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: class Config: title = product_name + customer: customer_selector() # type: ignore geant_s_sid: str iptrunk_description: str iptrunk_type: IptrunkType @@ -86,8 +86,8 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: @step("Create subscription") -def create_subscription(product: UUIDstr) -> State: - subscription = IptrunkInactive.from_product_id(product, uuid4()) +def create_subscription(product: UUIDstr, customer: UUIDstr) -> State: + subscription = IptrunkInactive.from_product_id(product, customer) return { "subscription": subscription, diff --git a/gso/workflows/site/create_site.py b/gso/workflows/site/create_site.py index 5930bf155e1fd48eb61ecf31bbe4742d0db069f2..67e3b91253cf7cc2588aa36bbc962c81c31e6bdf 100644 --- a/gso/workflows/site/create_site.py +++ b/gso/workflows/site/create_site.py @@ -1,5 +1,3 @@ -from uuid import uuid4 - from orchestrator.forms import FormPage from orchestrator.targets import Target from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUIDstr @@ -9,6 +7,7 @@ from orchestrator.workflows.utils import wrap_create_initial_input_form from gso.products.product_blocks import site as site_pb from gso.products.product_types import site +from gso.workflows.utils import customer_selector def initial_input_form_generator(product_name: str) -> FormGenerator: @@ -16,6 +15,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: class Config: title = product_name + customer: customer_selector() # type: ignore site_name: str site_city: str site_country: str @@ -33,8 +33,8 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: @step("Create subscription") -def create_subscription(product: UUIDstr) -> State: - subscription = site.SiteInactive.from_product_id(product, uuid4()) +def create_subscription(product: UUIDstr, customer: UUIDstr) -> State: + subscription = site.SiteInactive.from_product_id(product, customer) return { "subscription": subscription, diff --git a/gso/workflows/utils.py b/gso/workflows/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..d2c631377667abf1d31b9448c164f2dff96c1eaa --- /dev/null +++ b/gso/workflows/utils.py @@ -0,0 +1,11 @@ +from orchestrator.forms.validators import Choice + +from gso.services.crm import all_customers + + +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 diff --git a/tox.ini b/tox.ini index 8bfef47e58735f1d937e8cb31b6e01a9a81e4cb4..ed2f8f9ad2007e11acacc02d1cc50541b0982838 100644 --- a/tox.ini +++ b/tox.ini @@ -19,14 +19,14 @@ deps = -r requirements.txt commands = + isort -c . + ruff . + black --check . + mypy . + flake8 coverage erase coverage run --source gso -m pytest {posargs} coverage xml coverage html # coverage report --fail-under 80 coverage report - isort -c . - ruff . - black --check . - mypy . - flake8