Skip to content
Snippets Groups Projects
Verified Commit 26ddc379 authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

router creation flow update

create_router workflow takes a router to the PROVISIONING state
subscription service includes method for fetching all PROVISIONING routers
create_iptrunk workflow can now also select PROVISIONING routers next to ACTIVE ones
parent 4c50c2fc
No related branches found
No related tags found
1 merge request!165router creation flow update
This commit is part of merge request !165. Comments created here will be created in the context of that merge request.
......@@ -24,19 +24,18 @@ from gso.products import ProductType
SubscriptionType = dict[str, Any]
def get_active_subscriptions(
def get_subscriptions(
product_type: str,
lifecycle: SubscriptionLifecycle,
includes: list[str] | None = None,
excludes: list[str] | None = None,
) -> list[SubscriptionType]:
"""Retrieve active subscriptions for a specific product type.
:param product_type: The type of the product for which to retrieve subscriptions.
:type product_type: str
:param includes: List of fields to be included in the returned Subscription objects.
:type includes: list[str]
:param excludes: List of fields to be excluded from the returned Subscription objects.
:type excludes: list[str]
:param str product_type: The type of the product for which to retrieve subscriptions.
:param SubscriptionLifecycle lifecycle: The lifecycle that the products must be in.
:param list[str] includes: List of fields to be included in the returned Subscription objects.
:param list[str] excludes: List of fields to be excluded from the returned Subscription objects.
:return: A list of Subscription objects that match the query.
:rtype: list[Subscription]
......@@ -51,7 +50,7 @@ def get_active_subscriptions(
query = SubscriptionTable.query.join(ProductTable).filter(
ProductTable.product_type == product_type,
SubscriptionTable.status == SubscriptionLifecycle.ACTIVE,
SubscriptionTable.status == lifecycle,
)
results = query.with_entities(*dynamic_fields).all()
......@@ -59,9 +58,7 @@ def get_active_subscriptions(
return [dict(zip(includes, result, strict=True)) for result in results]
def get_active_site_subscriptions(
includes: list[str] | None = None,
) -> list[SubscriptionType]:
def get_active_site_subscriptions(includes: list[str] | None = None) -> list[SubscriptionType]:
"""Retrieve active subscriptions specifically for sites.
:param includes: The fields to be included in the returned Subscription objects.
......@@ -70,12 +67,10 @@ def get_active_site_subscriptions(
:return: A list of Subscription objects for sites.
:rtype: list[Subscription]
"""
return get_active_subscriptions(product_type=ProductType.SITE, includes=includes)
return get_subscriptions(product_type=ProductType.SITE, lifecycle=SubscriptionLifecycle.ACTIVE, includes=includes)
def get_active_router_subscriptions(
includes: list[str] | None = None,
) -> list[SubscriptionType]:
def get_active_router_subscriptions(includes: list[str] | None = None) -> list[SubscriptionType]:
"""Retrieve active subscriptions specifically for routers.
:param includes: The fields to be included in the returned Subscription objects.
......@@ -84,12 +79,19 @@ def get_active_router_subscriptions(
:return: A list of Subscription objects for routers.
:rtype: list[Subscription]
"""
return get_active_subscriptions(product_type="Router", includes=includes)
return get_subscriptions(product_type="Router", lifecycle=SubscriptionLifecycle.ACTIVE, includes=includes)
def get_active_iptrunk_subscriptions(
includes: list[str] | None = None,
) -> list[SubscriptionType]:
def get_provisioning_router_subscriptions(includes: list[str] | None = None) -> list[SubscriptionType]:
"""Retrieve provisioning subscriptions specifically for routers.
:param list[str] | None includes: The fields to be included in the returned Subscription objects.
:return list[Subscription]: A list of router Subscription objects.
"""
return get_subscriptions(product_type="Router", lifecycle=SubscriptionLifecycle.PROVISIONING, includes=includes)
def get_active_iptrunk_subscriptions(includes: list[str] | None = None) -> list[SubscriptionType]:
"""Retrieve active subscriptions specifically for IP trunks.
:param includes: The fields to be included in the returned Subscription objects.
......@@ -98,7 +100,7 @@ def get_active_iptrunk_subscriptions(
:return: A list of Subscription objects for IP trunks.
:rtype: list[Subscription]
"""
return get_active_subscriptions(product_type="Iptrunk", includes=includes)
return get_subscriptions(product_type="Iptrunk", lifecycle=SubscriptionLifecycle.ACTIVE, includes=includes)
def get_active_trunks_that_terminate_on_router(subscription_id: UUIDstr) -> list[SubscriptionTable]:
......
......@@ -43,7 +43,10 @@ from gso.utils.helpers import (
def initial_input_form_generator(product_name: str) -> FormGenerator:
"""Gather input from the user in three steps. General information, and information on both sides of the trunk."""
routers = {}
for router in subscriptions.get_active_router_subscriptions(includes=["subscription_id", "description"]):
for router in subscriptions.get_active_router_subscriptions(
includes=["subscription_id", "description"]
) + subscriptions.get_provisioning_router_subscriptions(includes=["subscription_id", "description"]):
# Add both provisioning and active routers, since trunks are required for promoting a router to active.
routers[str(router["subscription_id"])] = router["description"]
class CreateIptrunkForm(FormPage):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment