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

make use of partials for sending requests in provisioning proxy

parent 1449d7fa
No related branches found
No related tags found
1 merge request!96Make use of new callback step for external provisioning
This commit is part of merge request !96. Comments created here will be created in the context of that merge request.
...@@ -6,6 +6,7 @@ import json ...@@ -6,6 +6,7 @@ import json
import logging import logging
import requests import requests
from functools import partial
from orchestrator import step from orchestrator import step
from orchestrator.config.assignee import Assignee from orchestrator.config.assignee import Assignee
from orchestrator.types import State, UUIDstr, strEnum from orchestrator.types import State, UUIDstr, strEnum
...@@ -34,9 +35,11 @@ class CUDOperation(strEnum): ...@@ -34,9 +35,11 @@ class CUDOperation(strEnum):
DELETE = "DELETE" 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. """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 :param endpoint: The :term:`LSO`-specific endpoint to call, depending on the type of service object that's acted
upon. upon.
:type endpoint: str :type endpoint: str
...@@ -45,8 +48,6 @@ def _send_request(endpoint: str, parameters: dict, callback_route: str, operatio ...@@ -45,8 +48,6 @@ def _send_request(endpoint: str, parameters: dict, callback_route: str, operatio
:type parameters: dict :type parameters: dict
:param callback_route: The callback route that should be used to resume the workflow. :param callback_route: The callback route that should be used to resume the workflow.
:type callback_route: str :type callback_route: str
:param operation: The specific operation that's performed with the request.
:type operation: :class:`CUDOperation`
:rtype: None :rtype: None
""" """
oss = settings.load_oss_params() oss = settings.load_oss_params()
...@@ -75,6 +76,11 @@ def _send_request(endpoint: str, parameters: dict, callback_route: str, operatio ...@@ -75,6 +76,11 @@ def _send_request(endpoint: str, parameters: dict, callback_route: str, operatio
raise AssertionError(request.content) 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( def provision_router(
subscription: RouterProvisioning, process_id: UUIDstr, callback_route: str, tt_number: str, dry_run: bool = True subscription: RouterProvisioning, process_id: UUIDstr, callback_route: str, tt_number: str, dry_run: bool = True
) -> None: ) -> None:
...@@ -99,7 +105,7 @@ def provision_router( ...@@ -99,7 +105,7 @@ def provision_router(
"subscription": json.loads(json_dumps(subscription)), "subscription": json.loads(json_dumps(subscription)),
} }
_send_request("router", parameters, callback_route, CUDOperation.POST) _send_post("router", parameters, callback_route)
def provision_ip_trunk( def provision_ip_trunk(
...@@ -139,7 +145,7 @@ def provision_ip_trunk( ...@@ -139,7 +145,7 @@ def provision_ip_trunk(
"removed_ae_members": removed_ae_members, "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( def check_ip_trunk(
...@@ -165,7 +171,7 @@ def check_ip_trunk( ...@@ -165,7 +171,7 @@ def check_ip_trunk(
"check_name": check_name, "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( def deprovision_ip_trunk(
...@@ -193,7 +199,7 @@ def deprovision_ip_trunk( ...@@ -193,7 +199,7 @@ def deprovision_ip_trunk(
"verb": "terminate", "verb": "terminate",
} }
_send_request("ip_trunk", parameters, callback_route, CUDOperation.DELETE) _send_delete("ip_trunk", parameters, callback_route)
def migrate_ip_trunk( def migrate_ip_trunk(
...@@ -251,7 +257,7 @@ def migrate_ip_trunk( ...@@ -251,7 +257,7 @@ def migrate_ip_trunk(
"dry_run": dry_run, "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") @step("Evaluate provisioning proxy result")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment