File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -108,6 +108,15 @@ def __init__(self):
108108 str , description = "simply include/exclude VMs" ),
109109 ConfigOption ("vm_include_filter" , str )
110110 ]),
111+ ConfigOption ("vm_exclude_by_tag_filter" ,
112+ str ,
113+ description = """defines a comma separated list of vCenter tags which (if assigned to a VM)
114+ will exclude this VM from being synced to NetBox. The config option 'vm_tag_source'
115+ determines which tags are collected for VMs.
116+ """ ,
117+ config_example = "tag-a, tag-b"
118+ ),
119+
111120 ConfigOptionGroup (title = "relations" ,
112121 options = [
113122 ConfigOption ("cluster_site_relation" ,
@@ -439,7 +448,7 @@ def validate_options(self):
439448 if option .value is None :
440449 continue
441450
442- if "filter" in option .key :
451+ if "filter" in option .key and "vm_exclude_by_tag_filter" not in option . key :
443452
444453 re_compiled = None
445454 try :
@@ -452,6 +461,12 @@ def validate_options(self):
452461
453462 continue
454463
464+ if option .key == "vm_exclude_by_tag_filter" :
465+
466+ option .set_value (quoted_split (option .value ))
467+
468+ continue
469+
455470 if "relation" in option .key and "vlan_group_relation" not in option .key :
456471
457472 relation_data = list ()
Original file line number Diff line number Diff line change @@ -2187,7 +2187,16 @@ def add_virtual_machine(self, obj):
21872187 vm_tags = self .get_object_relation (name , "vm_tag_relation" )
21882188
21892189 # get vCenter tags
2190- vm_tags .extend (self .collect_object_tags (obj ))
2190+ vcenter_tags = self .collect_object_tags (obj )
2191+
2192+ # check if VM tag excludes VM from being synced to NetBox
2193+ for sync_exclude_tag in self .settings .vm_exclude_by_tag_filter or list ():
2194+ if sync_exclude_tag in vcenter_tags :
2195+ log .debug (f"Virtual machine vCenter tag '{ sync_exclude_tag } ' in matches 'vm_exclude_by_tag_filter'. "
2196+ f"Skipping" )
2197+ return
2198+
2199+ vm_tags .extend (vcenter_tags )
21912200
21922201 # vm memory depending on setting
21932202 vm_memory = grab (obj , "config.hardware.memoryMB" , fallback = 0 )
Original file line number Diff line number Diff line change @@ -172,6 +172,11 @@ password = super-secret
172172; vm_exclude_filter =
173173; vm_include_filter =
174174
175+ ; defines a comma separated list of vCenter tags which (if assigned to a VM) will exclude
176+ ; this VM from being synced to NetBox. The config option 'vm_tag_source' determines which
177+ ; tags are collected for VMs.
178+ ; vm_exclude_by_tag_filter = tag-a, tag-b
179+
175180; relations options
176181
177182; This option defines which vCenter cluster is part of a NetBox site.
You can’t perform that action at this time.
0 commit comments