Skip to content

Commit f615690

Browse files
Merge pull request #45 from netboxlabs/features-2025.11.01
Features 2025.11.01 Adds configurable inclusion of vms and lxc templates.
2 parents 0cafae0 + 90a2fc9 commit f615690

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

conf.d/netbox_setup_objects.yml-sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ netbox_api_config:
1313
api_token: netbox_api_secret_token
1414
verify_ssl: false # or true, up to you
1515
proxmox:
16+
create_vms_templates: True # default: False
17+
create_lxc_templates: True # default: False
1618
cluster_name: name-of-proxmox-cluster #(no longer required as it will be discovered)
1719
node_commands:
1820
dmidecode_command: /usr/sbin/dmidecode # required: where dmidecode lives on your system

setup/netbox_setup_objects_and_custom_fields.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def create_custom_field(netbox_url=None, netbox_api_token=None, name=None, label
167167
'filter_logic': 'disabled',
168168
'search_weight': 1000,
169169
'object_types': object_types,
170-
'type': input_type,
170+
'type': input_type['value'],
171171
'group_name': group_name,
172172
'name': name,
173173
'label': label,
@@ -178,7 +178,7 @@ def create_custom_field(netbox_url=None, netbox_api_token=None, name=None, label
178178
'filter_logic': 'disabled',
179179
'search_weight': 1000,
180180
'object_types': object_types,
181-
'type': input_type,
181+
'type': input_type['value'],
182182
'group_name': group_name,
183183
'name': name,
184184
'label': label,
@@ -195,6 +195,10 @@ def create_custom_field(netbox_url=None, netbox_api_token=None, name=None, label
195195
default_netbox_cluster_name = 'proxmox-ve'
196196
default_netbox_vm_role = 'Proxmox VM'
197197
default_netbox_lxc_role = 'Proxmox LXC'
198+
create_vms_templates = False
199+
create_lxc_templates = False
200+
netbox_field_choice_sets_vms_templates_id = 0
201+
netbox_field_choice_sets_lxc_templates_id = 0
198202

199203
args = get_arguments()
200204

@@ -224,6 +228,12 @@ def create_custom_field(netbox_url=None, netbox_api_token=None, name=None, label
224228
if 'cluster_name' in app_config['proxmox']:
225229
proxmox_cluster_name = app_config['proxmox']['cluster_name']
226230

231+
if 'create_vms_templates' in app_config['proxmox'] and app_config['proxmox']['create_vms_templates']:
232+
create_vms_templates = True
233+
234+
if 'create_lxc_templates' in app_config['proxmox'] and app_config['proxmox']['create_lxc_templates']:
235+
create_lxc_templates = True
236+
227237
if 'netbox' in app_config:
228238
if 'cluster_role' in app_config['netbox']:
229239
vm_cluster_role = app_config['netbox']['cluster_role']
@@ -242,11 +252,17 @@ def create_custom_field(netbox_url=None, netbox_api_token=None, name=None, label
242252
netbox_cluster_id = dict(nbc.obj)['id']
243253

244254
# custom field choice sets
245-
netbox_field_choice_sets_templates_id = create_custom_field_choice_sets_proxmox_vm_templates(p)
255+
if create_vms_templates and len(p.proxmox_vm_templates.keys()) > 0:
256+
netbox_field_choice_sets_vms_templates_id = create_custom_field_choice_sets_proxmox_vm_templates(p)
246257

247258
netbox_field_choice_sets_vm_storage_volumes_id = create_custom_field_choice_sets_proxmox_vm_storage(p)
248259

249-
netbox_field_choice_sets_lxc_templates_id = create_custom_field_choice_sets_proxmox_lxc_templates(p)
260+
if create_lxc_templates:
261+
for n in p.proxmox_nodes:
262+
p.proxmox_get_lxc_templates(n)
263+
264+
if len(p.proxmox_lxc_templates.keys()) > 0:
265+
netbox_field_choice_sets_lxc_templates_id = create_custom_field_choice_sets_proxmox_lxc_templates(p)
250266

251267
netbox_field_choice_sets_proxmox_nodes_id = create_custom_field_choice_sets_proxmox_vm_cluster_nodes(p)
252268

@@ -255,7 +271,9 @@ def create_custom_field(netbox_url=None, netbox_api_token=None, name=None, label
255271
# custom fields
256272

257273
# VM template id
258-
custom_field_template_id = create_custom_field(netbox_url, netbox_api_token, 'proxmox_vm_templates', 'Proxmox VM Templates', netbox_field_choice_sets_templates_id, str(min(p.proxmox_vm_templates.keys())))
274+
if create_vms_templates and len(p.proxmox_vm_templates.keys()) > 0:
275+
if netbox_field_choice_sets_vms_templates_id > 0:
276+
custom_field_vms_template_id = create_custom_field(netbox_url, netbox_api_token, 'proxmox_vm_templates', 'Proxmox VM Templates', netbox_field_choice_sets_vms_templates_id, str(min(p.proxmox_vm_templates.keys())))
259277

260278
# VM proxmox node id
261279
# NODES {'pxmx-n1': {'ip': '192.168.71.3', 'online': 1, 'version': 'Proxmox-8.4.1-2a5fa54a8503f96d'}, 'pxmx-n2': {'ip': '192.168.71.4', 'online': 1, 'version': 'Proxmox-8.4.1-2a5fa54a8503f96d'}}
@@ -277,9 +295,6 @@ def create_custom_field(netbox_url=None, netbox_api_token=None, name=None, label
277295
custom_field_proxmox_vm_type = create_custom_field(netbox_url, netbox_api_token, 'proxmox_vm_type', 'Proxmox VM Type', netbox_field_choice_sets_proxmox_vm_types_id, 'vm')
278296

279297
# proxmox_lxc_templates
280-
if netbox_field_choice_sets_lxc_templates_id > 0:
281-
#custom_field_proxmox_disk_storage_volume_id = create_custom_field(netbox_url, netbox_api_token, 'proxmox_lxc_templates', 'Proxmox LXC Templates', netbox_field_choice_sets_lxc_templates_id, str(min(p.proxmox_lxc_templates.keys())))
282-
if len(p.proxmox_lxc_templates.keys()):
283-
custom_field_proxmox_disk_storage_volume_id = create_custom_field(netbox_url, netbox_api_token, 'proxmox_lxc_templates', 'Proxmox LXC Templates', netbox_field_choice_sets_lxc_templates_id, str(min(p.proxmox_lxc_templates.keys())))
284-
else:
285-
custom_field_proxmox_disk_storage_volume_id = create_custom_field(netbox_url, netbox_api_token, 'proxmox_lxc_templates', 'Proxmox LXC Templates', netbox_field_choice_sets_lxc_templates_id, "")
298+
if create_lxc_templates and len(p.proxmox_lxc_templates.keys()) > 0:
299+
if netbox_field_choice_sets_lxc_templates_id > 0:
300+
custom_field_lxc_template_id = create_custom_field(netbox_url, netbox_api_token, 'proxmox_lxc_templates', 'Proxmox LXC Templates', netbox_field_choice_sets_lxc_templates_id, str(min(p.proxmox_lxc_templates.keys())))

0 commit comments

Comments
 (0)