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

don't fail router termination if the device doesn't exist in LibreNMS or Kentik

parent 06a32a55
No related branches found
No related tags found
1 merge request!287don't fail router termination if the device doesn't exist in LibreNMS or Kentik
...@@ -5,7 +5,7 @@ from uuid import UUID ...@@ -5,7 +5,7 @@ from uuid import UUID
import pydantic import pydantic
import pynetbox import pynetbox
from pydantic_forms.types import UUIDstr from orchestrator.types import UUIDstr
from pynetbox.models.dcim import Devices, DeviceTypes, Interfaces from pynetbox.models.dcim import Devices, DeviceTypes, Interfaces
from gso.products.product_types.router import Router from gso.products.product_types.router import Router
......
...@@ -18,8 +18,7 @@ from orchestrator.db import ( ...@@ -18,8 +18,7 @@ from orchestrator.db import (
) )
from orchestrator.domain import SubscriptionModel from orchestrator.domain import SubscriptionModel
from orchestrator.services.subscriptions import query_in_use_by_subscriptions from orchestrator.services.subscriptions import query_in_use_by_subscriptions
from orchestrator.types import SubscriptionLifecycle from orchestrator.types import SubscriptionLifecycle, UUIDstr
from pydantic_forms.types import UUIDstr
from gso.products import ProductName, ProductType from gso.products import ProductName, ProductType
from gso.products.product_types.site import Site from gso.products.product_types.site import Site
......
...@@ -11,8 +11,9 @@ import os ...@@ -11,8 +11,9 @@ import os
from pathlib import Path from pathlib import Path
from typing import Annotated from typing import Annotated
from orchestrator.types import UUIDstr
from pydantic import EmailStr, Field from pydantic import EmailStr, Field
from pydantic_forms.types import UUIDstr, strEnum from pydantic_forms.types import strEnum
from pydantic_settings import BaseSettings from pydantic_settings import BaseSettings
from typing_extensions import Doc from typing_extensions import Doc
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
from typing import Annotated, TypeVar from typing import Annotated, TypeVar
from orchestrator.types import UUIDstr
from pydantic import AfterValidator from pydantic import AfterValidator
from pydantic_forms.types import UUIDstr
from gso.products.product_types.router import Router from gso.products.product_types.router import Router
from gso.services.netbox_client import NetboxClient from gso.services.netbox_client import NetboxClient
......
...@@ -3,13 +3,11 @@ ...@@ -3,13 +3,11 @@
import ipaddress import ipaddress
import json import json
import logging import logging
from typing import Any
from orchestrator.forms import FormPage from orchestrator.forms import FormPage
from orchestrator.forms.validators import Label from orchestrator.forms.validators import Label
from orchestrator.targets import Target from orchestrator.targets import Target
from orchestrator.types import FormGenerator, SubscriptionLifecycle, UUIDstr from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUIDstr
from orchestrator.utils.errors import ProcessFailureError
from orchestrator.utils.json import json_dumps from orchestrator.utils.json import json_dumps
from orchestrator.workflow import StepList, begin, conditional, done, step, workflow from orchestrator.workflow import StepList, begin, conditional, done, step, workflow
from orchestrator.workflows.steps import ( from orchestrator.workflows.steps import (
...@@ -19,6 +17,7 @@ from orchestrator.workflows.steps import ( ...@@ -19,6 +17,7 @@ from orchestrator.workflows.steps import (
unsync, unsync,
) )
from orchestrator.workflows.utils import wrap_modify_initial_input_form from orchestrator.workflows.utils import wrap_modify_initial_input_form
from requests import HTTPError
from gso.products.product_blocks.router import RouterRole from gso.products.product_blocks.router import RouterRole
from gso.products.product_types.router import Router from gso.products.product_types.router import Router
...@@ -224,13 +223,17 @@ def remove_pe_from_all_p_real(subscription: Router, tt_number: str, process_id: ...@@ -224,13 +223,17 @@ def remove_pe_from_all_p_real(subscription: Router, tt_number: str, process_id:
@step("Remove Device from Librenms") @step("Remove Device from Librenms")
def remove_device_from_librenms(subscription: Router) -> None: def remove_device_from_librenms(subscription: Router) -> State | None:
"""Remove the device from LibreNMS.""" """Remove the device from LibreNMS."""
LibreNMSClient().remove_device(subscription.router.router_fqdn) try:
LibreNMSClient().remove_device(subscription.router.router_fqdn)
except HTTPError as e:
return {"librenms_error": str(e)}
return None
@step("Apply the archiving license in Kentik") @step("Apply the archiving license in Kentik")
def kentik_apply_archive_license(subscription: Router) -> dict[str, dict[str, Any]]: def kentik_apply_archive_license(subscription: Router) -> State:
"""Apply the archiving license to a PE router in Kentik. """Apply the archiving license to a PE router in Kentik.
This includes setting the flow rate to one flow per second. This includes setting the flow rate to one flow per second.
...@@ -239,8 +242,7 @@ def kentik_apply_archive_license(subscription: Router) -> dict[str, dict[str, An ...@@ -239,8 +242,7 @@ def kentik_apply_archive_license(subscription: Router) -> dict[str, dict[str, An
kentik_archive_plan_id = kentik_client.get_plan_by_name(load_oss_params().KENTIK.archive_license_key)["id"] kentik_archive_plan_id = kentik_client.get_plan_by_name(load_oss_params().KENTIK.archive_license_key)["id"]
kentik_device = kentik_client.get_device_by_name(subscription.router.router_fqdn) kentik_device = kentik_client.get_device_by_name(subscription.router.router_fqdn)
if "id" not in kentik_device: if "id" not in kentik_device:
msg = "Failed to find Kentik device by name" return {"kentik_device": "Device not found, no license applied"}
raise ProcessFailureError(msg, details=kentik_device)
updated_device = {"device": {"plan_id": kentik_archive_plan_id, "device_sample_rate": 1}} updated_device = {"device": {"plan_id": kentik_archive_plan_id, "device_sample_rate": 1}}
kentik_device = kentik_client.update_device(kentik_device["id"], updated_device) kentik_device = kentik_client.update_device(kentik_device["id"], updated_device)
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
from typing import Any from typing import Any
from orchestrator.targets import Target from orchestrator.targets import Target
from orchestrator.types import State, UUIDstr
from orchestrator.utils.errors import ProcessFailureError from orchestrator.utils.errors import ProcessFailureError
from orchestrator.workflow import StepList, begin, conditional, done, step, workflow from orchestrator.workflow import StepList, begin, conditional, done, step, workflow
from orchestrator.workflows.steps import resync, store_process_subscription, unsync from orchestrator.workflows.steps import resync, store_process_subscription, unsync
from orchestrator.workflows.utils import wrap_modify_initial_input_form from orchestrator.workflows.utils import wrap_modify_initial_input_form
from pydantic_forms.types import State, UUIDstr
from gso.products.product_blocks.router import RouterRole from gso.products.product_blocks.router import RouterRole
from gso.products.product_types.router import Router from gso.products.product_types.router import Router
......
...@@ -4,10 +4,9 @@ from enum import Enum ...@@ -4,10 +4,9 @@ from enum import Enum
from orchestrator.forms import FormPage from orchestrator.forms import FormPage
from orchestrator.targets import Target from orchestrator.targets import Target
from orchestrator.types import FormGenerator, State from orchestrator.types import FormGenerator, State, UUIDstr
from orchestrator.workflow import StepList, begin, done, step, workflow from orchestrator.workflow import StepList, begin, done, step, workflow
from pydantic import ConfigDict, EmailStr, field_validator from pydantic import ConfigDict, EmailStr, field_validator
from pydantic_forms.types import UUIDstr
from pydantic_forms.validators import Choice from pydantic_forms.validators import Choice
from gso.services.partners import delete_partner, get_all_partners, get_partner_by_name from gso.services.partners import delete_partner, get_all_partners, get_partner_by_name
......
...@@ -2,10 +2,9 @@ ...@@ -2,10 +2,9 @@
from orchestrator.forms import FormPage from orchestrator.forms import FormPage
from orchestrator.targets import Target from orchestrator.targets import Target
from orchestrator.types import FormGenerator, State from orchestrator.types import FormGenerator, State, UUIDstr
from orchestrator.workflow import StepList, begin, done, step, workflow from orchestrator.workflow import StepList, begin, done, step, workflow
from pydantic import ConfigDict, EmailStr, field_validator from pydantic import ConfigDict, EmailStr, field_validator
from pydantic_forms.types import UUIDstr
from pydantic_forms.validators import Choice from pydantic_forms.validators import Choice
from gso.services.partners import ( from gso.services.partners import (
......
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