diff --git a/gso/services/provisioning_proxy.py b/gso/services/provisioning_proxy.py index 232ed3f1a5b8d9efb2d49e6edd8dbc8769b49a22..fd0f8685bd0d08c6338d1d504362481152394bb4 100644 --- a/gso/services/provisioning_proxy.py +++ b/gso/services/provisioning_proxy.py @@ -6,6 +6,7 @@ import json import logging import requests +from functools import partial from orchestrator import step from orchestrator.config.assignee import Assignee from orchestrator.types import State, UUIDstr, strEnum @@ -34,9 +35,11 @@ class CUDOperation(strEnum): DELETE = "DELETE" -def _send_request(endpoint: str, parameters: dict, callback_route: str, operation: CUDOperation) -> None: +def _send_request(operation: CUDOperation, endpoint: str, parameters: dict, callback_route: str) -> None: """Send a request to :term:`LSO`. The callback address is derived using the process ID provided. + :param operation: The specific operation that's performed with the request. + :type operation: :class:`CUDOperation` :param endpoint: The :term:`LSO`-specific endpoint to call, depending on the type of service object that's acted upon. :type endpoint: str @@ -45,8 +48,6 @@ def _send_request(endpoint: str, parameters: dict, callback_route: str, operatio :type parameters: dict :param callback_route: The callback route that should be used to resume the workflow. :type callback_route: str - :param operation: The specific operation that's performed with the request. - :type operation: :class:`CUDOperation` :rtype: None """ oss = settings.load_oss_params() @@ -75,6 +76,11 @@ def _send_request(endpoint: str, parameters: dict, callback_route: str, operatio raise AssertionError(request.content) +_send_post = partial(_send_request, CUDOperation.POST) +_send_put = partial(_send_request, CUDOperation.PUT) +_send_delete = partial(_send_request, CUDOperation.DELETE) + + def provision_router( subscription: RouterProvisioning, process_id: UUIDstr, callback_route: str, tt_number: str, dry_run: bool = True ) -> None: @@ -99,7 +105,7 @@ def provision_router( "subscription": json.loads(json_dumps(subscription)), } - _send_request("router", parameters, callback_route, CUDOperation.POST) + _send_post("router", parameters, callback_route) def provision_ip_trunk( @@ -139,7 +145,7 @@ def provision_ip_trunk( "removed_ae_members": removed_ae_members, } - _send_request("ip_trunk", parameters, callback_route, CUDOperation.POST) + _send_post("ip_trunk", parameters, callback_route) def check_ip_trunk( @@ -165,7 +171,7 @@ def check_ip_trunk( "check_name": check_name, } - _send_request("ip_trunk/perform_check", parameters, callback_route, CUDOperation.POST) + _send_post("ip_trunk/perform_check", parameters, callback_route) def deprovision_ip_trunk( @@ -193,7 +199,7 @@ def deprovision_ip_trunk( "verb": "terminate", } - _send_request("ip_trunk", parameters, callback_route, CUDOperation.DELETE) + _send_delete("ip_trunk", parameters, callback_route) def migrate_ip_trunk( @@ -251,7 +257,7 @@ def migrate_ip_trunk( "dry_run": dry_run, } - _send_request("ip_trunk/migrate", parameters, callback_route, CUDOperation.POST) + _send_post("ip_trunk/migrate", parameters, callback_route) @step("Evaluate provisioning proxy result")