vinogorod: проект СКС «Винный город» — скрипты, документация, снимки справочников NetBox

- скрипты: экспорт справочников (export_netbox_refs) и портовой модели
  (export_netbox_inventory) для составления CSV-импорта устройств/соединений
- docs: CSV-снимки справочников + inventory JSON (2026-10-12, сайт «Винный город»)
- статус/план/конспекты проекта; .gitignore исключает .venv, skc_pdfs, skc_texts
This commit is contained in:
2026-10-12 05:41:30 +00:00
parent 2677c43b4b
commit bbf8b20802
48 changed files with 68003 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
import json
from django.apps import apps
def get_model(name):
try:
return apps.get_model('dcim', name)
except Exception:
return None
def name_of(obj, attr):
try:
v = getattr(obj, attr)
return getattr(v, 'name', v)
except Exception:
return None
Site = get_model('Site'); Location = get_model('Location'); Rack = get_model('Rack')
Manufacturer = get_model('Manufacturer'); DeviceType = get_model('DeviceType')
DeviceRole = get_model('DeviceRole'); Device = get_model('Device')
Cable = get_model('Cable'); Interface = get_model('Interface'); FrontPort = get_model('FrontPort')
out = {}
if Site:
out['sites'] = [{'name': s.name, 'slug': s.slug, 'status': getattr(s,'status',None)} for s in Site.objects.all().order_by('name')]
if Location:
out['locations'] = [{'name': l.name, 'slug': l.slug, 'site': name_of(l,'site'), 'status': getattr(l,'status',None)} for l in Location.objects.all().order_by('name')]
if Rack:
out['rack_total'] = Rack.objects.count()
out['racks_B'] = [{'name': r.name, 'status': getattr(r,'status',None), 'u_height': getattr(r,'u_height',None),
'site': name_of(r,'site'), 'location': name_of(r,'location'),
'manuf': name_of(r,'manufacturer'), 'model': name_of(r,'model')}
for r in Rack.objects.filter(name__icontains='ТШ-В').order_by('name')]
if Manufacturer:
out['manufacturers'] = [m.name for m in Manufacturer.objects.all().order_by('name')]
if DeviceType:
dts = []
for t in DeviceType.objects.all().order_by('model'):
cnt = t.device_count if hasattr(t, 'device_count') else Device.objects.filter(device_type=t).count()
dts.append({'model': t.model, 'manuf': name_of(t,'manufacturer'), 'slug': getattr(t,'slug',None),
'u_height': getattr(t,'u_height',None), 'count': cnt})
out['device_types'] = dts
if DeviceRole:
out['roles'] = [{'name': r.name, 'slug': r.slug, 'color': getattr(r,'color',None)}
for r in DeviceRole.objects.all().order_by('name')]
if Device:
out['devices_B2'] = [{'name': d.name, 'type': name_of(d,'device_type'), 'role': name_of(d,'role'),
'rack': name_of(d,'rack'), 'pos': getattr(d,'position',None), 'status': getattr(d,'status',None)}
for d in Device.objects.filter(name__icontains='B.2').order_by('name')]
out['rack_B_devices'] = [{'name': d.name, 'rack': d.rack.name, 'type': name_of(d,'device_type'),
'role': name_of(d,'role'), 'pos': getattr(d,'position',None)}
for d in Device.objects.filter(rack__name__icontains='ТШ-В').order_by('rack__name','position')]
out['iface_B2_sample'] = [{'dev': i.device.name, 'name': i.name, 'type': str(getattr(i,'type',None))}
for i in Interface.objects.filter(device__name__icontains='B.2').order_by('device__name','name')[:6]]
out['front_B2_sample'] = [{'dev': p.device.name, 'name': p.name, 'type': str(getattr(p,'type',None)),
'label': getattr(p,'label',None)}
for p in FrontPort.objects.filter(device__name__icontains='B.2')[:8]]
if Cable:
out['cable_total'] = Cable.objects.count()
out['cables'] = [{'label': getattr(c,'label',None) or getattr(c,'name',None),
'type': str(getattr(c,'type',None)), 'status': getattr(c,'status',None),
'length': getattr(c,'length',None), 'unit': getattr(c,'length_unit',None)}
for c in Cable.objects.all()[:25]]
print(json.dumps(out, ensure_ascii=False, indent=1, default=str))