Compare commits
3 commits
main
...
extra-debu
Author | SHA1 | Date | |
---|---|---|---|
d94e982cee | |||
66cfbae863 | |||
02759b5251 |
6 changed files with 17 additions and 70 deletions
|
@ -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 }}
|
|
|
@ -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
|
|
14
Changelog.md
14
Changelog.md
|
@ -2,20 +2,6 @@
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
## [0.2.4] - 02/09/2025
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- Import vCPU core count instead of total available cores.
|
|
||||||
|
|
||||||
## [0.2.3] - 26/08/2025
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- Allow VM disk sizes in Megabytes.
|
|
||||||
|
|
||||||
## [0.2.2] - 07/05/2025
|
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Use `NB_CLUSTER_ID` even for VM update.
|
- Use `NB_CLUSTER_ID` even for VM update.
|
||||||
|
|
|
@ -63,5 +63,5 @@ The following env variables will need to be set:
|
||||||
You can then execute the script using the following command:
|
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 nbpxsync
|
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
|
||||||
```
|
```
|
|
@ -130,7 +130,7 @@ def _process_pve_virtual_machine(
|
||||||
site=_nb_device.site.id,
|
site=_nb_device.site.id,
|
||||||
cluster=os.environ.get('NB_CLUSTER_ID', 1),
|
cluster=os.environ.get('NB_CLUSTER_ID', 1),
|
||||||
device=_nb_device.id,
|
device=_nb_device.id,
|
||||||
vcpus=_get_virtual_machine_vcpus(pve_virtual_machine_config),
|
vcpus=pve_virtual_machine_config['cores'],
|
||||||
memory=int(pve_virtual_machine_config['memory']),
|
memory=int(pve_virtual_machine_config['memory']),
|
||||||
status='active' if _pve_virtual_machine['status'] == 'running' else 'offline',
|
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)),
|
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.site = _nb_device.site.id
|
||||||
nb_virtual_machine.cluster = os.environ.get('NB_CLUSTER_ID', 1)
|
nb_virtual_machine.cluster = os.environ.get('NB_CLUSTER_ID', 1)
|
||||||
nb_virtual_machine.device = _nb_device.id
|
nb_virtual_machine.device = _nb_device.id
|
||||||
nb_virtual_machine.vcpus = _get_virtual_machine_vcpus(pve_virtual_machine_config)
|
nb_virtual_machine.vcpus = pve_virtual_machine_config['cores']
|
||||||
nb_virtual_machine.memory = int(pve_virtual_machine_config['memory'])
|
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.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))
|
||||||
|
@ -220,6 +220,10 @@ def _process_pve_virtual_machine_network_interface(
|
||||||
_interface_vlan_id: Optional[int],
|
_interface_vlan_id: Optional[int],
|
||||||
_pve_virtual_machine_ip_addresses: dict,
|
_pve_virtual_machine_ip_addresses: dict,
|
||||||
) -> 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'] \
|
nb_virtual_machines_interface = _nb_objects['virtual_machines_interfaces'] \
|
||||||
.get(_nb_virtual_machine.id, {}) \
|
.get(_nb_virtual_machine.id, {}) \
|
||||||
.get(_interface_name)
|
.get(_interface_name)
|
||||||
|
@ -231,6 +235,10 @@ def _process_pve_virtual_machine_network_interface(
|
||||||
description=_interface_mac_address,
|
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']:
|
if _nb_virtual_machine.id not in _nb_objects['virtual_machines_interfaces']:
|
||||||
_nb_objects['virtual_machines_interfaces'][_nb_virtual_machine.id] = {}
|
_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,
|
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_objects['mac_addresses'][_interface_mac_address] = nb_mac_address
|
||||||
|
|
||||||
nb_virtual_machines_interface.primary_mac_address = nb_mac_address.id
|
nb_virtual_machines_interface.primary_mac_address = nb_mac_address.id
|
||||||
|
@ -391,8 +403,6 @@ def _process_pve_disk_size(_raw_disk_size: str) -> int:
|
||||||
size = _raw_disk_size[:-1]
|
size = _raw_disk_size[:-1]
|
||||||
size_unit = _raw_disk_size[-1]
|
size_unit = _raw_disk_size[-1]
|
||||||
|
|
||||||
if size_unit == 'M':
|
|
||||||
return int(size)
|
|
||||||
if size_unit == 'G':
|
if size_unit == 'G':
|
||||||
return int(size) * 1_000
|
return int(size) * 1_000
|
||||||
if size_unit == 'T':
|
if size_unit == 'T':
|
||||||
|
@ -401,13 +411,6 @@ def _process_pve_disk_size(_raw_disk_size: str) -> int:
|
||||||
return -1
|
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():
|
def main():
|
||||||
"""
|
"""
|
||||||
netbox-pve-sync main entrypoint
|
netbox-pve-sync main entrypoint
|
||||||
|
|
|
@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "netbox-pve-sync"
|
name = "netbox-pve-sync"
|
||||||
version = "0.2.4"
|
version = "0.2.1"
|
||||||
authors = [
|
authors = [
|
||||||
{ name = "Aloïs Micard", email = "alois@micard.lu" },
|
{ name = "Aloïs Micard", email = "alois@micard.lu" },
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue