From 18956158893a96808e7fddb90fd32bbe677a7043 Mon Sep 17 00:00:00 2001 From: Julian Keck <julian.keck9@kit.edu> Date: Wed, 29 Jan 2025 13:50:24 +0100 Subject: [PATCH] UPD: require comment when requesting tagged port or lacp --- api/patch_request.py | 9 +++++++++ model/patch_request.py | 2 ++ templates/patch_request_confirm_template.j2 | 3 +++ templates/patch_request_template.j2 | 8 +++++++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/api/patch_request.py b/api/patch_request.py index 6c6ad78..c33e0af 100644 --- a/api/patch_request.py +++ b/api/patch_request.py @@ -161,6 +161,14 @@ def validate_patch_request_actions(conn, user, actions: list[APIPatchRequestActi {'idx': 'vlan_list', 'name': 'nd.vlan.list', 'inner_join_ref': {'bcd_list': 'default'}}, ], user=user.login_name) internal_action.bcd = Port(**bcd_result['bcd_list'][0]) + + if action.bcd_tagged or action.use_lacp: + if action.comment is None or len(action.comment) == 0: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail='Comment must be provided for tagged or lacp!' + ) + if len(bcd_result['vlan_list']) > 0: internal_action.vlan_ids = list( map(lambda v: '{compound}: {id}'.format(compound=v.get('net_instnc', 'UNKNOWN?'), id=v['id']), @@ -343,6 +351,7 @@ def validate_patch_request_actions(conn, user, actions: list[APIPatchRequestActi internal_action.site = Site(**r['site_list'][0]) internal_action.action = action.action internal_action.bcd_tagged = action.bcd_tagged + internal_action.use_lacp = action.use_lacp internal_action.comment = action.comment internal_actions.append(internal_action) diff --git a/model/patch_request.py b/model/patch_request.py index 16d1f64..85aaabc 100644 --- a/model/patch_request.py +++ b/model/patch_request.py @@ -22,6 +22,7 @@ class APIPatchRequestAction(BaseModel): action: PatchActionType = Field() bcd_name: Optional[str] = Field(default=None) bcd_tagged: Optional[bool] = Field(default=False) + use_lacp: Optional[bool] = Field(default=False) building_gpk: str = Field() comment: str = Field() module_gpk: str = Field() @@ -35,6 +36,7 @@ class PatchRequestAction(BaseModel): action: Optional[PatchActionType] = Field(default=None) bcd: Optional[BCD] = Field(default=None) bcd_tagged: Optional[bool] = Field(default=False) + use_lacp: Optional[bool] = Field(default=False) building: Optional[Bldg] = Field(default=None) comment: str = Field(default='') module: Optional[Module] = Field(default=None) diff --git a/templates/patch_request_confirm_template.j2 b/templates/patch_request_confirm_template.j2 index d3cd463..d985481 100644 --- a/templates/patch_request_confirm_template.j2 +++ b/templates/patch_request_confirm_template.j2 @@ -18,6 +18,9 @@ {% if action['bcd'] is defined and action['bcd']['name'] is defined %} <b>Broadcast domain:</b> {{ action['bcd']['name'] }} ({% if action['bcd_tagged'] %}add tagged{%else%}untagged{%endif%})<br> {% endif %} + {% if action['use_lacp'] %} + <b>LACP:</b> True <br> + {% endif %} {% if action['new_insert_type'] %} <b>New insert:</b> {{ action['new_insert_type'] }}<br> {% endif %} diff --git a/templates/patch_request_template.j2 b/templates/patch_request_template.j2 index 7ecb09e..0bb2514 100644 --- a/templates/patch_request_template.j2 +++ b/templates/patch_request_template.j2 @@ -38,10 +38,16 @@ <td style="border: 1px solid black; border-collapse: collapse;">{{ action['p_port']['name'] }}</td> </tr> {% endif %} + {% if action['use_lacp'] %} + <tr> + <th style="border: 1px solid black; border-collapse: collapse; font-weight: bold;">LACP</th> + <td style="border: 1px solid black; border-collapse: collapse;">True (see comment!)</td> + </tr> + {% endif %} {% if action['bcd'] is defined and action['bcd']['name'] is defined %} <tr> <th style="border: 1px solid black; border-collapse: collapse;">Broadcast Domain</th> - <td style="border: 1px solid black; border-collapse: collapse;">{{ action['bcd']['name'] }} ({% if action['bcd_tagged'] %}add tagged{% else %}untagged{% endif %}) + <td style="border: 1px solid black; border-collapse: collapse;">{{ action['bcd']['name'] }} ({% if action['bcd_tagged'] %}add tagged (see comment){% else %}untagged{% endif %}) <ul> {% for v in action['vlan_ids'] %} <li>{{ v }}</li> -- GitLab