|
1 | 1 | from typing import Tuple |
2 | | - |
3 | | -from circuits.models import Circuit, CircuitTermination, ProviderNetwork |
| 2 | +from circuits.constants import CIRCUIT_TERMINATION_TERMINATION_TYPES |
| 3 | +from circuits.models import Circuit, CircuitTermination |
4 | 4 | from dcim.models import ( |
5 | 5 | Cable, |
6 | 6 | CableTermination, |
|
13 | 13 | PowerPanel, |
14 | 14 | PowerPort, |
15 | 15 | RearPort, |
16 | | - Site, |
17 | 16 | ) |
18 | 17 | from django.contrib.contenttypes.models import ContentType |
19 | 18 | from django.db.models import Q |
20 | 19 |
|
21 | 20 | from netbox_initializers.initializers.base import BaseInitializer, register_initializer |
| 21 | +from netbox_initializers.initializers.utils import get_scope_details |
22 | 22 |
|
23 | 23 | CONSOLE_PORT_TERMINATION = ContentType.objects.get_for_model(ConsolePort) |
24 | 24 | CONSOLE_SERVER_PORT_TERMINATION = ContentType.objects.get_for_model(ConsoleServerPort) |
@@ -55,16 +55,13 @@ def get_termination_object(params: dict, side: str): |
55 | 55 | circuit = Circuit.objects.get(cid=circuit_params.pop("cid")) |
56 | 56 | term_side = circuit_params.pop("term_side").upper() |
57 | 57 |
|
58 | | - site_name = circuit_params.pop("site", None) |
59 | | - provider_network = circuit_params.pop("provider_network", None) |
60 | | - |
61 | | - if site_name: |
62 | | - circuit_params["site"] = Site.objects.get(name=site_name) |
63 | | - elif provider_network: |
64 | | - circuit_params["provider_network"] = ProviderNetwork.objects.get(name=provider_network) |
| 58 | + if scope := circuit_params.pop("scope", None): |
| 59 | + scope_type, scope_id = get_scope_details(scope, CIRCUIT_TERMINATION_TERMINATION_TYPES) |
| 60 | + circuit_params["termination_type"] = scope_type |
| 61 | + circuit_params["termination_id"] = scope_id |
65 | 62 | else: |
66 | 63 | raise ValueError( |
67 | | - f"⚠️ Missing one of required parameters: 'site' or 'provider_network' " |
| 64 | + f"⚠️ Missing required parameter: 'scope'" |
68 | 65 | f"for side {term_side} of circuit {circuit}" |
69 | 66 | ) |
70 | 67 |
|
|
0 commit comments