mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 04:02:52 -06:00
Fixes #632: Use semicolons instead of commas to separate regexes in topology maps
This commit is contained in:
parent
96eaea7db9
commit
ea92e92c5a
@ -98,4 +98,4 @@ dist-switch\d
|
|||||||
access-switch\d+,oob-switch\d+
|
access-switch\d+,oob-switch\d+
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that you can combine multiple regexes onto one line using commas. (Commas can only be used for separating regexes; they will not be processed as part of a regex.) The order in which regexes are listed on a line is significant: devices matching the first regex will be rendered first, and subsequent groups will be rendered to the right of those.
|
Note that you can combine multiple regexes onto one line using semicolons. The order in which regexes are listed on a line is significant: devices matching the first regex will be rendered first, and subsequent groups will be rendered to the right of those.
|
||||||
|
@ -80,7 +80,7 @@ class TopologyMapView(APIView):
|
|||||||
|
|
||||||
# Add each device to the graph
|
# Add each device to the graph
|
||||||
devices = []
|
devices = []
|
||||||
for query in device_set.split(','):
|
for query in device_set.split(';'): # Split regexes on semicolons
|
||||||
devices += Device.objects.filter(name__regex=query)
|
devices += Device.objects.filter(name__regex=query)
|
||||||
for d in devices:
|
for d in devices:
|
||||||
subgraph.node(d.name)
|
subgraph.node(d.name)
|
||||||
@ -94,7 +94,7 @@ class TopologyMapView(APIView):
|
|||||||
# Compile list of all devices
|
# Compile list of all devices
|
||||||
device_superset = Q()
|
device_superset = Q()
|
||||||
for device_set in tmap.device_sets:
|
for device_set in tmap.device_sets:
|
||||||
for query in device_set.split(','):
|
for query in device_set.split(';'): # Split regexes on semicolons
|
||||||
device_superset = device_superset | Q(name__regex=query)
|
device_superset = device_superset | Q(name__regex=query)
|
||||||
|
|
||||||
# Add all connections to the graph
|
# Add all connections to the graph
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10 on 2016-11-03 18:33
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
from extras.models import TopologyMap
|
||||||
|
|
||||||
|
|
||||||
|
def commas_to_semicolons(apps, schema_editor):
|
||||||
|
for tm in TopologyMap.objects.filter(device_patterns__contains=','):
|
||||||
|
tm.device_patterns = tm.device_patterns.replace(',', ';')
|
||||||
|
tm.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('extras', '0003_exporttemplate_add_description'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='topologymap',
|
||||||
|
name='device_patterns',
|
||||||
|
field=models.TextField(help_text=b'Identify devices to include in the diagram using regular expressions, one per line. Each line will result in a new tier of the drawing. Separate multiple regexes within a line using semicolons. Devices will be rendered in the order they are defined.'),
|
||||||
|
),
|
||||||
|
migrations.RunPython(commas_to_semicolons),
|
||||||
|
]
|
@ -268,10 +268,11 @@ class TopologyMap(models.Model):
|
|||||||
name = models.CharField(max_length=50, unique=True)
|
name = models.CharField(max_length=50, unique=True)
|
||||||
slug = models.SlugField(unique=True)
|
slug = models.SlugField(unique=True)
|
||||||
site = models.ForeignKey('dcim.Site', related_name='topology_maps', blank=True, null=True)
|
site = models.ForeignKey('dcim.Site', related_name='topology_maps', blank=True, null=True)
|
||||||
device_patterns = models.TextField(help_text="Identify devices to include in the diagram using regular expressions,"
|
device_patterns = models.TextField(
|
||||||
"one per line. Each line will result in a new tier of the drawing. "
|
help_text="Identify devices to include in the diagram using regular expressions, one per line. Each line will "
|
||||||
"Separate multiple regexes on a line using commas. Devices will be "
|
"result in a new tier of the drawing. Separate multiple regexes within a line using semicolons. "
|
||||||
"rendered in the order they are defined.")
|
"Devices will be rendered in the order they are defined."
|
||||||
|
)
|
||||||
description = models.CharField(max_length=100, blank=True)
|
description = models.CharField(max_length=100, blank=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
Loading…
Reference in New Issue
Block a user