From c892d596f49cb1f89e3529f98726ee7be91d1902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Thu, 1 May 2025 08:49:38 +0200 Subject: [PATCH 1/6] [#7] Improve tag handling Closes: #7 --- Changelog.md | 4 ++++ netbox_pve_sync/__init__.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index c0ce759..57c612a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Fixed + +- [#7] Improve tag handling. + ## [0.2.0] - 21/04/2025 ### New diff --git a/netbox_pve_sync/__init__.py b/netbox_pve_sync/__init__.py index 882b503..906bc41 100644 --- a/netbox_pve_sync/__init__.py +++ b/netbox_pve_sync/__init__.py @@ -88,6 +88,7 @@ def _process_pve_tags( slug=f'pool-{_pve_pool["poolid"]}'.lower(), description=f'Proxmox pool {_pve_pool["poolid"]}', ) + _nb_objects['tags'][_nb_tag.name] = _nb_tag return _nb_objects @@ -433,7 +434,8 @@ def main(): for pve_vm_resource in pve_api.cluster.resources.get(type='vm'): pve_vm_tags[pve_vm_resource['vmid']] = [] - pve_vm_tags[pve_vm_resource['vmid']].append(f'Pool/{pve_vm_resource["pool"]}') + if 'pool' in pve_vm_resource: + pve_vm_tags[pve_vm_resource['vmid']].append(f'Pool/{pve_vm_resource["pool"]}') if 'tags' in pve_vm_resource: pass # TODO: pve_vm_tags[pve_vm_resource['vmid']].append(pve_vm_resource['tags']) From e7d5f5dd26343c0b18b6444d89e4abafd569c310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Thu, 1 May 2025 08:50:40 +0200 Subject: [PATCH 2/6] Release 0.2.1 --- Changelog.md | 2 ++ pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 57c612a..2ab3653 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,8 @@ ## [Unreleased] +## [0.2.1] - 01/05/2025 + ### Fixed - [#7] Improve tag handling. diff --git a/pyproject.toml b/pyproject.toml index 72095db..151b8f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "netbox-pve-sync" -version = "0.2.0" +version = "0.2.1" authors = [ { name = "Aloïs Micard", email = "alois@micard.lu" }, ] From e0c732043cdbfc8b380d9abce13a2fcb7471e05e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Thu, 1 May 2025 09:16:44 +0200 Subject: [PATCH 3/6] Documentation updated to mention NB_CLUSTER_ID --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 666a6ef..900fa1f 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,9 @@ The following env variables will need to be set: - **NB_API_URL**: The URL to your NetBox instance. (ex: https://netbox.example.org) - **NB_API_TOKEN**: The token created previously. (ex: f74cb99cf552b7005fd1a616b53efba2ce0c9656) +You can also set the `NB_CLUSTER_ID` env variable in order to indicate the ID of the cluster that will be used in +NetBox. + You'll also need to perform a minimal configuration on NetBox: - Create the physical nodes hosting the cluster. (The name should match the one on Proxmox, so that the script can From c0d2c62bbbf15d352ebae3397843aa245c163d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Fri, 2 May 2025 08:20:54 +0200 Subject: [PATCH 4/6] Use `NB_CLUSTER_ID` even for VM update --- Changelog.md | 4 ++++ netbox_pve_sync/__init__.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 2ab3653..6b88a73 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Fixed + +- Use `NB_CLUSTER_ID` even for VM update. + ## [0.2.1] - 01/05/2025 ### Fixed diff --git a/netbox_pve_sync/__init__.py b/netbox_pve_sync/__init__.py index 906bc41..de581bd 100644 --- a/netbox_pve_sync/__init__.py +++ b/netbox_pve_sync/__init__.py @@ -143,7 +143,7 @@ def _process_pve_virtual_machine( else: nb_virtual_machine.name = _pve_virtual_machine['name'] nb_virtual_machine.site = _nb_device.site.id - nb_virtual_machine.cluster = 1 + nb_virtual_machine.cluster = os.environ.get('NB_CLUSTER_ID', 1) nb_virtual_machine.device = _nb_device.id nb_virtual_machine.vcpus = pve_virtual_machine_config['cores'] nb_virtual_machine.memory = int(pve_virtual_machine_config['memory']) From e0a94e68d9f2786ca4ef8506e57c4c0704717923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Wed, 7 May 2025 09:10:07 +0200 Subject: [PATCH 5/6] Release 0.2.2 --- Changelog.md | 2 ++ pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 6b88a73..933d873 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,8 @@ ## [Unreleased] +## [0.2.2] - 07/05/2025 + ### Fixed - Use `NB_CLUSTER_ID` even for VM update. diff --git a/pyproject.toml b/pyproject.toml index 151b8f5..37f5f13 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "netbox-pve-sync" -version = "0.2.1" +version = "0.2.2" authors = [ { name = "Aloïs Micard", email = "alois@micard.lu" }, ] From 1a0107381bec25345674486a29438f34d5ac3a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Tue, 3 Jun 2025 16:36:12 +0200 Subject: [PATCH 6/6] Update run instructions --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 900fa1f..2911245 100644 --- a/README.md +++ b/README.md @@ -63,5 +63,5 @@ The following env variables will need to be set: You can then execute the script using the following command: ``` -PVE_API_HOST=xx PVE_API_USER=xx PVE_API_TOKEN=xx PVE_API_SECRET=xx NB_API_URL=xx NB_API_TOKEN=xx python3 -m netbox_pve_sync -``` \ No newline at end of file +PVE_API_HOST=xx PVE_API_USER=xx PVE_API_TOKEN=xx PVE_API_SECRET=xx NB_API_URL=xx NB_API_TOKEN=xx nbpxsync +```