diff --git a/CHANGELOG.md b/CHANGELOG.md index fd5cf1f..a1117ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 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 - Fixed `DuplicateColumn` (`column "provider" ... already exists`) when running migrations on diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 4cfeab0..66659f2 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -20,3 +20,5 @@ | 0.2.6 | 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.2 | 4.6.5 | 4.7.x | +| 0.3.3 | 4.6.5 | 4.7.x | diff --git a/README.md b/README.md index 9dd71c6..23c7260 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ guest data is incomplete. ## 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` - 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 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 The endpoint password is stored encrypted in the plugin table. The key is diff --git a/netbox_vmware_importer/crypto.py b/netbox_vmware_importer/crypto.py index e12108a..4c6c3a5 100644 --- a/netbox_vmware_importer/crypto.py +++ b/netbox_vmware_importer/crypto.py @@ -3,6 +3,7 @@ import hashlib from cryptography.fernet import Fernet, InvalidToken from django.conf import settings +from django.utils.translation import gettext as _ def _fernet(): @@ -22,4 +23,4 @@ def decrypt_secret(value): try: return _fernet().decrypt(value.encode("ascii")).decode("utf-8") 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 diff --git a/netbox_vmware_importer/jobs.py b/netbox_vmware_importer/jobs.py index 3daacb5..9bd654a 100644 --- a/netbox_vmware_importer/jobs.py +++ b/netbox_vmware_importer/jobs.py @@ -1,6 +1,7 @@ from core.choices import JobStatusChoices from core.exceptions import JobFailed from django.utils import timezone +from django.utils.translation import gettext as _ from netbox.jobs import JobRunner, system_job from .choices import EndpointProviderChoices, SyncStatusChoices @@ -46,11 +47,12 @@ class SyncVCenterEndpointJob(JobRunner): endpoint = VCenterEndpoint.objects.get(pk=endpoint_pk) if not endpoint.enabled: - endpoint.mark_failure("Endpoint is disabled.") - raise JobFailed("Endpoint is disabled.") + message = _("Endpoint is disabled.") + endpoint.mark_failure(message) + raise JobFailed(message) 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) endpoint.mark_failure(message) raise JobFailed(message) @@ -72,7 +74,7 @@ class SyncVCenterEndpointJob(JobRunner): endpoint.last_updated_count = result.updated endpoint.last_error_count = result.errors 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.save( update_fields=( @@ -120,7 +122,7 @@ class ScheduleDueVCenterSyncsJob(JobRunner): legacy_endpoints = VCenterEndpoint.objects.exclude(provider=EndpointProviderChoices.PROVIDER_VMWARE) cleared = 0 for endpoint in legacy_endpoints: - deleted_count, _ = clear_endpoint_sync_schedule(endpoint) + deleted_count, __ = clear_endpoint_sync_schedule(endpoint) cleared += deleted_count enabled_endpoints = VCenterEndpoint.objects.filter( diff --git a/netbox_vmware_importer/locale/de/LC_MESSAGES/django.mo b/netbox_vmware_importer/locale/de/LC_MESSAGES/django.mo new file mode 100644 index 0000000..abf7a98 Binary files /dev/null and b/netbox_vmware_importer/locale/de/LC_MESSAGES/django.mo differ diff --git a/netbox_vmware_importer/locale/de/LC_MESSAGES/django.po b/netbox_vmware_importer/locale/de/LC_MESSAGES/django.po new file mode 100644 index 0000000..0a58b41 --- /dev/null +++ b/netbox_vmware_importer/locale/de/LC_MESSAGES/django.po @@ -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." diff --git a/netbox_vmware_importer/models.py b/netbox_vmware_importer/models.py index 4ee52fc..f87d0bd 100644 --- a/netbox_vmware_importer/models.py +++ b/netbox_vmware_importer/models.py @@ -17,38 +17,47 @@ from .crypto import decrypt_secret, encrypt_secret class VCenterEndpoint(JobsMixin, NetBoxModel): name = models.CharField( + verbose_name=_("Name"), max_length=100, unique=True, ) slug = models.SlugField( + verbose_name=_("Slug"), max_length=100, unique=True, ) enabled = models.BooleanField( + verbose_name=_("Enabled"), default=True, ) provider = models.CharField( + verbose_name=_("Provider"), max_length=30, choices=EndpointProviderChoices, default=EndpointProviderChoices.PROVIDER_VMWARE, ) host = models.CharField( + verbose_name=_("Host"), max_length=255, help_text=_("vCenter or ESXi hostname or IP address"), ) port = models.PositiveIntegerField( + verbose_name=_("Port"), default=443, validators=[MinValueValidator(1), MaxValueValidator(65535)], ) username = models.CharField( + verbose_name=_("Username"), max_length=255, ) auth_method = models.CharField( + verbose_name=_("Authentication method"), max_length=30, choices=EndpointAuthMethodChoices, default=EndpointAuthMethodChoices.METHOD_PASSWORD, ) token_name = models.CharField( + verbose_name=_("Token name"), max_length=100, blank=True, help_text=_("Legacy Proxmox API token ID. Kept only for deleting old endpoints."), @@ -58,25 +67,30 @@ class VCenterEndpoint(JobsMixin, NetBoxModel): editable=False, ) validate_ssl = models.BooleanField( + verbose_name=_("Validate SSL"), default=False, help_text=_("Validate the VMware endpoint certificate."), ) request_timeout_seconds = models.PositiveIntegerField( + verbose_name=_("Request timeout (seconds)"), default=120, validators=[MinValueValidator(5), MaxValueValidator(600)], help_text=_("HTTP/API read timeout in seconds."), ) connect_timeout_seconds = models.PositiveIntegerField( + verbose_name=_("Connect timeout (seconds)"), default=10, validators=[MinValueValidator(1), MaxValueValidator(120)], help_text=_("TCP/TLS connection timeout in seconds."), ) max_retries = models.PositiveSmallIntegerField( + verbose_name=_("Maximum retries"), default=0, validators=[MinValueValidator(0), MaxValueValidator(10)], help_text=_("Legacy connection retry setting. Kept only for compatibility with older plugin versions."), ) retry_backoff_seconds = models.DecimalField( + verbose_name=_("Retry backoff (seconds)"), max_digits=5, decimal_places=2, default=Decimal("0.50"), @@ -84,6 +98,7 @@ class VCenterEndpoint(JobsMixin, NetBoxModel): help_text=_("Exponential retry backoff base delay in seconds."), ) tenant = models.ForeignKey( + verbose_name=_("Tenant"), to="tenancy.Tenant", on_delete=models.PROTECT, related_name="vmware_import_endpoints", @@ -91,6 +106,7 @@ class VCenterEndpoint(JobsMixin, NetBoxModel): null=True, ) site = models.ForeignKey( + verbose_name=_("Site"), to="dcim.Site", on_delete=models.PROTECT, related_name="vmware_import_endpoints", @@ -98,17 +114,20 @@ class VCenterEndpoint(JobsMixin, NetBoxModel): null=True, ) cluster = models.ForeignKey( + verbose_name=_("Cluster"), to="virtualization.Cluster", on_delete=models.PROTECT, related_name="vmware_import_endpoints", help_text=_("NetBox cluster into which VMware VMs will be synchronized."), ) include_name_regex = models.CharField( + verbose_name=_("Include name regex"), max_length=255, blank=True, help_text=_("Only synchronize matching VM names. Leave empty to include all VMs."), ) exclude_name_regex = models.CharField( + verbose_name=_("Exclude name regex"), max_length=255, blank=True, help_text=_("Skip matching VM names."), @@ -118,12 +137,15 @@ class VCenterEndpoint(JobsMixin, NetBoxModel): verbose_name=_("Sync powered-off VMs"), ) sync_interfaces = models.BooleanField( + verbose_name=_("Sync interfaces"), default=True, ) sync_ip_addresses = models.BooleanField( + verbose_name=_("Sync IP addresses"), default=True, ) sync_primary_ips = models.BooleanField( + verbose_name=_("Sync primary IPs"), default=True, ) sync_lxc_containers = models.BooleanField( @@ -131,66 +153,80 @@ class VCenterEndpoint(JobsMixin, NetBoxModel): verbose_name=_("Sync legacy Proxmox LXC containers"), ) update_existing = models.BooleanField( + verbose_name=_("Update existing VMs"), default=True, help_text=_("Update existing VMs matched by name and cluster."), ) default_ipv4_prefix_length = models.PositiveSmallIntegerField( + verbose_name=_("Default IPv4 prefix length"), default=24, validators=[MinValueValidator(1), MaxValueValidator(32)], ) default_ipv6_prefix_length = models.PositiveSmallIntegerField( + verbose_name=_("Default IPv6 prefix length"), default=64, validators=[MinValueValidator(1), MaxValueValidator(128)], ) sync_interval_minutes = models.PositiveIntegerField( + verbose_name=_("Sync interval (minutes)"), blank=True, null=True, validators=[MinValueValidator(5)], help_text=_("Optional automatic sync interval in minutes. Leave empty for manual sync only."), ) next_sync_at = models.DateTimeField( + verbose_name=_("Next sync"), blank=True, null=True, editable=False, ) last_sync_at = models.DateTimeField( + verbose_name=_("Last sync"), blank=True, null=True, editable=False, ) last_success_at = models.DateTimeField( + verbose_name=_("Last success"), blank=True, null=True, editable=False, ) last_status = models.CharField( + verbose_name=_("Last status"), max_length=30, choices=SyncStatusChoices, default=SyncStatusChoices.STATUS_NEVER, editable=False, ) last_message = models.CharField( + verbose_name=_("Last message"), max_length=500, blank=True, editable=False, ) last_vm_count = models.PositiveIntegerField( + verbose_name=_("Last VM count"), default=0, editable=False, ) last_created_count = models.PositiveIntegerField( + verbose_name=_("Last created count"), default=0, editable=False, ) last_updated_count = models.PositiveIntegerField( + verbose_name=_("Last updated count"), default=0, editable=False, ) last_error_count = models.PositiveIntegerField( + verbose_name=_("Last error count"), default=0, editable=False, ) comments = models.TextField( + verbose_name=_("Comments"), blank=True, ) diff --git a/netbox_vmware_importer/navigation.py b/netbox_vmware_importer/navigation.py index 0caec39..bb3b326 100644 --- a/netbox_vmware_importer/navigation.py +++ b/netbox_vmware_importer/navigation.py @@ -1,15 +1,16 @@ +from django.utils.translation import gettext_lazy as _ from netbox.choices import ButtonColorChoices from netbox.plugins import PluginMenu, PluginMenuButton, PluginMenuItem endpoint_item = PluginMenuItem( link="plugins:netbox_vmware_importer:vcenterendpoint_list", - link_text="Endpoints", + link_text=_("Endpoints"), permissions=["netbox_vmware_importer.view_vcenterendpoint"], buttons=( PluginMenuButton( "plugins:netbox_vmware_importer:vcenterendpoint_add", - "Add", + _("Add"), "mdi mdi-plus-thick", ButtonColorChoices.GREEN, permissions=["netbox_vmware_importer.add_vcenterendpoint"], @@ -18,9 +19,9 @@ endpoint_item = PluginMenuItem( ) menu = PluginMenu( - label="VMware Import", + label=_("VMware Import"), groups=( - ("VMware", (endpoint_item,)), + (_("VMware"), (endpoint_item,)), ), icon_class="mdi mdi-cloud-sync", ) diff --git a/netbox_vmware_importer/sync.py b/netbox_vmware_importer/sync.py index dbb7d51..05bd172 100644 --- a/netbox_vmware_importer/sync.py +++ b/netbox_vmware_importer/sync.py @@ -6,6 +6,7 @@ from dataclasses import dataclass, field from django.contrib.contenttypes.models import ContentType from django.db import transaction from django.db.models import Sum +from django.utils.translation import gettext as _ from dcim.models import MACAddress, Platform from ipam.models import IPAddress from virtualization.models import VMInterface, VirtualDisk, VirtualMachine @@ -79,7 +80,7 @@ class VMwareClient: def __enter__(self): 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 if not self.endpoint.validate_ssl: @@ -224,7 +225,7 @@ class VMwareImporter: def sync(self): 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() platforms = list(Platform.objects.all()) diff --git a/netbox_vmware_importer/templates/netbox_vmware_importer/vcenterendpoint.html b/netbox_vmware_importer/templates/netbox_vmware_importer/vcenterendpoint.html index 3946284..81443c8 100644 --- a/netbox_vmware_importer/templates/netbox_vmware_importer/vcenterendpoint.html +++ b/netbox_vmware_importer/templates/netbox_vmware_importer/vcenterendpoint.html @@ -1,66 +1,67 @@ {% extends 'generic/object.html' %} +{% load i18n %} {% block content %} {% if object.provider != "vmware" %} {% endif %}
-
Endpoint
+
{% trans "Endpoint" %}
- + - + - + - + - - + + - - + +
Name{% trans "Name" %} {{ object.name }}
Provider{% trans "Provider" %} {{ object.get_provider_display }}
Host{% trans "Host" %} {{ object.host }}:{{ object.port }}
Username{% trans "Username" %} {{ object.username }}
Enabled{{ object.enabled|yesno:"Yes,No" }}{% trans "Enabled" %}{% if object.enabled %}{% trans "Yes" %}{% else %}{% trans "No" %}{% endif %}
Validate SSL{{ object.validate_ssl|yesno:"Yes,No" }}{% trans "Validate SSL" %}{% if object.validate_ssl %}{% trans "Yes" %}{% else %}{% trans "No" %}{% endif %}
-
NetBox Target
+
{% trans "NetBox Target" %}
- + - + - + - - + + - +
Tenant{% trans "Tenant" %} {{ object.tenant|default:"-" }}
Site{% trans "Site" %} {{ object.site|default:"-" }}
Cluster{% trans "Cluster" %} {{ object.cluster }}
Sync interval{{ object.sync_interval_minutes|default:"Manual only" }}{% trans "Sync interval" %}{% if object.sync_interval_minutes %}{{ object.sync_interval_minutes }}{% else %}{% trans "Manual only" %}{% endif %}
Next sync{% trans "Next sync" %} {{ object.next_sync_at|default:"-" }}
@@ -71,26 +72,26 @@
-
Sync
+
{% trans "Sync" %}
- + - + - + - - + + - +
Last status{% trans "Last status" %} {{ object.get_last_status_display }}
Last sync{% trans "Last sync" %} {{ object.last_sync_at|default:"-" }}
Last success{% trans "Last success" %} {{ object.last_success_at|default:"-" }}
VMs{{ object.last_vm_count }} total, {{ object.last_created_count }} created, {{ object.last_updated_count }} updated, {{ object.last_error_count }} errors{% trans "VMs" %}{% 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 %}
Message{% trans "Message" %} {{ object.last_message|default:"-" }}
@@ -100,7 +101,7 @@
{% csrf_token %}
@@ -110,23 +111,23 @@
-
Filters
+
{% trans "Filters" %}
- + - + - - + + - - + +
Include regex{% trans "Include regex" %} {{ object.include_name_regex|default:"-" }}
Exclude regex{% trans "Exclude regex" %} {{ object.exclude_name_regex|default:"-" }}
Powered off VMs{{ object.sync_powered_off|yesno:"Synced,Skipped" }}{% trans "Powered off VMs" %}{% if object.sync_powered_off %}{% trans "Synced" %}{% else %}{% trans "Skipped" %}{% endif %}
Interfaces/IPs{{ object.sync_interfaces|yesno:"Interfaces on,Interfaces off" }} / {{ object.sync_ip_addresses|yesno:"IPs on,IPs off" }}{% trans "Interfaces/IPs" %}{% 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 %}
@@ -137,7 +138,7 @@
-
Comments
+
{% trans "Comments" %}
{{ object.comments|linebreaksbr }}
diff --git a/pyproject.toml b/pyproject.toml index fe7e673..f4477c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,4 +28,8 @@ dependencies = [ include = ["netbox_vmware_importer*"] [tool.setuptools.package-data] -netbox_vmware_importer = ["templates/**/*.html"] +netbox_vmware_importer = [ + "templates/**/*.html", + "locale/*/LC_MESSAGES/*.po", + "locale/*/LC_MESSAGES/*.mo", +] diff --git a/tests/test_compatibility.py b/tests/test_compatibility.py new file mode 100644 index 0000000..2c8912c --- /dev/null +++ b/tests/test_compatibility.py @@ -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()