From 02759b5251bfc5b7bcfd7cb0090658df3998880b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Thu, 1 May 2025 11:01:05 +0200 Subject: [PATCH 1/8] Add debug logs --- netbox_pve_sync/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/netbox_pve_sync/__init__.py b/netbox_pve_sync/__init__.py index 906bc41..a3ef3ec 100644 --- a/netbox_pve_sync/__init__.py +++ b/netbox_pve_sync/__init__.py @@ -220,6 +220,10 @@ def _process_pve_virtual_machine_network_interface( _interface_vlan_id: Optional[int], _pve_virtual_machine_ip_addresses: dict, ) -> dict: + print( + f'_process_pve_virtual_machine_network_interface(_nb_api, _nb_objects, {_nb_virtual_machine.serial}, {_interface_name}, {_interface_mac_address}, {_interface_vlan_id}, {_pve_virtual_machine_ip_addresses})' + ) + nb_virtual_machines_interface = _nb_objects['virtual_machines_interfaces'] \ .get(_nb_virtual_machine.id, {}) \ .get(_interface_name) @@ -231,6 +235,10 @@ def _process_pve_virtual_machine_network_interface( description=_interface_mac_address, ) + print( + f'_nb_api.virtualization.interfaces.create(virtual_machine={_nb_virtual_machine.id}, name={_nb_virtual_machine.name}, description={_interface_mac_address}) = {nb_virtual_machines_interface} ({nb_virtual_machines_interface.id})' + ) + if _nb_virtual_machine.id not in _nb_objects['virtual_machines_interfaces']: _nb_objects['virtual_machines_interfaces'][_nb_virtual_machine.id] = {} @@ -246,6 +254,10 @@ def _process_pve_virtual_machine_network_interface( assigned_object_id=nb_virtual_machines_interface.id, ) + print( + f'_nb_api.dcim.mac_addresses.create(mac_address={_interface_mac_address}, assigned_object_type=virtualization.vminterface, assigned_object_id={nb_virtual_machines_interface.id}) = {nb_mac_address}' + ) + _nb_objects['mac_addresses'][_interface_mac_address] = nb_mac_address nb_virtual_machines_interface.primary_mac_address = nb_mac_address.id From 66cfbae8631d01369f65adeb051b59028db705bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Thu, 1 May 2025 11:01:28 +0200 Subject: [PATCH 2/8] remove workflows --- .forgejo/workflows/cd.yaml | 25 ------------------------- .forgejo/workflows/ci.yaml | 17 ----------------- 2 files changed, 42 deletions(-) delete mode 100644 .forgejo/workflows/cd.yaml delete mode 100644 .forgejo/workflows/ci.yaml diff --git a/.forgejo/workflows/cd.yaml b/.forgejo/workflows/cd.yaml deleted file mode 100644 index 3690493..0000000 --- a/.forgejo/workflows/cd.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: CD - -on: - push: - tags: - - '*' -jobs: - ci: - runs-on: docker - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-python@v5 - with: - python-version: '3.13' - cache: 'pip' - - - run: pip install -r requirements.txt - - - run: python3 -m build - - - run: twine upload dist/* - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} \ No newline at end of file diff --git a/.forgejo/workflows/ci.yaml b/.forgejo/workflows/ci.yaml deleted file mode 100644 index 6a0f581..0000000 --- a/.forgejo/workflows/ci.yaml +++ /dev/null @@ -1,17 +0,0 @@ -name: CI - -on: [ push ] -jobs: - ci: - runs-on: docker - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-python@v5 - with: - python-version: '3.13' - cache: 'pip' - - - run: pip install -r requirements.txt - - - run: pylint --max-line-length=120 netbox_pve_sync \ No newline at end of file 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 3/8] 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 4/8] 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 +``` From f70c55e0026f08cd166d10b063df69100e8b4536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Tue, 26 Aug 2025 17:30:23 +0200 Subject: [PATCH 5/8] [PATCH] Fix: Allow VM disk sizes in Megabytes Co-authored-by: eliba See: https://github.com/creekorful/netbox-pve-sync/pull/9 --- netbox_pve_sync/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/netbox_pve_sync/__init__.py b/netbox_pve_sync/__init__.py index de581bd..7117fe2 100644 --- a/netbox_pve_sync/__init__.py +++ b/netbox_pve_sync/__init__.py @@ -391,6 +391,8 @@ def _process_pve_disk_size(_raw_disk_size: str) -> int: size = _raw_disk_size[:-1] size_unit = _raw_disk_size[-1] + if size_unit == 'M': + return int(size) if size_unit == 'G': return int(size) * 1_000 if size_unit == 'T': From 490f72071f6ea74f3721a4137b1c1e472aaef9b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Tue, 26 Aug 2025 17:33:18 +0200 Subject: [PATCH 6/8] Release 0.2.3 --- Changelog.md | 6 ++++++ pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 933d873..bccdd54 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,12 @@ ## [Unreleased] +## [0.2.3] - 26/08/2025 + +### Fixed + +- Allow VM disk sizes in Megabytes. + ## [0.2.2] - 07/05/2025 ### Fixed diff --git a/pyproject.toml b/pyproject.toml index 37f5f13..c014f62 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "netbox-pve-sync" -version = "0.2.2" +version = "0.2.3" authors = [ { name = "Aloïs Micard", email = "alois@micard.lu" }, ] From 49bc0cd3bc77897118104290c8c42cf70198888c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Tue, 2 Sep 2025 23:56:34 +0200 Subject: [PATCH 7/8] [PATCH] Import vCPU core count instead of total available cores See: https://github.com/creekorful/netbox-pve-sync/pull/10 --- netbox_pve_sync/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/netbox_pve_sync/__init__.py b/netbox_pve_sync/__init__.py index 7117fe2..2a2c2bd 100644 --- a/netbox_pve_sync/__init__.py +++ b/netbox_pve_sync/__init__.py @@ -130,7 +130,7 @@ def _process_pve_virtual_machine( site=_nb_device.site.id, cluster=os.environ.get('NB_CLUSTER_ID', 1), device=_nb_device.id, - vcpus=pve_virtual_machine_config['cores'], + vcpus=_get_virtual_machine_vcpus(pve_virtual_machine_config), memory=int(pve_virtual_machine_config['memory']), status='active' if _pve_virtual_machine['status'] == 'running' else 'offline', tags=list(map(lambda _pve_tag_name: _nb_objects['tags'][_pve_tag_name].id, _pve_tags)), @@ -145,7 +145,7 @@ def _process_pve_virtual_machine( nb_virtual_machine.site = _nb_device.site.id 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.vcpus = _get_virtual_machine_vcpus(pve_virtual_machine_config) nb_virtual_machine.memory = int(pve_virtual_machine_config['memory']) nb_virtual_machine.status = 'active' if _pve_virtual_machine['status'] == 'running' else 'offline' nb_virtual_machine.tags = list(map(lambda _pve_tag_name: _nb_objects['tags'][_pve_tag_name].id, _pve_tags)) @@ -401,6 +401,13 @@ def _process_pve_disk_size(_raw_disk_size: str) -> int: return -1 +def _get_virtual_machine_vcpus(_pve_virtual_machine_config: dict) -> int: + if 'vcpus' in _pve_virtual_machine_config: + return _pve_virtual_machine_config['vcpus'] + + return _pve_virtual_machine_config['cores'] * _pve_virtual_machine_config['sockets'] + + def main(): """ netbox-pve-sync main entrypoint From 647034887510dcc86136c86080b606429559d862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Tue, 2 Sep 2025 23:57:53 +0200 Subject: [PATCH 8/8] Release 0.2.4 --- Changelog.md | 6 ++++++ pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index bccdd54..923e588 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,12 @@ ## [Unreleased] +## [0.2.4] - 02/09/2025 + +### Fixed + +- Import vCPU core count instead of total available cores. + ## [0.2.3] - 26/08/2025 ### Fixed diff --git a/pyproject.toml b/pyproject.toml index c014f62..6266659 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "netbox-pve-sync" -version = "0.2.3" +version = "0.2.4" authors = [ { name = "Aloïs Micard", email = "alois@micard.lu" }, ]