Compare commits

..

23 Commits

Author SHA1 Message Date
IluaAir b715019845 reorder file paths 2026-02-03 16:43:23 +03:00
IluaAir 3268274f69 reorder file paths 2026-02-01 15:56:37 +03:00
IluaAir fc0a232808 add script order 2025-10-06 17:59:59 +03:00
IluaAir 774412d5dd fix 2025-10-06 17:30:01 +03:00
IluaAir 909a7f10b9 fix tenant group 2025-10-06 17:28:31 +03:00
IluaAir f7edac730a test tenants group 2025-10-06 17:26:04 +03:00
IluaAir 8f014953af fix tenant group 2025-10-06 17:24:49 +03:00
IluaAir 7e8b74f3b8 add device test template 2025-10-06 17:21:10 +03:00
IluaAir dd851d388c 3 fix 2025-10-06 15:12:27 +03:00
IluaAir 88fad0f9fa doble fix tanant check 2025-10-06 15:04:50 +03:00
IluaAir 1e0c3b808b fix tenant check 2025-10-06 15:03:15 +03:00
IluaAir 12cbfef017 refactor 2025-10-06 13:32:42 +03:00
gitark b416d9d530 Update add_tenant_with_prefix.py 2025-10-01 17:03:14 +03:00
gitark 109e644dad Update add_tenant_with_prefix.py 2025-10-01 16:17:24 +03:00
IluaAir 1d825546cb role fix 2025-09-30 18:41:22 +03:00
IluaAir d75d98d1a2 another fix assigment 2025-09-30 18:36:35 +03:00
IluaAir cc72c4619d fix assigment 2025-09-30 18:34:41 +03:00
IluaAir edfa955edf fix contacts role 2025-09-30 18:29:42 +03:00
IluaAir 6388522486 fix name 2025-09-30 17:51:32 +03:00
IluaAir e03c28e7d9 fix contacts 2025-09-30 17:21:56 +03:00
IluaAir 569a88a248 add contact deps tenant 2025-09-30 17:04:15 +03:00
IluaAir e6df4820a6 update contacts 2025-09-30 16:24:34 +03:00
IluaAir 070a1722d2 init 2025-09-29 12:48:09 +03:00
7 changed files with 32 additions and 76 deletions
+4 -1
View File
@@ -1 +1,4 @@
/.idea /.venv/
/.idea/
/.netbox/netbox
/.vscode/
+1
View File
@@ -0,0 +1 @@
3.12
View File
-75
View File
@@ -1,75 +0,0 @@
import re
from dcim.models.devices import Device
from extras.models.tags import Tag
from extras.scripts import ObjectVar, Script
from dcim.models import VirtualChassis, Interface
from netbox.choices import ColorChoices
from utilities.exceptions import AbortScript
TAGS = "sync:vchas_interface"
class Vchassis_checker(Script):
IFACE_RE = re.compile(
r"^(?P<prefix>[A-Za-z]+)\s?(?:(?P<slot>\d+)/)?(?P<rest>\d+/\d+)$"
)
class Meta(Script.Meta):
commit_default = False
scheduling_enabled = False
name = "Переопределение интерфейсов"
description = "Переопределение интерфейсов у стекированных коммутаторов"
virtual_chassis = ObjectVar(
model=VirtualChassis,
description="Виртуальное шасси без тегов",
query_params={"tag__n": [TAGS.replace(":", "_")]},
)
def run(self, data, commit):
if Tag.objects.filter(name=TAGS).exists():
tag = Tag.objects.get(name=TAGS)
else:
self.log_warning(f"Отсутствует tag {TAGS}")
tag_data = {
"color": ColorChoices.COLOR_LIGHT_BLUE,
"name": TAGS,
"slug": TAGS.replace(":", "_"),
"description": "тег для автоматического назначения на синхронизированные интерфейсы vchassis",
}
tag = Tag(**tag_data)
if commit:
tag.full_clean()
tag.save()
self.log_success(
f"Создан тег: {TAGS}",
obj=tag,
)
vc = data["virtual_chassis"]
devices: list[Device] = list(vc.members.all().order_by("vc_position"))
if not vc._state.adding and vc.master and vc.master not in devices:
raise AbortScript(f"В стеке {vc.name} отсутствует мастер")
device_ids = [d.pk for d in devices]
interfaces_qs = Interface.objects.filter(
device_id__in=device_ids
).select_related("device")
to_update = []
for iface in interfaces_qs:
m = self.IFACE_RE.match(iface.name)
if m:
prefix = m.group("prefix")
slot = m.group("slot")
rest = m.group("rest")
iface.name = f"{prefix}{iface.device.vc_position}/{rest}"
to_update.append(iface)
if commit:
Interface.objects.bulk_update(to_update, fields=["name"], batch_size=100)
vc.tags.add(tag)
for iface in to_update:
iface.tags.add(tag)
self.log_success(f"Обновлено интерфейсов: {len(to_update)}")
else:
self.log_success(f"Будет обновлено интерфейсов: {len(to_update)}")
+7
View File
@@ -0,0 +1,7 @@
[project]
name = "netbox-scripts"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []
+12
View File
@@ -0,0 +1,12 @@
{
"extraPaths": ["netbox/netbox"],
"typeCheckingMode": "off",
"reportMissingImports": "warning",
"reportMissingTypeStubs": "none",
"reportGeneralTypeIssues": "none",
"reportOptionalMemberAccess": "none",
"reportOptionalSubscript": "none",
"reportArgumentType": "none",
"reportAssignmentType": "none",
"reportReturnType": "none"
}
Generated
+8
View File
@@ -0,0 +1,8 @@
version = 1
revision = 3
requires-python = ">=3.12"
[[package]]
name = "netbox-scripts"
version = "0.1.0"
source = { virtual = "." }