Archived
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9d9b59d16 | ||
|
|
34be43bffb |
No files matched your search
@@ -30,7 +30,7 @@ IP ranges created automatically from the saved IP addresses:
|
|||||||
|
|
||||||
## Compatibility
|
## Compatibility
|
||||||
|
|
||||||
- NetBox `4.6.5` – `4.7.x` (verified with 4.7.2)
|
- NetBox `4.6.5` – `4.7.x` (verified with 4.7.3)
|
||||||
- Python `>=3.12`
|
- Python `>=3.12`
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
@@ -169,6 +169,29 @@ NetBox has no separate core model called organisation. The overview maps
|
|||||||
organisation to NetBox `Region` and includes child regions and their sites and
|
organisation to NetBox `Region` and includes child regions and their sites and
|
||||||
locations.
|
locations.
|
||||||
|
|
||||||
|
### Language
|
||||||
|
|
||||||
|
The plugin is available in English (source) and German. Switch the display
|
||||||
|
language as usual in the user profile (**Preferences → Language**).
|
||||||
|
Translations live in `netbox_better_ips/locale/de/LC_MESSAGES/`.
|
||||||
|
|
||||||
|
## Development and tests
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python -m unittest discover -s tests
|
||||||
|
```
|
||||||
|
|
||||||
|
The tests check that the NetBox range in this README and the package version
|
||||||
|
match the `PluginConfig`, and that the translations are shipped.
|
||||||
|
|
||||||
|
After changing user-visible strings, update and compile the catalogue from
|
||||||
|
within `netbox_better_ips/`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
django-admin makemessages -l de --no-location
|
||||||
|
msgfmt --check -o locale/de/LC_MESSAGES/django.mo locale/de/LC_MESSAGES/django.po
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Apache License 2.0 — see [LICENSE](LICENSE).
|
Apache License 2.0 — see [LICENSE](LICENSE).
|
||||||
@@ -1,4 +1,33 @@
|
|||||||
from .config import BetterIPsConfig
|
from netbox.plugins import PluginConfig
|
||||||
|
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.2"
|
||||||
|
|
||||||
|
|
||||||
|
# Defined here rather than in a submodule: NetBox resolves default resources
|
||||||
|
# such as template_content relative to the PluginConfig's module.
|
||||||
|
class BetterIPsConfig(PluginConfig):
|
||||||
|
name = "netbox_better_ips"
|
||||||
|
verbose_name = "NetBox Better IPs"
|
||||||
|
description = "Automatic IP ranges from IP addresses and an extended IP network overview"
|
||||||
|
author = "LKE"
|
||||||
|
version = __version__
|
||||||
|
base_url = "better-ips"
|
||||||
|
min_version = "4.6.5"
|
||||||
|
max_version = "4.7.99"
|
||||||
|
default_settings = {
|
||||||
|
"auto_create_range": True,
|
||||||
|
"range_status": "active",
|
||||||
|
"inherit_tenant": True,
|
||||||
|
"ignore_host_prefixes": True,
|
||||||
|
}
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
super().ready()
|
||||||
|
from . import signals # noqa: F401
|
||||||
|
from . import tables # noqa: F401
|
||||||
|
from .navigation import register_ipam_menu_item
|
||||||
|
|
||||||
|
register_ipam_menu_item()
|
||||||
|
|
||||||
|
|
||||||
config = BetterIPsConfig
|
config = BetterIPsConfig
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
from netbox.plugins import PluginConfig
|
|
||||||
|
|
||||||
|
|
||||||
class BetterIPsConfig(PluginConfig):
|
|
||||||
name = "netbox_better_ips"
|
|
||||||
verbose_name = "NetBox Better IPs"
|
|
||||||
description = "Automatische Prefix-Zuordnung und erweiterte IP-Netzübersicht"
|
|
||||||
author = "LKE"
|
|
||||||
version = "1.2.2"
|
|
||||||
base_url = "better-ips"
|
|
||||||
min_version = "4.6.5"
|
|
||||||
max_version = "4.7.99"
|
|
||||||
default_settings = {
|
|
||||||
"auto_create_range": True,
|
|
||||||
"range_status": "active",
|
|
||||||
"inherit_tenant": True,
|
|
||||||
"ignore_host_prefixes": True,
|
|
||||||
}
|
|
||||||
|
|
||||||
def ready(self):
|
|
||||||
super().ready()
|
|
||||||
from . import signals # noqa: F401
|
|
||||||
from . import tables # noqa: F401
|
|
||||||
from .navigation import register_ipam_menu_item
|
|
||||||
|
|
||||||
register_ipam_menu_item()
|
|
||||||
@@ -1,25 +1,26 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
from dcim.models import Location, Region, Site, SiteGroup
|
from dcim.models import Location, Region, Site, SiteGroup
|
||||||
from tenancy.models import Tenant, TenantGroup
|
from tenancy.models import Tenant, TenantGroup
|
||||||
|
|
||||||
|
|
||||||
class NetworkOverviewFilterForm(forms.Form):
|
class NetworkOverviewFilterForm(forms.Form):
|
||||||
q = forms.CharField(required=False, label="Suche")
|
q = forms.CharField(required=False, label=_("Search"))
|
||||||
organization = forms.ModelChoiceField(
|
organization = forms.ModelChoiceField(
|
||||||
queryset=Region.objects.all(), required=False, label="Organisation / Region"
|
queryset=Region.objects.all(), required=False, label=_("Organisation / Region")
|
||||||
)
|
)
|
||||||
site_group = forms.ModelChoiceField(
|
site_group = forms.ModelChoiceField(
|
||||||
queryset=SiteGroup.objects.all(), required=False, label="Standortgruppe"
|
queryset=SiteGroup.objects.all(), required=False, label=_("Site group")
|
||||||
)
|
)
|
||||||
site = forms.ModelChoiceField(queryset=Site.objects.all(), required=False, label="Standort")
|
site = forms.ModelChoiceField(queryset=Site.objects.all(), required=False, label=_("Site"))
|
||||||
location = forms.ModelChoiceField(
|
location = forms.ModelChoiceField(
|
||||||
queryset=Location.objects.all(), required=False, label="Lokation"
|
queryset=Location.objects.all(), required=False, label=_("Location")
|
||||||
)
|
)
|
||||||
tenant_group = forms.ModelChoiceField(
|
tenant_group = forms.ModelChoiceField(
|
||||||
queryset=TenantGroup.objects.all(), required=False, label="Mandantengruppe"
|
queryset=TenantGroup.objects.all(), required=False, label=_("Tenant group")
|
||||||
)
|
)
|
||||||
tenant = forms.ModelChoiceField(
|
tenant = forms.ModelChoiceField(
|
||||||
queryset=Tenant.objects.all(), required=False, label="Mandant"
|
queryset=Tenant.objects.all(), required=False, label=_("Tenant")
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,102 @@
|
|||||||
|
# German translation of NetBox Better IPs.
|
||||||
|
# This file is distributed under the same license as the netbox-better-ips package.
|
||||||
|
#
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: netbox-better-ips\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2026-10-26 21:14+0100\n"
|
||||||
|
"PO-Revision-Date: 2026-10-26 21:15+0100\n"
|
||||||
|
"Last-Translator: NetBox Better IPs contributors\n"
|
||||||
|
"Language-Team: German\n"
|
||||||
|
"Language: de\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
|
||||||
|
msgid "Search"
|
||||||
|
msgstr "Suche"
|
||||||
|
|
||||||
|
msgid "Organisation / Region"
|
||||||
|
msgstr "Organisation / Region"
|
||||||
|
|
||||||
|
msgid "Site group"
|
||||||
|
msgstr "Standortgruppe"
|
||||||
|
|
||||||
|
msgid "Site"
|
||||||
|
msgstr "Standort"
|
||||||
|
|
||||||
|
msgid "Location"
|
||||||
|
msgstr "Lokation"
|
||||||
|
|
||||||
|
msgid "Tenant group"
|
||||||
|
msgstr "Mandantengruppe"
|
||||||
|
|
||||||
|
msgid "Tenant"
|
||||||
|
msgstr "Mandant"
|
||||||
|
|
||||||
|
msgid "IP Network Overview"
|
||||||
|
msgstr "IP-Netzübersicht"
|
||||||
|
|
||||||
|
msgid "Device / VM"
|
||||||
|
msgstr "Gerät / VM"
|
||||||
|
|
||||||
|
msgid "Extended network overview"
|
||||||
|
msgstr "Erweiterte Netzübersicht"
|
||||||
|
|
||||||
|
msgid "Create all missing ranges"
|
||||||
|
msgstr "Alle fehlenden Bereiche anlegen"
|
||||||
|
|
||||||
|
#, python-format
|
||||||
|
msgid "%(counter)s network"
|
||||||
|
msgid_plural "%(counter)s networks"
|
||||||
|
msgstr[0] "%(counter)s Netz"
|
||||||
|
msgstr[1] "%(counter)s Netze"
|
||||||
|
|
||||||
|
msgid "Network"
|
||||||
|
msgstr "Netz"
|
||||||
|
|
||||||
|
msgid "VRF"
|
||||||
|
msgstr "VRF"
|
||||||
|
|
||||||
|
msgid "Scope"
|
||||||
|
msgstr "Geltungsbereich"
|
||||||
|
|
||||||
|
msgid "Status"
|
||||||
|
msgstr "Status"
|
||||||
|
|
||||||
|
msgid "Description"
|
||||||
|
msgstr "Beschreibung"
|
||||||
|
|
||||||
|
msgid "No matching networks found."
|
||||||
|
msgstr "Keine passenden Netze gefunden."
|
||||||
|
|
||||||
|
msgid "Previous"
|
||||||
|
msgstr "Vorherige"
|
||||||
|
|
||||||
|
#, python-format
|
||||||
|
msgid "Page %(number)s of %(total)s"
|
||||||
|
msgstr "Seite %(number)s von %(total)s"
|
||||||
|
|
||||||
|
msgid "Next"
|
||||||
|
msgstr "Nächste"
|
||||||
|
|
||||||
|
msgid "Filter"
|
||||||
|
msgstr "Filter"
|
||||||
|
|
||||||
|
msgid "Apply"
|
||||||
|
msgstr "Anwenden"
|
||||||
|
|
||||||
|
msgid "Reset"
|
||||||
|
msgstr "Zurücksetzen"
|
||||||
|
|
||||||
|
#, python-brace-format
|
||||||
|
msgid ""
|
||||||
|
"{created} ranges were created; {failed} IP addresses could not be processed."
|
||||||
|
msgstr "{created} Bereiche wurden angelegt; {failed} IP-Adressen konnten nicht verarbeitet werden."
|
||||||
|
|
||||||
|
#, python-brace-format
|
||||||
|
msgid ""
|
||||||
|
"{created} missing ranges were created. {skipped} host addresses were ignored."
|
||||||
|
msgstr "{created} fehlende Bereiche wurden angelegt. {skipped} Host-Adressen wurden ignoriert."
|
||||||
@@ -21,7 +21,7 @@ class Command(BaseCommand):
|
|||||||
skipped += int(ip_range is None)
|
skipped += int(ip_range is None)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
failed += 1
|
failed += 1
|
||||||
self.stderr.write(f"Fehler bei {address}: {exc}")
|
self.stderr.write(f"Error for {address}: {exc}")
|
||||||
verb = "würden erstellt" if options["dry_run"] else "erstellt"
|
verb = "would be created" if options["dry_run"] else "created"
|
||||||
message = f"{created} IP-Bereiche {verb}; {skipped} Hostmasken ignoriert; {failed} Fehler."
|
message = f"{created} IP ranges {verb}; {skipped} host masks ignored; {failed} errors."
|
||||||
self.stdout.write(self.style.SUCCESS(message) if not failed else self.style.WARNING(message))
|
self.stdout.write(self.style.SUCCESS(message) if not failed else self.style.WARNING(message))
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
from netbox.navigation import MenuItem
|
from netbox.navigation import MenuItem
|
||||||
|
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ def register_ipam_menu_item():
|
|||||||
*group.items,
|
*group.items,
|
||||||
MenuItem(
|
MenuItem(
|
||||||
link=link,
|
link=link,
|
||||||
link_text="IP-Netzübersicht",
|
link_text=_("IP Network Overview"),
|
||||||
permissions=["ipam.view_prefix"],
|
permissions=["ipam.view_prefix"],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
from ipam.tables import IPAddressTable
|
from ipam.tables import IPAddressTable
|
||||||
from utilities.tables import register_table_column
|
from utilities.tables import register_table_column
|
||||||
|
|
||||||
@@ -7,7 +8,7 @@ device_or_vm = tables.Column(
|
|||||||
accessor="assigned_object__parent_object",
|
accessor="assigned_object__parent_object",
|
||||||
linkify=True,
|
linkify=True,
|
||||||
orderable=False,
|
orderable=False,
|
||||||
verbose_name="Gerät / VM",
|
verbose_name=_("Device / VM"),
|
||||||
empty_values=(),
|
empty_values=(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from netbox.plugins import PluginTemplateExtension
|
|||||||
|
|
||||||
|
|
||||||
class IPRangeListActions(PluginTemplateExtension):
|
class IPRangeListActions(PluginTemplateExtension):
|
||||||
model = "ipam.iprange"
|
models = ["ipam.iprange"]
|
||||||
|
|
||||||
def list_buttons(self):
|
def list_buttons(self):
|
||||||
return self.render("netbox_better_ips/inc/iprange_list_buttons.html")
|
return self.render("netbox_better_ips/inc/iprange_list_buttons.html")
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
{% load i18n %}
|
||||||
{% if perms.ipam.view_prefix %}
|
{% if perms.ipam.view_prefix %}
|
||||||
<a href="{% url 'plugins:netbox_better_ips:network_overview' %}" class="btn btn-outline-primary">
|
<a href="{% url 'plugins:netbox_better_ips:network_overview' %}" class="btn btn-outline-primary">
|
||||||
<i class="mdi mdi-view-list" aria-hidden="true"></i>
|
<i class="mdi mdi-view-list" aria-hidden="true"></i>
|
||||||
Erweiterte Netzübersicht
|
{% trans "Extended network overview" %}
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if perms.ipam.view_ipaddress and perms.ipam.add_iprange %}
|
{% if perms.ipam.view_ipaddress and perms.ipam.add_iprange %}
|
||||||
@@ -9,7 +10,7 @@
|
|||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<button type="submit" class="btn btn-primary">
|
<button type="submit" class="btn btn-primary">
|
||||||
<i class="mdi mdi-auto-fix" aria-hidden="true"></i>
|
<i class="mdi mdi-auto-fix" aria-hidden="true"></i>
|
||||||
Alle fehlenden Bereiche anlegen
|
{% trans "Create all missing ranges" %}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
{% extends 'base/layout.html' %}
|
{% extends 'base/layout.html' %}
|
||||||
{% load helpers %}
|
{% load helpers i18n %}
|
||||||
|
|
||||||
{% block title %}IP-Netzübersicht{% endblock %}
|
{% block title %}{% trans "IP Network Overview" %}{% endblock %}
|
||||||
|
|
||||||
{% block header %}
|
{% block header %}
|
||||||
<div class="row align-items-center">
|
<div class="row align-items-center">
|
||||||
<div class="col"><h1>IP-Netzübersicht</h1></div>
|
<div class="col"><h1>{% trans "IP Network Overview" %}</h1></div>
|
||||||
<div class="col-auto text-secondary">{{ total_count }} Netze</div>
|
<div class="col-auto text-secondary">{% blocktrans count counter=total_count %}{{ counter }} network{% plural %}{{ counter }} networks{% endblocktrans %}</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-hover mb-0">
|
<table class="table table-hover mb-0">
|
||||||
<thead><tr><th>Netz</th><th>VRF</th><th>Scope</th><th>Mandant</th><th>Status</th><th>Beschreibung</th></tr></thead>
|
<thead><tr><th>{% trans "Network" %}</th><th>{% trans "VRF" %}</th><th>{% trans "Scope" %}</th><th>{% trans "Tenant" %}</th><th>{% trans "Status" %}</th><th>{% trans "Description" %}</th></tr></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for prefix in page_obj %}
|
{% for prefix in page_obj %}
|
||||||
<tr>
|
<tr>
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
<td>{{ prefix.description|placeholder }}</td>
|
<td>{{ prefix.description|placeholder }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% empty %}
|
{% empty %}
|
||||||
<tr><td colspan="6" class="text-center text-secondary py-4">Keine passenden Netze gefunden.</td></tr>
|
<tr><td colspan="6" class="text-center text-secondary py-4">{% trans "No matching networks found." %}</td></tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -36,19 +36,19 @@
|
|||||||
</div>
|
</div>
|
||||||
{% if page_obj.has_other_pages %}
|
{% if page_obj.has_other_pages %}
|
||||||
<nav class="mt-3"><ul class="pagination">
|
<nav class="mt-3"><ul class="pagination">
|
||||||
{% if page_obj.has_previous %}<li class="page-item"><a class="page-link" href="?{% querystring request page=page_obj.previous_page_number %}">Zurück</a></li>{% endif %}
|
{% if page_obj.has_previous %}<li class="page-item"><a class="page-link" href="?{% querystring request page=page_obj.previous_page_number %}">{% trans "Previous" %}</a></li>{% endif %}
|
||||||
<li class="page-item disabled"><span class="page-link">Seite {{ page_obj.number }} / {{ page_obj.paginator.num_pages }}</span></li>
|
<li class="page-item disabled"><span class="page-link">{% blocktrans with number=page_obj.number total=page_obj.paginator.num_pages %}Page {{ number }} of {{ total }}{% endblocktrans %}</span></li>
|
||||||
{% if page_obj.has_next %}<li class="page-item"><a class="page-link" href="?{% querystring request page=page_obj.next_page_number %}">Weiter</a></li>{% endif %}
|
{% if page_obj.has_next %}<li class="page-item"><a class="page-link" href="?{% querystring request page=page_obj.next_page_number %}">{% trans "Next" %}</a></li>{% endif %}
|
||||||
</ul></nav>
|
</ul></nav>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xl-3">
|
<div class="col-xl-3">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h2 class="card-header">Filter</h2>
|
<h2 class="card-header">{% trans "Filter" %}</h2>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form method="get">
|
<form method="get">
|
||||||
{% for field in filter_form %}<div class="mb-3">{{ field.label_tag }}{{ field }}</div>{% endfor %}
|
{% for field in filter_form %}<div class="mb-3">{{ field.label_tag }}{{ field }}</div>{% endfor %}
|
||||||
<div class="d-flex gap-2"><button class="btn btn-primary" type="submit">Filtern</button><a class="btn btn-outline-secondary" href=".">Zurücksetzen</a></div>
|
<div class="d-flex gap-2"><button class="btn btn-primary" type="submit">{% trans "Apply" %}</button><a class="btn btn-outline-secondary" href=".">{% trans "Reset" %}</a></div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from django.contrib.auth.mixins import PermissionRequiredMixin
|
|||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
from django.views.decorators.http import require_POST
|
from django.views.decorators.http import require_POST
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
from dcim.models import Location, Region, Site, SiteGroup
|
from dcim.models import Location, Region, Site, SiteGroup
|
||||||
@@ -112,11 +113,15 @@ def reconcile_missing_ranges(request):
|
|||||||
if failed:
|
if failed:
|
||||||
messages.warning(
|
messages.warning(
|
||||||
request,
|
request,
|
||||||
f"{created} Bereiche wurden angelegt; {failed} IP-Adressen konnten nicht verarbeitet werden.",
|
_("{created} ranges were created; {failed} IP addresses could not be processed.").format(
|
||||||
|
created=created, failed=failed
|
||||||
|
),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
messages.success(
|
messages.success(
|
||||||
request,
|
request,
|
||||||
f"{created} fehlende Bereiche wurden angelegt. {skipped} Host-Adressen wurden ignoriert.",
|
_("{created} missing ranges were created. {skipped} host addresses were ignored.").format(
|
||||||
|
created=created, skipped=skipped
|
||||||
|
),
|
||||||
)
|
)
|
||||||
return redirect("ipam:iprange_list")
|
return redirect("ipam:iprange_list")
|
||||||
+6
-2
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
[project]
|
[project]
|
||||||
name = "netbox-better-ips"
|
name = "netbox-better-ips"
|
||||||
version = "1.2.2"
|
version = "1.2.2"
|
||||||
description = "Automatic prefix creation and an organization-aware IP network overview for NetBox 4.6"
|
description = "Automatic IP ranges from IP addresses and an organisation-aware IP network overview for NetBox"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
license = {text = "Apache-2.0"}
|
license = {text = "Apache-2.0"}
|
||||||
@@ -21,4 +21,8 @@ classifiers = [
|
|||||||
include = ["netbox_better_ips*"]
|
include = ["netbox_better_ips*"]
|
||||||
|
|
||||||
[tool.setuptools.package-data]
|
[tool.setuptools.package-data]
|
||||||
netbox_better_ips = ["templates/**/*.html"]
|
netbox_better_ips = [
|
||||||
|
"templates/**/*.html",
|
||||||
|
"locale/*/LC_MESSAGES/*.po",
|
||||||
|
"locale/*/LC_MESSAGES/*.mo",
|
||||||
|
]
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
"""Keep README and packaging metadata in sync with the PluginConfig.
|
||||||
|
|
||||||
|
Runs without NetBox: `python -m unittest discover -s tests`.
|
||||||
|
"""
|
||||||
|
import ast
|
||||||
|
import re
|
||||||
|
import tomllib
|
||||||
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
|
||||||
|
|
||||||
|
def plugin_config():
|
||||||
|
tree = ast.parse((ROOT / "netbox_better_ips" / "__init__.py").read_text())
|
||||||
|
return {
|
||||||
|
node.targets[0].id: node.value.value
|
||||||
|
for node in ast.walk(tree)
|
||||||
|
if isinstance(node, ast.Assign)
|
||||||
|
and isinstance(node.targets[0], ast.Name)
|
||||||
|
and isinstance(node.value, ast.Constant)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def readme_range(max_version):
|
||||||
|
# max_version "4.7.99" is written as "4.7.x" in the README
|
||||||
|
major_minor, patch = max_version.rsplit(".", 1)
|
||||||
|
return major_minor + ".x" if patch == "99" else max_version
|
||||||
|
|
||||||
|
|
||||||
|
class MetadataTest(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.config = plugin_config()
|
||||||
|
self.readme = (ROOT / "README.md").read_text()
|
||||||
|
|
||||||
|
def test_readme_netbox_range_matches_plugin_config(self):
|
||||||
|
expected = f"`{self.config['min_version']}` – `{readme_range(self.config['max_version'])}`"
|
||||||
|
info_row = re.search(r"^\| \*\*NetBox\*\* \| (.+?) \|$", self.readme, re.M)
|
||||||
|
self.assertIsNotNone(info_row, "README info table has no NetBox row")
|
||||||
|
self.assertEqual(info_row.group(1), expected)
|
||||||
|
compatibility = self.readme.split("## Compatibility", 1)[1].split("\n## ", 1)[0]
|
||||||
|
self.assertIn(f"NetBox {expected}", compatibility)
|
||||||
|
|
||||||
|
def test_package_version_matches_plugin_config(self):
|
||||||
|
project = tomllib.loads((ROOT / "pyproject.toml").read_text())["project"]
|
||||||
|
self.assertEqual(project["version"], self.config["__version__"])
|
||||||
|
|
||||||
|
def test_translations_are_shipped(self):
|
||||||
|
package_data = tomllib.loads((ROOT / "pyproject.toml").read_text())["tool"]["setuptools"][
|
||||||
|
"package-data"
|
||||||
|
]["netbox_better_ips"]
|
||||||
|
self.assertIn("locale/*/LC_MESSAGES/*.mo", package_data)
|
||||||
|
self.assertTrue((ROOT / "netbox_better_ips/locale/de/LC_MESSAGES/django.mo").is_file())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in new issue
Block a user