diff --git a/gso/services/provisioning_proxy.py b/gso/services/provisioning_proxy.py index d705f3de30f941dca2834d021b06d188359ddd63..e9dc112871e5291c8894e22f5e09e33cd596ced8 100644 --- a/gso/services/provisioning_proxy.py +++ b/gso/services/provisioning_proxy.py @@ -5,46 +5,26 @@ import json import logging -from functools import partial from typing import Any import requests from orchestrator import step from orchestrator.config.assignee import Assignee -from orchestrator.types import State, UUIDstr, strEnum +from orchestrator.types import State from orchestrator.utils.errors import ProcessFailureError -from orchestrator.utils.json import json_dumps from orchestrator.workflow import Step, StepList, begin, callback_step, inputstep from pydantic_forms.core import FormPage, ReadOnlyField from pydantic_forms.types import FormGenerator from pydantic_forms.validators import LongText from gso import settings -from gso.products.product_types.iptrunk import Iptrunk, IptrunkProvisioning -from gso.products.product_types.router import Router, RouterProvisioning logger = logging.getLogger(__name__) -class CUDOperation(strEnum): - """Enumerator for different :term:`CRUD` operations that the provisioning proxy supports. - - Read is not applicable, hence the missing R. - """ - - POST = "POST" - PUT = "PUT" - DELETE = "DELETE" - - -def _send_request(operation: CUDOperation, endpoint: str, parameters: dict, callback_route: str) -> None: +def _send_request(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 :param parameters: JSON body for the request, which will almost always at least consist of a subscription object, and a boolean value to indicate a dry run. :type parameters: dict @@ -61,26 +41,12 @@ def _send_request(operation: CUDOperation, endpoint: str, parameters: dict, call logger.debug(debug_msg) parameters.update({"callback": callback_url}) - url = f"{pp_params.scheme}://{pp_params.api_base}/api/{endpoint}" - - request = None - - # Fire off the request, depending on the operation type. - if operation == CUDOperation.POST: - request = requests.post(url, json=parameters, timeout=10000) - elif operation == CUDOperation.PUT: - request = requests.put(url, json=parameters, timeout=10000) - elif operation == CUDOperation.DELETE: - request = requests.delete(url, json=parameters, timeout=10000) + url = f"{pp_params.scheme}://{pp_params.api_base}/api/playbook" + request = requests.post(url, json=parameters, timeout=10) request.raise_for_status() -_send_post = partial(_send_request, CUDOperation.POST) -_send_put = partial(_send_request, CUDOperation.PUT) -_send_delete = partial(_send_request, CUDOperation.DELETE) - - def execute_playbook( playbook_name: str, callback_route: str, @@ -143,202 +109,7 @@ def execute_playbook( "extra_vars": extra_vars, } - _send_post("playbook", parameters, callback_route) - - -def provision_router( - subscription: RouterProvisioning, - process_id: UUIDstr, - callback_route: str, - tt_number: str, - *, - dry_run: bool = True, -) -> None: - """Provision a new router using :term:`LSO`. - - :param subscription: The subscription object that's to be provisioned. - :type subscription: :class:`RouterProvisioning` - :param process_id: The related process ID, used for callback. - :type process_id: UUIDstr - :param callback_route: The API endpoint that should be used for the callback URL. - :type callback_route: str - :param tt_number: Trouble ticket number related to the operation. - :type tt_number: str - :param dry_run: A boolean indicating whether this should be a dry run or not, defaults to ``True``. - :type dry_run: bool - :rtype: None - """ - parameters = { - "process_id": process_id, - "tt_number": tt_number, - "dry_run": dry_run, - "subscription": json.loads(json_dumps(subscription)), - } - - _send_post("router", parameters, callback_route) - - -def provision_ip_trunk( - subscription: IptrunkProvisioning, - process_id: UUIDstr, - callback_route: str, - tt_number: str, - config_object: str, - *, - dry_run: bool = True, - removed_ae_members: list[str] | None = None, -) -> None: - """Provision an IP trunk service using :term:`LSO`. - - :param subscription: The subscription object that's to be provisioned. - :type subscription: :class:`IptrunkProvisioning` - :param process_id: The related process ID, used for callback. - :type process_id: UUIDstr - :param callback_route: The API endpoint that should be used for the callback URL. - :type callback_route: str - :param tt_number: Trouble ticket number related to the operation. - :type tt_number: str - :param config_object: The type of object that's deployed. - :type config_object: str - :param dry_run: A boolean indicating whether this should be a dry run or not, defaults to ``True``. - :type dry_run: bool - :rtype: None - :param removed_ae_members: A list of interfaces that are removed from the :term:`LAG`, defaults to ``None``. - only used when removing interfaces from the :term:`LAG` in ``modify_ip_trunk``. - """ - parameters = { - "subscription": json.loads(json_dumps(subscription)), - "dry_run": dry_run, - "verb": "deploy", - "tt_number": tt_number, - "process_id": process_id, - "object": config_object, - "removed_ae_members": removed_ae_members, - } - - _send_post("ip_trunk", parameters, callback_route) - - -def check_ip_trunk( - subscription: IptrunkProvisioning, - process_id: UUIDstr, - callback_route: str, - tt_number: str, - check_name: str, -) -> None: - """Provision an IP trunk service using :term:`LSO`. - - :param subscription: The subscription object that's to be provisioned. - :type subscription: :class:`IptrunkProvisioning` - :param process_id: The related process ID, used for callback. - :type process_id: UUIDstr - :param callback_route: The API endpoint that should be used for the callback URL. - :type callback_route: str - :param tt_number: Trouble ticket number related to the operation. - :type tt_number: str - :param check_name: The name of the check to execute - :rtype: None - """ - parameters = { - "subscription": json.loads(json_dumps(subscription)), - "tt_number": tt_number, - "process_id": process_id, - "check_name": check_name, - } - - _send_post("ip_trunk/perform_check", parameters, callback_route) - - -def deprovision_ip_trunk( - subscription: Iptrunk, - process_id: UUIDstr, - callback_route: str, - tt_number: str, - *, - dry_run: bool = True, -) -> None: - """Deprovision an IP trunk service using :term:`LSO`. - - :param subscription: The subscription object that's to be provisioned. - :type subscription: :class:`IptrunkProvisioning` - :param process_id: The related process ID, used for callback. - :type process_id: UUIDstr - :param callback_route: The API endpoint that should be used for the callback URL. - :type callback_route: str - :param tt_number: Trouble ticket number related to the operation. - :type tt_number: str - :param dry_run: A boolean indicating whether this should be a dry run or not, defaults to ``True``. - :type dry_run: bool - :rtype: None - """ - parameters = { - "subscription": json.loads(json_dumps(subscription)), - "tt_number": tt_number, - "process_id": process_id, - "dry_run": dry_run, - "verb": "terminate", - } - - _send_delete("ip_trunk", parameters, callback_route) - - -def migrate_ip_trunk( - subscription: Iptrunk, - new_node: Router, - new_lag_interface: str, - new_lag_member_interfaces: list[dict], - replace_index: int, - process_id: UUIDstr, - callback_route: str, - tt_number: str, - verb: str, - config_object: str, - *, - dry_run: bool = True, -) -> None: - """Migrate an IP trunk service using :term:`LSO`. - - :param subscription: The subscription object that's to be migrated. - :type subscription: :class:`Iptrunk` - :param new_node: The new node that is being migrated to. - :type new_node: :class:`Router` - :param new_lag_interface: The name of the new aggregated Ethernet interface. - :type new_lag_interface: str - :param new_lag_member_interfaces: The new list of interfaces that are part of the :term:`LAG`. - :type new_lag_member_interfaces: list[str] - :param replace_index: The index of the side that is going to be replaced as part of the existing trunk, can be ``0`` - or ``1``. - :type replace_index: int - :param process_id: The related process ID, used for callback. - :type process_id: UUIDstr - :param callback_route: The :term:`API` endpoint that should be used for the callback URL. - :type callback_route: str - :param tt_number: Trouble ticket number related to the operation. - :type tt_number: str - :param verb: The verb that is passed to the executed playbook. - :type verb: str - :param config_object: The object that is configured. - :type config_object: str - :param dry_run: A boolean indicating whether this should be a dry run or not, defaults to ``True``. - :type dry_run: bool - :rtype: None - """ - parameters = { - "subscription": json.loads(json_dumps(subscription)), - "tt_number": tt_number, - "process_id": process_id, - "new_side": { - "new_node": json.loads(json_dumps(new_node)), - "new_lag_interface": new_lag_interface, - "new_lag_member_interfaces": new_lag_member_interfaces, - "replace_index": replace_index, - }, - "verb": verb, - "config_object": config_object, - "dry_run": dry_run, - } - - _send_post("ip_trunk/migrate", parameters, callback_route) + _send_request(parameters, callback_route) @step("Evaluate provisioning proxy result")