Skip to content
Snippets Groups Projects
Commit 28a66dea authored by Neda Moeini's avatar Neda Moeini Committed by Mohammad Torkashvand
Browse files

Make GA and GS unique ids functionality

parent 6f960127
No related branches found
No related tags found
1 merge request!324Feature/manage sid and gids
......@@ -19,6 +19,8 @@ from orchestrator.db import (
from orchestrator.domain import SubscriptionModel
from orchestrator.services.subscriptions import query_in_use_by_subscriptions
from orchestrator.types import SubscriptionLifecycle, UUIDstr
from sqlalchemy import text
from sqlalchemy.exc import SQLAlchemyError
from gso.products import ProductName, ProductType
from gso.products.product_types.site import Site
......@@ -329,3 +331,39 @@ def is_virtual_circuit_id_available(virtual_circuit_id: str) -> bool:
True if the virtual circuit ID is unique (not found), False if it exists.
"""
return is_resource_type_value_unique("virtual_circuit_id", virtual_circuit_id)
def make_unique_gs_id() -> str:
"""Generate a unique GS ID using the gs_id_seq database sequence.
Returns:
str: A unique GS ID in the format `GS-<number>`.
Raises:
ValueError: If there is an error generating the ID.
"""
try:
new_id = db.session.execute(text("SELECT nextval('gs_id_seq')")).scalar_one()
except SQLAlchemyError as exc:
error_message = f"Error generating GS ID: {exc}"
raise ValueError(error_message) from exc
else:
return f"GS-{new_id}"
def make_unique_ga_id() -> str:
"""Generate a unique GA ID using the ga_id_seq database sequence.
Returns:
str: A unique GA ID in the format `GA<number>`.
Raises:
ValueError: If there is an error generating the ID.
"""
try:
new_id = db.session.execute(text("SELECT nextval('ga_id_seq')")).scalar_one()
except SQLAlchemyError as exc:
error_message = f"Error generating GA ID: {exc}"
raise ValueError(error_message) from exc
else:
return f"GA-{new_id}"
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