Compare commits

..

No commits in common. "eb663ee3c67324a57490306344cc3c3491cf0158" and "20cdbfc49979f2f7c02a8a3ef0ae1769fd3a7058" have entirely different histories.

4 changed files with 8 additions and 35 deletions

View file

@ -2,12 +2,6 @@
## [Unreleased] ## [Unreleased]
## [0.2.0] - 21/04/2025
### New
- Monitoring PVE HA/Replication.
## [0.1.1] - 19/02/2025 ## [0.1.1] - 19/02/2025
### New ### New

View file

@ -34,19 +34,17 @@ You'll also need to perform a minimal configuration on NetBox:
- Create the cluster. - Create the cluster.
- Add the following Custom Fields: - Add the following Custom Fields:
| Name | Object types | Label | Type | | Name | Object types | Label | Type |
|------------|-----------------|------------|---------| |-----------|-----------------|-----------|---------|
| autostart | Virtual Machine | Autostart | Boolean | | autostart | Virtual Machine | Autostart | Boolean |
| replicated | Virtual Machine | Replicated | Boolean | | backup | Virtual Disk | Backup | Boolean |
| ha | Virtual Machine | Failover | Boolean | | dns_name | Prefix | DNS Name | Text |
| backup | Virtual Disk | Backup | Boolean |
| dns_name | Prefix | DNS Name | Text |
### On the PVE API ### On the PVE API
You'll need to create a dedicated user (ex: netsync) on your PVE cluster and then create an API token. You'll need to create a dedicated user (ex: netsync) on your PVE cluster and then create an API token.
The user needs to have access to the VM.Monitor, Pool.Audit, VM.Audit, Sys.Audit permissions. The user needs to have access to the VM.Monitor, Pool.Audit, VM.Audit permissions.
The following env variables will need to be set: The following env variables will need to be set:

View file

@ -98,9 +98,7 @@ def _process_pve_virtual_machine(
_nb_objects: dict, _nb_objects: dict,
_nb_device: any, _nb_device: any,
_pve_tags: [str], _pve_tags: [str],
_pve_virtual_machine: dict, _pve_virtual_machine: dict
_is_replicated: bool,
_has_ha: bool,
) -> dict: ) -> dict:
_pve_node_name = _nb_device.name.lower() _pve_node_name = _nb_device.name.lower()
@ -135,8 +133,6 @@ def _process_pve_virtual_machine(
tags=list(map(lambda _pve_tag_name: _nb_objects['tags'][_pve_tag_name].id, _pve_tags)), tags=list(map(lambda _pve_tag_name: _nb_objects['tags'][_pve_tag_name].id, _pve_tags)),
custom_fields={ custom_fields={
'autostart': pve_virtual_machine_config.get('onboot') == 1, 'autostart': pve_virtual_machine_config.get('onboot') == 1,
'replicated': _is_replicated,
'ha': _has_ha,
} }
) )
else: else:
@ -149,8 +145,6 @@ def _process_pve_virtual_machine(
nb_virtual_machine.status = 'active' if _pve_virtual_machine['status'] == 'running' else 'offline' 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)) nb_virtual_machine.tags = list(map(lambda _pve_tag_name: _nb_objects['tags'][_pve_tag_name].id, _pve_tags))
nb_virtual_machine.custom_fields['autostart'] = pve_virtual_machine_config.get('onboot') == 1 nb_virtual_machine.custom_fields['autostart'] = pve_virtual_machine_config.get('onboot') == 1
nb_virtual_machine.custom_fields['replicated'] = _is_replicated
nb_virtual_machine.custom_fields['ha'] = _has_ha
nb_virtual_machine.save() nb_virtual_machine.save()
# Handle the VM network interfaces # Handle the VM network interfaces
@ -438,19 +432,8 @@ def main():
if 'tags' in pve_vm_resource: if 'tags' in pve_vm_resource:
pass # TODO: pve_vm_tags[pve_vm_resource['vmid']].append(pve_vm_resource['tags']) pass # TODO: pve_vm_tags[pve_vm_resource['vmid']].append(pve_vm_resource['tags'])
pve_ha_virtual_machine_ids = list(
map(
lambda r: int(r['sid'].split(':')[1]),
filter(lambda r: r['type'] == 'service', pve_api.cluster.ha.status.current.get())
)
)
# Process Proxmox nodes # Process Proxmox nodes
for pve_node in pve_api.nodes.get(): for pve_node in pve_api.nodes.get():
pve_replicated_virtual_machine_ids = list(
map(lambda r: r['guest'], pve_api.nodes(pve_node['node']).replication.get())
)
# This script does not create the hardware devices. # This script does not create the hardware devices.
nb_device = nb_objects['devices'].get(pve_node['node'].lower()) nb_device = nb_objects['devices'].get(pve_node['node'].lower())
if nb_device is None: if nb_device is None:
@ -469,8 +452,6 @@ def main():
nb_device, nb_device,
pve_vm_tags.get(pve_virtual_machine['vmid'], []), pve_vm_tags.get(pve_virtual_machine['vmid'], []),
pve_virtual_machine, pve_virtual_machine,
pve_virtual_machine['vmid'] in pve_replicated_virtual_machine_ids,
pve_virtual_machine['vmid'] in pve_ha_virtual_machine_ids,
) )

View file

@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "netbox-pve-sync" name = "netbox-pve-sync"
version = "0.2.0" version = "0.1.1"
authors = [ authors = [
{ name = "Aloïs Micard", email = "alois@micard.lu" }, { name = "Aloïs Micard", email = "alois@micard.lu" },
] ]