feat(i18n): make UI translatable and add German translation #1

Open
MrBlake wants to merge 1 commits from feat/i18n into main
pull from: feat/i18n
13 changed files with 635 additions and 47 deletions

No files matched your search

+5
View File
@@ -1,5 +1,10 @@
# Changelog # Changelog
## Unreleased
- The UI, choices, validation and sync messages are translatable; German translation added.
- Added a test that keeps the NetBox version range in `README.md` and `COMPATIBILITY.md` in line with `min_version`/`max_version`.
## 0.3.3 ## 0.3.3
- Fixed `DuplicateColumn` (`column "provider" ... already exists`) when running migrations on - Fixed `DuplicateColumn` (`column "provider" ... already exists`) when running migrations on
+2
View File
@@ -20,3 +20,5 @@
| 0.2.6 | 4.4.0 | 4.6.x | | 0.2.6 | 4.4.0 | 4.6.x |
| 0.3.0 | 4.4.0 | 4.6.x | | 0.3.0 | 4.4.0 | 4.6.x |
| 0.3.1 | 4.6.5 | 4.6.8 | | 0.3.1 | 4.6.5 | 4.6.8 |
| 0.3.2 | 4.6.5 | 4.7.x |
| 0.3.3 | 4.6.5 | 4.7.x |
+8 -1
View File
@@ -34,7 +34,7 @@ guest data is incomplete.
## 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.2 and 4.7.3)
- Python `>=3.12` - Python `>=3.12`
- Dependencies installed automatically: `pyvmomi`, `cryptography` - Dependencies installed automatically: `pyvmomi`, `cryptography`
@@ -145,6 +145,13 @@ Proxmox support has been removed. Old Proxmox endpoints from earlier versions
remain visible in the list and detail view so they can be deleted; they can no remain visible in the list and detail view so they can be deleted; they can no
longer be edited, created or synchronised. longer be edited, created or synchronised.
### Language
The plugin is available in English and German. Switch the display language
as usual in the user profile (**Preferences → Language**). Translations live in
`netbox_vmware_importer/locale/de/LC_MESSAGES/`. Status messages stored on an
endpoint keep the language that was active when the sync ran.
## Security ## Security
The endpoint password is stored encrypted in the plugin table. The key is The endpoint password is stored encrypted in the plugin table. The key is
+2 -1
View File
@@ -3,6 +3,7 @@ import hashlib
from cryptography.fernet import Fernet, InvalidToken from cryptography.fernet import Fernet, InvalidToken
from django.conf import settings from django.conf import settings
from django.utils.translation import gettext as _
def _fernet(): def _fernet():
@@ -22,4 +23,4 @@ def decrypt_secret(value):
try: try:
return _fernet().decrypt(value.encode("ascii")).decode("utf-8") return _fernet().decrypt(value.encode("ascii")).decode("utf-8")
except InvalidToken as exc: except InvalidToken as exc:
raise ValueError("Stored endpoint password cannot be decrypted. Re-enter it on the endpoint.") from exc raise ValueError(_("Stored endpoint password cannot be decrypted. Re-enter it on the endpoint.")) from exc
+7 -5
View File
@@ -1,6 +1,7 @@
from core.choices import JobStatusChoices from core.choices import JobStatusChoices
from core.exceptions import JobFailed from core.exceptions import JobFailed
from django.utils import timezone from django.utils import timezone
from django.utils.translation import gettext as _
from netbox.jobs import JobRunner, system_job from netbox.jobs import JobRunner, system_job
from .choices import EndpointProviderChoices, SyncStatusChoices from .choices import EndpointProviderChoices, SyncStatusChoices
@@ -46,11 +47,12 @@ class SyncVCenterEndpointJob(JobRunner):
endpoint = VCenterEndpoint.objects.get(pk=endpoint_pk) endpoint = VCenterEndpoint.objects.get(pk=endpoint_pk)
if not endpoint.enabled: if not endpoint.enabled:
endpoint.mark_failure("Endpoint is disabled.") message = _("Endpoint is disabled.")
raise JobFailed("Endpoint is disabled.") endpoint.mark_failure(message)
raise JobFailed(message)
if endpoint.provider != EndpointProviderChoices.PROVIDER_VMWARE: if endpoint.provider != EndpointProviderChoices.PROVIDER_VMWARE:
message = "Legacy Proxmox endpoints are no longer supported. Delete this endpoint." message = _("Legacy Proxmox endpoints are no longer supported. Delete this endpoint.")
clear_endpoint_sync_schedule(endpoint) clear_endpoint_sync_schedule(endpoint)
endpoint.mark_failure(message) endpoint.mark_failure(message)
raise JobFailed(message) raise JobFailed(message)
@@ -72,7 +74,7 @@ class SyncVCenterEndpointJob(JobRunner):
endpoint.last_updated_count = result.updated endpoint.last_updated_count = result.updated
endpoint.last_error_count = result.errors endpoint.last_error_count = result.errors
endpoint.last_status = SyncStatusChoices.STATUS_FAILED endpoint.last_status = SyncStatusChoices.STATUS_FAILED
endpoint.last_message = f"Finished with {result.errors} VM error(s). Check the job log." endpoint.last_message = _("Finished with %(errors)s VM error(s). Check the job log.") % {"errors": result.errors}
endpoint.set_next_sync(endpoint.last_sync_at) endpoint.set_next_sync(endpoint.last_sync_at)
endpoint.save( endpoint.save(
update_fields=( update_fields=(
@@ -120,7 +122,7 @@ class ScheduleDueVCenterSyncsJob(JobRunner):
legacy_endpoints = VCenterEndpoint.objects.exclude(provider=EndpointProviderChoices.PROVIDER_VMWARE) legacy_endpoints = VCenterEndpoint.objects.exclude(provider=EndpointProviderChoices.PROVIDER_VMWARE)
cleared = 0 cleared = 0
for endpoint in legacy_endpoints: for endpoint in legacy_endpoints:
deleted_count, _ = clear_endpoint_sync_schedule(endpoint) deleted_count, __ = clear_endpoint_sync_schedule(endpoint)
cleared += deleted_count cleared += deleted_count
enabled_endpoints = VCenterEndpoint.objects.filter( enabled_endpoints = VCenterEndpoint.objects.filter(
@@ -0,0 +1,476 @@
# German translation of netbox-vmware-importer.
msgid ""
msgstr ""
"Project-Id-Version: netbox-vmware-importer\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-10-26 21:20+0100\n"
"PO-Revision-Date: 2026-10-26 21:30+0100\n"
"Last-Translator: \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"
#: choices.py:13
msgid "Never synced"
msgstr "Nie synchronisiert"
#: choices.py:14
msgid "Queued"
msgstr "In Warteschlange"
#: choices.py:15
msgid "Running"
msgstr "Läuft"
#: choices.py:16
msgid "Success"
msgstr "Erfolgreich"
#: choices.py:17
msgid "Failed"
msgstr "Fehlgeschlagen"
#: choices.py:26
msgid "VMware vSphere"
msgstr "VMware vSphere"
#: choices.py:27
msgid "Proxmox VE (legacy)"
msgstr "Proxmox VE (veraltet)"
#: choices.py:36
msgid "Username/password"
msgstr "Benutzername/Passwort"
#: choices.py:37
msgid "API token (legacy)"
msgstr "API-Token (veraltet)"
#: crypto.py:26
msgid ""
"Stored endpoint password cannot be decrypted. Re-enter it on the endpoint."
msgstr "Das gespeicherte Endpunkt-Passwort kann nicht entschlüsselt werden. Gib es am Endpunkt erneut ein."
#: forms.py:33
msgid "Password"
msgstr "Passwort"
#: forms.py:36
msgid "Leave blank to keep the currently stored password."
msgstr "Leer lassen, um das gespeicherte Passwort beizubehalten."
#: forms.py:40 forms.py:154
#: templates/netbox_vmware_importer/vcenterendpoint.html:14
msgid "Endpoint"
msgstr "Endpunkt"
#: forms.py:47
msgid "Connection"
msgstr "Verbindung"
#: forms.py:49
msgid "NetBox target"
msgstr "NetBox-Ziel"
#: forms.py:58
msgid "Sync behavior"
msgstr "Synchronisationsverhalten"
#: forms.py:60
msgid "Automation"
msgstr "Automatisierung"
#: forms.py:61
msgid "Tags"
msgstr "Tags"
#: forms.py:97
msgid "A password is required for new endpoints."
msgstr "Für neue Endpunkte ist ein Passwort erforderlich."
#: forms.py:124 models.py:30
#: templates/netbox_vmware_importer/vcenterendpoint.html:33
msgid "Enabled"
msgstr "Aktiviert"
#: forms.py:130 models.py:101
#: templates/netbox_vmware_importer/vcenterendpoint.html:48
msgid "Tenant"
msgstr "Mandant"
#: forms.py:135 models.py:109
#: templates/netbox_vmware_importer/vcenterendpoint.html:52
msgid "Site"
msgstr "Standort"
#: forms.py:140 models.py:117
#: templates/netbox_vmware_importer/vcenterendpoint.html:56
msgid "Cluster"
msgstr "Cluster"
#: forms.py:145 models.py:196 tables.py:25
#: templates/netbox_vmware_importer/vcenterendpoint.html:78
msgid "Last status"
msgstr "Letzter Status"
#: forms.py:150 models.py:34
#: templates/netbox_vmware_importer/vcenterendpoint.html:21
msgid "Provider"
msgstr "Anbieter"
#: jobs.py:50
msgid "Endpoint is disabled."
msgstr "Der Endpunkt ist deaktiviert."
#: jobs.py:55 sync.py:228
msgid "Legacy Proxmox endpoints are no longer supported. Delete this endpoint."
msgstr "Veraltete Proxmox-Endpunkte werden nicht mehr unterstützt. Lösche diesen Endpunkt."
#: jobs.py:77
#, python-format
msgid "Finished with %(errors)s VM error(s). Check the job log."
msgstr "Mit %(errors)s VM-Fehler(n) abgeschlossen. Prüfe das Job-Protokoll."
#: models.py:20 templates/netbox_vmware_importer/vcenterendpoint.html:17
msgid "Name"
msgstr "Name"
#: models.py:25
msgid "Slug"
msgstr "Slug"
#: models.py:40 templates/netbox_vmware_importer/vcenterendpoint.html:25
msgid "Host"
msgstr "Host"
#: models.py:42
msgid "vCenter or ESXi hostname or IP address"
msgstr "Hostname oder IP-Adresse von vCenter oder ESXi"
#: models.py:45
msgid "Port"
msgstr "Port"
#: models.py:50 templates/netbox_vmware_importer/vcenterendpoint.html:29
msgid "Username"
msgstr "Benutzername"
#: models.py:54
msgid "Authentication method"
msgstr "Authentifizierungsmethode"
#: models.py:60
msgid "Token name"
msgstr "Token-Name"
#: models.py:63
msgid "Legacy Proxmox API token ID. Kept only for deleting old endpoints."
msgstr "Veraltete Proxmox-API-Token-ID. Wird nur zum Löschen alter Endpunkte aufbewahrt."
#: models.py:70 templates/netbox_vmware_importer/vcenterendpoint.html:37
msgid "Validate SSL"
msgstr "SSL prüfen"
#: models.py:72
msgid "Validate the VMware endpoint certificate."
msgstr "Zertifikat des VMware-Endpunkts prüfen."
#: models.py:75
msgid "Request timeout (seconds)"
msgstr "Anfrage-Timeout (Sekunden)"
#: models.py:78
msgid "HTTP/API read timeout in seconds."
msgstr "HTTP-/API-Lese-Timeout in Sekunden."
#: models.py:81
msgid "Connect timeout (seconds)"
msgstr "Verbindungs-Timeout (Sekunden)"
#: models.py:84
msgid "TCP/TLS connection timeout in seconds."
msgstr "TCP-/TLS-Verbindungs-Timeout in Sekunden."
#: models.py:87
msgid "Maximum retries"
msgstr "Maximale Wiederholungen"
#: models.py:90
msgid ""
"Legacy connection retry setting. Kept only for compatibility with older "
"plugin versions."
msgstr "Veraltete Einstellung für Verbindungswiederholungen. Wird nur zur Kompatibilität mit älteren Plugin-Versionen aufbewahrt."
#: models.py:93
msgid "Retry backoff (seconds)"
msgstr "Wartezeit zwischen Wiederholungen (Sekunden)"
#: models.py:98
msgid "Exponential retry backoff base delay in seconds."
msgstr "Basisverzögerung des exponentiellen Backoffs in Sekunden."
#: models.py:121
msgid "NetBox cluster into which VMware VMs will be synchronized."
msgstr "NetBox-Cluster, in den die VMware-VMs synchronisiert werden."
#: models.py:124
msgid "Include name regex"
msgstr "Regex für einzuschließende Namen"
#: models.py:127
msgid "Only synchronize matching VM names. Leave empty to include all VMs."
msgstr "Nur passende VM-Namen synchronisieren. Leer lassen, um alle VMs einzuschließen."
#: models.py:130
msgid "Exclude name regex"
msgstr "Regex für auszuschließende Namen"
#: models.py:133
msgid "Skip matching VM names."
msgstr "Passende VM-Namen überspringen."
#: models.py:137
msgid "Sync powered-off VMs"
msgstr "Ausgeschaltete VMs synchronisieren"
#: models.py:140
msgid "Sync interfaces"
msgstr "Schnittstellen synchronisieren"
#: models.py:144
msgid "Sync IP addresses"
msgstr "IP-Adressen synchronisieren"
#: models.py:148
msgid "Sync primary IPs"
msgstr "Primäre IPs synchronisieren"
#: models.py:153
msgid "Sync legacy Proxmox LXC containers"
msgstr "Veraltete Proxmox-LXC-Container synchronisieren"
#: models.py:156
msgid "Update existing VMs"
msgstr "Vorhandene VMs aktualisieren"
#: models.py:158
msgid "Update existing VMs matched by name and cluster."
msgstr "Vorhandene VMs aktualisieren, die über Name und Cluster zugeordnet werden."
#: models.py:161
msgid "Default IPv4 prefix length"
msgstr "Standard-Präfixlänge IPv4"
#: models.py:166
msgid "Default IPv6 prefix length"
msgstr "Standard-Präfixlänge IPv6"
#: models.py:171
msgid "Sync interval (minutes)"
msgstr "Synchronisationsintervall (Minuten)"
#: models.py:175
msgid ""
"Optional automatic sync interval in minutes. Leave empty for manual sync "
"only."
msgstr "Optionales automatisches Synchronisationsintervall in Minuten. Leer lassen für ausschließlich manuelle Synchronisation."
#: models.py:178 templates/netbox_vmware_importer/vcenterendpoint.html:64
msgid "Next sync"
msgstr "Nächste Synchronisation"
#: models.py:184 templates/netbox_vmware_importer/vcenterendpoint.html:82
msgid "Last sync"
msgstr "Letzte Synchronisation"
#: models.py:190 templates/netbox_vmware_importer/vcenterendpoint.html:86
msgid "Last success"
msgstr "Letzter Erfolg"
#: models.py:203
msgid "Last message"
msgstr "Letzte Meldung"
#: models.py:209
msgid "Last VM count"
msgstr "Letzte VM-Anzahl"
#: models.py:214
msgid "Last created count"
msgstr "Zuletzt erstellt"
#: models.py:219
msgid "Last updated count"
msgstr "Zuletzt aktualisiert"
#: models.py:224
msgid "Last error count"
msgstr "Letzte Fehleranzahl"
#: models.py:229 templates/netbox_vmware_importer/vcenterendpoint.html:141
msgid "Comments"
msgstr "Kommentare"
#: models.py:256
msgid "VMware endpoint"
msgstr "VMware-Endpunkt"
#: models.py:257
msgid "VMware endpoints"
msgstr "VMware-Endpunkte"
#: models.py:282
#, python-format
msgid "Invalid regular expression: %(error)s"
msgstr "Ungültiger regulärer Ausdruck: %(error)s"
#: models.py:286
msgid "Selected cluster belongs to a different site."
msgstr "Der gewählte Cluster gehört zu einem anderen Standort."
#: models.py:290
msgid "Proxmox endpoints are legacy records and can only be deleted."
msgstr "Proxmox-Endpunkte sind veraltete Einträge und können nur gelöscht werden."
#: models.py:294
msgid "VMware endpoints support username/password authentication only."
msgstr "VMware-Endpunkte unterstützen nur die Anmeldung mit Benutzername und Passwort."
#: models.py:298
msgid "Sync job queued."
msgstr "Synchronisationsjob eingereiht."
#: models.py:304
msgid "Sync job running."
msgstr "Synchronisationsjob läuft."
#: models.py:317
#, python-format
msgid "Synchronized %(synced)s VM(s), skipped %(skipped)s VM(s)."
msgstr "%(synced)s VM(s) synchronisiert, %(skipped)s VM(s) übersprungen."
#: navigation.py:8
msgid "Endpoints"
msgstr "Endpunkte"
#: navigation.py:13
msgid "Add"
msgstr "Hinzufügen"
#: navigation.py:22
msgid "VMware Import"
msgstr "VMware-Import"
#: navigation.py:24
msgid "VMware"
msgstr "VMware"
#: sync.py:83
msgid "pyVmomi is not installed in the NetBox Python environment."
msgstr "pyVmomi ist in der Python-Umgebung von NetBox nicht installiert."
#: templates/netbox_vmware_importer/vcenterendpoint.html:7
msgid ""
"This is a legacy Proxmox endpoint from an older plugin version. Proxmox sync "
"is no longer supported; this endpoint can be deleted."
msgstr "Dies ist ein veralteter Proxmox-Endpunkt aus einer älteren Plugin-Version. Die Proxmox-Synchronisation wird nicht mehr unterstützt; dieser Endpunkt kann gelöscht werden."
#: templates/netbox_vmware_importer/vcenterendpoint.html:34
#: templates/netbox_vmware_importer/vcenterendpoint.html:38
msgid "Yes"
msgstr "Ja"
#: templates/netbox_vmware_importer/vcenterendpoint.html:34
#: templates/netbox_vmware_importer/vcenterendpoint.html:38
msgid "No"
msgstr "Nein"
#: templates/netbox_vmware_importer/vcenterendpoint.html:45
msgid "NetBox Target"
msgstr "NetBox-Ziel"
#: templates/netbox_vmware_importer/vcenterendpoint.html:60
msgid "Sync interval"
msgstr "Synchronisationsintervall"
#: templates/netbox_vmware_importer/vcenterendpoint.html:61
msgid "Manual only"
msgstr "Nur manuell"
#: templates/netbox_vmware_importer/vcenterendpoint.html:75
msgid "Sync"
msgstr "Synchronisation"
#: templates/netbox_vmware_importer/vcenterendpoint.html:90
msgid "VMs"
msgstr "VMs"
#: templates/netbox_vmware_importer/vcenterendpoint.html:91
#, python-format
msgid ""
"%(total)s total, %(created)s created, %(updated)s updated, %(errors)s errors"
msgstr "%(total)s gesamt, %(created)s erstellt, %(updated)s aktualisiert, %(errors)s Fehler"
#: templates/netbox_vmware_importer/vcenterendpoint.html:94
msgid "Message"
msgstr "Meldung"
#: templates/netbox_vmware_importer/vcenterendpoint.html:104
msgid "Start sync now"
msgstr "Synchronisation jetzt starten"
#: templates/netbox_vmware_importer/vcenterendpoint.html:114
msgid "Filters"
msgstr "Filter"
#: templates/netbox_vmware_importer/vcenterendpoint.html:117
msgid "Include regex"
msgstr "Einschluss-Regex"
#: templates/netbox_vmware_importer/vcenterendpoint.html:121
msgid "Exclude regex"
msgstr "Ausschluss-Regex"
#: templates/netbox_vmware_importer/vcenterendpoint.html:125
msgid "Powered off VMs"
msgstr "Ausgeschaltete VMs"
#: templates/netbox_vmware_importer/vcenterendpoint.html:126
msgid "Synced"
msgstr "Synchronisiert"
#: templates/netbox_vmware_importer/vcenterendpoint.html:126
msgid "Skipped"
msgstr "Übersprungen"
#: templates/netbox_vmware_importer/vcenterendpoint.html:129
msgid "Interfaces/IPs"
msgstr "Schnittstellen/IPs"
#: templates/netbox_vmware_importer/vcenterendpoint.html:130
msgid "Interfaces on"
msgstr "Schnittstellen an"
#: templates/netbox_vmware_importer/vcenterendpoint.html:130
msgid "Interfaces off"
msgstr "Schnittstellen aus"
#: templates/netbox_vmware_importer/vcenterendpoint.html:130
msgid "IPs on"
msgstr "IPs an"
#: templates/netbox_vmware_importer/vcenterendpoint.html:130
msgid "IPs off"
msgstr "IPs aus"
#: views.py:49
msgid "Legacy Proxmox endpoints can only be deleted."
msgstr "Veraltete Proxmox-Endpunkte können nur gelöscht werden."
#: views.py:54
#, python-format
msgid "VM sync job queued for %(endpoint)s."
msgstr "VM-Synchronisationsjob für %(endpoint)s eingereiht."
+36
View File
@@ -17,38 +17,47 @@ from .crypto import decrypt_secret, encrypt_secret
class VCenterEndpoint(JobsMixin, NetBoxModel): class VCenterEndpoint(JobsMixin, NetBoxModel):
name = models.CharField( name = models.CharField(
verbose_name=_("Name"),
max_length=100, max_length=100,
unique=True, unique=True,
) )
slug = models.SlugField( slug = models.SlugField(
verbose_name=_("Slug"),
max_length=100, max_length=100,
unique=True, unique=True,
) )
enabled = models.BooleanField( enabled = models.BooleanField(
verbose_name=_("Enabled"),
default=True, default=True,
) )
provider = models.CharField( provider = models.CharField(
verbose_name=_("Provider"),
max_length=30, max_length=30,
choices=EndpointProviderChoices, choices=EndpointProviderChoices,
default=EndpointProviderChoices.PROVIDER_VMWARE, default=EndpointProviderChoices.PROVIDER_VMWARE,
) )
host = models.CharField( host = models.CharField(
verbose_name=_("Host"),
max_length=255, max_length=255,
help_text=_("vCenter or ESXi hostname or IP address"), help_text=_("vCenter or ESXi hostname or IP address"),
) )
port = models.PositiveIntegerField( port = models.PositiveIntegerField(
verbose_name=_("Port"),
default=443, default=443,
validators=[MinValueValidator(1), MaxValueValidator(65535)], validators=[MinValueValidator(1), MaxValueValidator(65535)],
) )
username = models.CharField( username = models.CharField(
verbose_name=_("Username"),
max_length=255, max_length=255,
) )
auth_method = models.CharField( auth_method = models.CharField(
verbose_name=_("Authentication method"),
max_length=30, max_length=30,
choices=EndpointAuthMethodChoices, choices=EndpointAuthMethodChoices,
default=EndpointAuthMethodChoices.METHOD_PASSWORD, default=EndpointAuthMethodChoices.METHOD_PASSWORD,
) )
token_name = models.CharField( token_name = models.CharField(
verbose_name=_("Token name"),
max_length=100, max_length=100,
blank=True, blank=True,
help_text=_("Legacy Proxmox API token ID. Kept only for deleting old endpoints."), help_text=_("Legacy Proxmox API token ID. Kept only for deleting old endpoints."),
@@ -58,25 +67,30 @@ class VCenterEndpoint(JobsMixin, NetBoxModel):
editable=False, editable=False,
) )
validate_ssl = models.BooleanField( validate_ssl = models.BooleanField(
verbose_name=_("Validate SSL"),
default=False, default=False,
help_text=_("Validate the VMware endpoint certificate."), help_text=_("Validate the VMware endpoint certificate."),
) )
request_timeout_seconds = models.PositiveIntegerField( request_timeout_seconds = models.PositiveIntegerField(
verbose_name=_("Request timeout (seconds)"),
default=120, default=120,
validators=[MinValueValidator(5), MaxValueValidator(600)], validators=[MinValueValidator(5), MaxValueValidator(600)],
help_text=_("HTTP/API read timeout in seconds."), help_text=_("HTTP/API read timeout in seconds."),
) )
connect_timeout_seconds = models.PositiveIntegerField( connect_timeout_seconds = models.PositiveIntegerField(
verbose_name=_("Connect timeout (seconds)"),
default=10, default=10,
validators=[MinValueValidator(1), MaxValueValidator(120)], validators=[MinValueValidator(1), MaxValueValidator(120)],
help_text=_("TCP/TLS connection timeout in seconds."), help_text=_("TCP/TLS connection timeout in seconds."),
) )
max_retries = models.PositiveSmallIntegerField( max_retries = models.PositiveSmallIntegerField(
verbose_name=_("Maximum retries"),
default=0, default=0,
validators=[MinValueValidator(0), MaxValueValidator(10)], validators=[MinValueValidator(0), MaxValueValidator(10)],
help_text=_("Legacy connection retry setting. Kept only for compatibility with older plugin versions."), help_text=_("Legacy connection retry setting. Kept only for compatibility with older plugin versions."),
) )
retry_backoff_seconds = models.DecimalField( retry_backoff_seconds = models.DecimalField(
verbose_name=_("Retry backoff (seconds)"),
max_digits=5, max_digits=5,
decimal_places=2, decimal_places=2,
default=Decimal("0.50"), default=Decimal("0.50"),
@@ -84,6 +98,7 @@ class VCenterEndpoint(JobsMixin, NetBoxModel):
help_text=_("Exponential retry backoff base delay in seconds."), help_text=_("Exponential retry backoff base delay in seconds."),
) )
tenant = models.ForeignKey( tenant = models.ForeignKey(
verbose_name=_("Tenant"),
to="tenancy.Tenant", to="tenancy.Tenant",
on_delete=models.PROTECT, on_delete=models.PROTECT,
related_name="vmware_import_endpoints", related_name="vmware_import_endpoints",
@@ -91,6 +106,7 @@ class VCenterEndpoint(JobsMixin, NetBoxModel):
null=True, null=True,
) )
site = models.ForeignKey( site = models.ForeignKey(
verbose_name=_("Site"),
to="dcim.Site", to="dcim.Site",
on_delete=models.PROTECT, on_delete=models.PROTECT,
related_name="vmware_import_endpoints", related_name="vmware_import_endpoints",
@@ -98,17 +114,20 @@ class VCenterEndpoint(JobsMixin, NetBoxModel):
null=True, null=True,
) )
cluster = models.ForeignKey( cluster = models.ForeignKey(
verbose_name=_("Cluster"),
to="virtualization.Cluster", to="virtualization.Cluster",
on_delete=models.PROTECT, on_delete=models.PROTECT,
related_name="vmware_import_endpoints", related_name="vmware_import_endpoints",
help_text=_("NetBox cluster into which VMware VMs will be synchronized."), help_text=_("NetBox cluster into which VMware VMs will be synchronized."),
) )
include_name_regex = models.CharField( include_name_regex = models.CharField(
verbose_name=_("Include name regex"),
max_length=255, max_length=255,
blank=True, blank=True,
help_text=_("Only synchronize matching VM names. Leave empty to include all VMs."), help_text=_("Only synchronize matching VM names. Leave empty to include all VMs."),
) )
exclude_name_regex = models.CharField( exclude_name_regex = models.CharField(
verbose_name=_("Exclude name regex"),
max_length=255, max_length=255,
blank=True, blank=True,
help_text=_("Skip matching VM names."), help_text=_("Skip matching VM names."),
@@ -118,12 +137,15 @@ class VCenterEndpoint(JobsMixin, NetBoxModel):
verbose_name=_("Sync powered-off VMs"), verbose_name=_("Sync powered-off VMs"),
) )
sync_interfaces = models.BooleanField( sync_interfaces = models.BooleanField(
verbose_name=_("Sync interfaces"),
default=True, default=True,
) )
sync_ip_addresses = models.BooleanField( sync_ip_addresses = models.BooleanField(
verbose_name=_("Sync IP addresses"),
default=True, default=True,
) )
sync_primary_ips = models.BooleanField( sync_primary_ips = models.BooleanField(
verbose_name=_("Sync primary IPs"),
default=True, default=True,
) )
sync_lxc_containers = models.BooleanField( sync_lxc_containers = models.BooleanField(
@@ -131,66 +153,80 @@ class VCenterEndpoint(JobsMixin, NetBoxModel):
verbose_name=_("Sync legacy Proxmox LXC containers"), verbose_name=_("Sync legacy Proxmox LXC containers"),
) )
update_existing = models.BooleanField( update_existing = models.BooleanField(
verbose_name=_("Update existing VMs"),
default=True, default=True,
help_text=_("Update existing VMs matched by name and cluster."), help_text=_("Update existing VMs matched by name and cluster."),
) )
default_ipv4_prefix_length = models.PositiveSmallIntegerField( default_ipv4_prefix_length = models.PositiveSmallIntegerField(
verbose_name=_("Default IPv4 prefix length"),
default=24, default=24,
validators=[MinValueValidator(1), MaxValueValidator(32)], validators=[MinValueValidator(1), MaxValueValidator(32)],
) )
default_ipv6_prefix_length = models.PositiveSmallIntegerField( default_ipv6_prefix_length = models.PositiveSmallIntegerField(
verbose_name=_("Default IPv6 prefix length"),
default=64, default=64,
validators=[MinValueValidator(1), MaxValueValidator(128)], validators=[MinValueValidator(1), MaxValueValidator(128)],
) )
sync_interval_minutes = models.PositiveIntegerField( sync_interval_minutes = models.PositiveIntegerField(
verbose_name=_("Sync interval (minutes)"),
blank=True, blank=True,
null=True, null=True,
validators=[MinValueValidator(5)], validators=[MinValueValidator(5)],
help_text=_("Optional automatic sync interval in minutes. Leave empty for manual sync only."), help_text=_("Optional automatic sync interval in minutes. Leave empty for manual sync only."),
) )
next_sync_at = models.DateTimeField( next_sync_at = models.DateTimeField(
verbose_name=_("Next sync"),
blank=True, blank=True,
null=True, null=True,
editable=False, editable=False,
) )
last_sync_at = models.DateTimeField( last_sync_at = models.DateTimeField(
verbose_name=_("Last sync"),
blank=True, blank=True,
null=True, null=True,
editable=False, editable=False,
) )
last_success_at = models.DateTimeField( last_success_at = models.DateTimeField(
verbose_name=_("Last success"),
blank=True, blank=True,
null=True, null=True,
editable=False, editable=False,
) )
last_status = models.CharField( last_status = models.CharField(
verbose_name=_("Last status"),
max_length=30, max_length=30,
choices=SyncStatusChoices, choices=SyncStatusChoices,
default=SyncStatusChoices.STATUS_NEVER, default=SyncStatusChoices.STATUS_NEVER,
editable=False, editable=False,
) )
last_message = models.CharField( last_message = models.CharField(
verbose_name=_("Last message"),
max_length=500, max_length=500,
blank=True, blank=True,
editable=False, editable=False,
) )
last_vm_count = models.PositiveIntegerField( last_vm_count = models.PositiveIntegerField(
verbose_name=_("Last VM count"),
default=0, default=0,
editable=False, editable=False,
) )
last_created_count = models.PositiveIntegerField( last_created_count = models.PositiveIntegerField(
verbose_name=_("Last created count"),
default=0, default=0,
editable=False, editable=False,
) )
last_updated_count = models.PositiveIntegerField( last_updated_count = models.PositiveIntegerField(
verbose_name=_("Last updated count"),
default=0, default=0,
editable=False, editable=False,
) )
last_error_count = models.PositiveIntegerField( last_error_count = models.PositiveIntegerField(
verbose_name=_("Last error count"),
default=0, default=0,
editable=False, editable=False,
) )
comments = models.TextField( comments = models.TextField(
verbose_name=_("Comments"),
blank=True, blank=True,
) )
+5 -4
View File
@@ -1,15 +1,16 @@
from django.utils.translation import gettext_lazy as _
from netbox.choices import ButtonColorChoices from netbox.choices import ButtonColorChoices
from netbox.plugins import PluginMenu, PluginMenuButton, PluginMenuItem from netbox.plugins import PluginMenu, PluginMenuButton, PluginMenuItem
endpoint_item = PluginMenuItem( endpoint_item = PluginMenuItem(
link="plugins:netbox_vmware_importer:vcenterendpoint_list", link="plugins:netbox_vmware_importer:vcenterendpoint_list",
link_text="Endpoints", link_text=_("Endpoints"),
permissions=["netbox_vmware_importer.view_vcenterendpoint"], permissions=["netbox_vmware_importer.view_vcenterendpoint"],
buttons=( buttons=(
PluginMenuButton( PluginMenuButton(
"plugins:netbox_vmware_importer:vcenterendpoint_add", "plugins:netbox_vmware_importer:vcenterendpoint_add",
"Add", _("Add"),
"mdi mdi-plus-thick", "mdi mdi-plus-thick",
ButtonColorChoices.GREEN, ButtonColorChoices.GREEN,
permissions=["netbox_vmware_importer.add_vcenterendpoint"], permissions=["netbox_vmware_importer.add_vcenterendpoint"],
@@ -18,9 +19,9 @@ endpoint_item = PluginMenuItem(
) )
menu = PluginMenu( menu = PluginMenu(
label="VMware Import", label=_("VMware Import"),
groups=( groups=(
("VMware", (endpoint_item,)), (_("VMware"), (endpoint_item,)),
), ),
icon_class="mdi mdi-cloud-sync", icon_class="mdi mdi-cloud-sync",
) )
+3 -2
View File
@@ -6,6 +6,7 @@ from dataclasses import dataclass, field
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.db import transaction from django.db import transaction
from django.db.models import Sum from django.db.models import Sum
from django.utils.translation import gettext as _
from dcim.models import MACAddress, Platform from dcim.models import MACAddress, Platform
from ipam.models import IPAddress from ipam.models import IPAddress
from virtualization.models import VMInterface, VirtualDisk, VirtualMachine from virtualization.models import VMInterface, VirtualDisk, VirtualMachine
@@ -79,7 +80,7 @@ class VMwareClient:
def __enter__(self): def __enter__(self):
if SmartConnect is None: if SmartConnect is None:
raise VMwareConnectionError("pyVmomi is not installed in the NetBox Python environment.") raise VMwareConnectionError(_("pyVmomi is not installed in the NetBox Python environment."))
ssl_context = None ssl_context = None
if not self.endpoint.validate_ssl: if not self.endpoint.validate_ssl:
@@ -224,7 +225,7 @@ class VMwareImporter:
def sync(self): def sync(self):
if self.endpoint.provider != EndpointProviderChoices.PROVIDER_VMWARE: if self.endpoint.provider != EndpointProviderChoices.PROVIDER_VMWARE:
raise VMwareConnectionError("Legacy Proxmox endpoints are no longer supported. Delete this endpoint.") raise VMwareConnectionError(_("Legacy Proxmox endpoints are no longer supported. Delete this endpoint."))
result = SyncResult() result = SyncResult()
platforms = list(Platform.objects.all()) platforms = list(Platform.objects.all())
@@ -1,66 +1,67 @@
{% extends 'generic/object.html' %} {% extends 'generic/object.html' %}
{% load i18n %}
{% block content %} {% block content %}
{% if object.provider != "vmware" %} {% if object.provider != "vmware" %}
<div class="alert alert-warning" role="alert"> <div class="alert alert-warning" role="alert">
This is a legacy Proxmox endpoint from an older plugin version. Proxmox sync is no longer supported; this endpoint can be deleted. {% trans "This is a legacy Proxmox endpoint from an older plugin version. Proxmox sync is no longer supported; this endpoint can be deleted." %}
</div> </div>
{% endif %} {% endif %}
<div class="row mb-3"> <div class="row mb-3">
<div class="col col-md-6"> <div class="col col-md-6">
<div class="card"> <div class="card">
<h5 class="card-header">Endpoint</h5> <h5 class="card-header">{% trans "Endpoint" %}</h5>
<table class="table table-hover attr-table"> <table class="table table-hover attr-table">
<tr> <tr>
<th scope="row">Name</th> <th scope="row">{% trans "Name" %}</th>
<td>{{ object.name }}</td> <td>{{ object.name }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Provider</th> <th scope="row">{% trans "Provider" %}</th>
<td>{{ object.get_provider_display }}</td> <td>{{ object.get_provider_display }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Host</th> <th scope="row">{% trans "Host" %}</th>
<td>{{ object.host }}:{{ object.port }}</td> <td>{{ object.host }}:{{ object.port }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Username</th> <th scope="row">{% trans "Username" %}</th>
<td>{{ object.username }}</td> <td>{{ object.username }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Enabled</th> <th scope="row">{% trans "Enabled" %}</th>
<td>{{ object.enabled|yesno:"Yes,No" }}</td> <td>{% if object.enabled %}{% trans "Yes" %}{% else %}{% trans "No" %}{% endif %}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Validate SSL</th> <th scope="row">{% trans "Validate SSL" %}</th>
<td>{{ object.validate_ssl|yesno:"Yes,No" }}</td> <td>{% if object.validate_ssl %}{% trans "Yes" %}{% else %}{% trans "No" %}{% endif %}</td>
</tr> </tr>
</table> </table>
</div> </div>
</div> </div>
<div class="col col-md-6"> <div class="col col-md-6">
<div class="card"> <div class="card">
<h5 class="card-header">NetBox Target</h5> <h5 class="card-header">{% trans "NetBox Target" %}</h5>
<table class="table table-hover attr-table"> <table class="table table-hover attr-table">
<tr> <tr>
<th scope="row">Tenant</th> <th scope="row">{% trans "Tenant" %}</th>
<td>{{ object.tenant|default:"-" }}</td> <td>{{ object.tenant|default:"-" }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Site</th> <th scope="row">{% trans "Site" %}</th>
<td>{{ object.site|default:"-" }}</td> <td>{{ object.site|default:"-" }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Cluster</th> <th scope="row">{% trans "Cluster" %}</th>
<td>{{ object.cluster }}</td> <td>{{ object.cluster }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Sync interval</th> <th scope="row">{% trans "Sync interval" %}</th>
<td>{{ object.sync_interval_minutes|default:"Manual only" }}</td> <td>{% if object.sync_interval_minutes %}{{ object.sync_interval_minutes }}{% else %}{% trans "Manual only" %}{% endif %}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Next sync</th> <th scope="row">{% trans "Next sync" %}</th>
<td>{{ object.next_sync_at|default:"-" }}</td> <td>{{ object.next_sync_at|default:"-" }}</td>
</tr> </tr>
</table> </table>
@@ -71,26 +72,26 @@
<div class="row mb-3"> <div class="row mb-3">
<div class="col col-md-6"> <div class="col col-md-6">
<div class="card"> <div class="card">
<h5 class="card-header">Sync</h5> <h5 class="card-header">{% trans "Sync" %}</h5>
<table class="table table-hover attr-table"> <table class="table table-hover attr-table">
<tr> <tr>
<th scope="row">Last status</th> <th scope="row">{% trans "Last status" %}</th>
<td>{{ object.get_last_status_display }}</td> <td>{{ object.get_last_status_display }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Last sync</th> <th scope="row">{% trans "Last sync" %}</th>
<td>{{ object.last_sync_at|default:"-" }}</td> <td>{{ object.last_sync_at|default:"-" }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Last success</th> <th scope="row">{% trans "Last success" %}</th>
<td>{{ object.last_success_at|default:"-" }}</td> <td>{{ object.last_success_at|default:"-" }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">VMs</th> <th scope="row">{% trans "VMs" %}</th>
<td>{{ object.last_vm_count }} total, {{ object.last_created_count }} created, {{ object.last_updated_count }} updated, {{ object.last_error_count }} errors</td> <td>{% blocktrans with total=object.last_vm_count created=object.last_created_count updated=object.last_updated_count errors=object.last_error_count %}{{ total }} total, {{ created }} created, {{ updated }} updated, {{ errors }} errors{% endblocktrans %}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Message</th> <th scope="row">{% trans "Message" %}</th>
<td>{{ object.last_message|default:"-" }}</td> <td>{{ object.last_message|default:"-" }}</td>
</tr> </tr>
</table> </table>
@@ -100,7 +101,7 @@
<form method="post" action="{% url 'plugins:netbox_vmware_importer:vcenterendpoint_sync' pk=object.pk %}"> <form method="post" action="{% url 'plugins:netbox_vmware_importer:vcenterendpoint_sync' pk=object.pk %}">
{% csrf_token %} {% csrf_token %}
<button type="submit" class="btn btn-primary"> <button type="submit" class="btn btn-primary">
<i class="mdi mdi-sync"></i> Sync jetzt starten <i class="mdi mdi-sync"></i> {% trans "Start sync now" %}
</button> </button>
</form> </form>
</div> </div>
@@ -110,23 +111,23 @@
</div> </div>
<div class="col col-md-6"> <div class="col col-md-6">
<div class="card"> <div class="card">
<h5 class="card-header">Filters</h5> <h5 class="card-header">{% trans "Filters" %}</h5>
<table class="table table-hover attr-table"> <table class="table table-hover attr-table">
<tr> <tr>
<th scope="row">Include regex</th> <th scope="row">{% trans "Include regex" %}</th>
<td>{{ object.include_name_regex|default:"-" }}</td> <td>{{ object.include_name_regex|default:"-" }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Exclude regex</th> <th scope="row">{% trans "Exclude regex" %}</th>
<td>{{ object.exclude_name_regex|default:"-" }}</td> <td>{{ object.exclude_name_regex|default:"-" }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Powered off VMs</th> <th scope="row">{% trans "Powered off VMs" %}</th>
<td>{{ object.sync_powered_off|yesno:"Synced,Skipped" }}</td> <td>{% if object.sync_powered_off %}{% trans "Synced" %}{% else %}{% trans "Skipped" %}{% endif %}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Interfaces/IPs</th> <th scope="row">{% trans "Interfaces/IPs" %}</th>
<td>{{ object.sync_interfaces|yesno:"Interfaces on,Interfaces off" }} / {{ object.sync_ip_addresses|yesno:"IPs on,IPs off" }}</td> <td>{% if object.sync_interfaces %}{% trans "Interfaces on" %}{% else %}{% trans "Interfaces off" %}{% endif %} / {% if object.sync_ip_addresses %}{% trans "IPs on" %}{% else %}{% trans "IPs off" %}{% endif %}</td>
</tr> </tr>
</table> </table>
</div> </div>
@@ -137,7 +138,7 @@
<div class="row mb-3"> <div class="row mb-3">
<div class="col"> <div class="col">
<div class="card"> <div class="card">
<h5 class="card-header">Comments</h5> <h5 class="card-header">{% trans "Comments" %}</h5>
<div class="card-body rendered-markdown"> <div class="card-body rendered-markdown">
{{ object.comments|linebreaksbr }} {{ object.comments|linebreaksbr }}
</div> </div>
+5 -1
View File
@@ -28,4 +28,8 @@ dependencies = [
include = ["netbox_vmware_importer*"] include = ["netbox_vmware_importer*"]
[tool.setuptools.package-data] [tool.setuptools.package-data]
netbox_vmware_importer = ["templates/**/*.html"] netbox_vmware_importer = [
"templates/**/*.html",
"locale/*/LC_MESSAGES/*.po",
"locale/*/LC_MESSAGES/*.mo",
]
+52
View File
@@ -0,0 +1,52 @@
"""Keeps the documented NetBox range in line with the PluginConfig."""
import ast
import re
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
def plugin_config():
tree = ast.parse((ROOT / "netbox_vmware_importer" / "__init__.py").read_text())
values = {}
for node in ast.walk(tree):
if isinstance(node, ast.Assign) and isinstance(node.value, ast.Constant):
for target in node.targets:
if isinstance(target, ast.Name):
values[target.id] = node.value.value
return values
def documented(version):
# "4.7.99" is the conventional upper bound for "any 4.7 release"
return re.sub(r"\.99$", ".x", version)
class CompatibilityTest(unittest.TestCase):
def setUp(self):
config = plugin_config()
self.version = config["version"]
self.min_version = documented(config["min_version"])
self.max_version = documented(config["max_version"])
def test_readme_matches_plugin_config(self):
readme = (ROOT / "README.md").read_text()
expected = f"`{self.min_version}` – `{self.max_version}`"
self.assertIn(f"| **NetBox** | {expected} |", readme)
self.assertIn(f"- NetBox {expected}", readme)
def test_compatibility_matrix_lists_current_release(self):
matrix = (ROOT / "COMPATIBILITY.md").read_text()
row = re.search(rf"^\|\s*{re.escape(self.version)}\s*\|\s*(\S+)\s*\|\s*(\S+)\s*\|$", matrix, re.M)
self.assertIsNotNone(row, f"COMPATIBILITY.md has no row for {self.version}")
self.assertEqual(row.groups(), (self.min_version, self.max_version))
def test_pyproject_version_matches_plugin_config(self):
pyproject = (ROOT / "pyproject.toml").read_text()
self.assertIn(f'version = "{self.version}"', pyproject)
if __name__ == "__main__":
unittest.main()