Removed previous patch for Nonetype hostgroups and made a proper fix by refactoring the set_hostgroup() function and removing it from virtual_machines.py

This commit is contained in:
TheNetworkGuy 2025-06-24 21:28:32 +02:00
parent 6d4f1ac0a5
commit 4a53b53789
3 changed files with 3 additions and 24 deletions

View File

@ -48,6 +48,7 @@ class PhysicalDevice:
self.zbx_template_names = []
self.zbx_templates = []
self.hostgroups = []
self.hostgroup_type = "dev"
self.tenant = nb.tenant
self.config_context = nb.config_context
self.zbxproxy = None
@ -121,7 +122,7 @@ class PhysicalDevice:
"""Set the hostgroup for this device"""
# Create new Hostgroup instance
hg = Hostgroup(
"dev",
self.hostgroup_type,
self.nb,
self.nb_api_version,
logger=self.logger,
@ -564,9 +565,6 @@ class PhysicalDevice:
final_data = []
# Check if the hostgroup is in a nested format and check each parent
for hostgroup in self.hostgroups:
# Check if hostgroup is string. If Nonetype skip hostgroup
if not isinstance(hostgroup, str):
continue
for pos in range(len(hostgroup.split("/"))):
zabbix_hg = hostgroup.rsplit("/", pos)[0]
if self.lookupZabbixHostgroup(hostgroups, zabbix_hg):

View File

@ -144,7 +144,6 @@ class Hostgroup:
)
self.logger.warning(msg)
return None
#raise HostgroupError(msg)
def list_formatoptions(self):
"""

View File

@ -16,6 +16,7 @@ class VirtualMachine(PhysicalDevice):
super().__init__(*args, **kwargs)
self.hostgroup = None
self.zbx_template_names = None
self.hostgroup_type = "vm"
def _inventory_map(self):
"""use VM inventory maps"""
@ -29,25 +30,6 @@ class VirtualMachine(PhysicalDevice):
"""use VM tag maps"""
return config["vm_tag_map"]
def set_hostgroup(self, hg_format, nb_site_groups, nb_regions):
"""Set the hostgroup for this device"""
# Create new Hostgroup instance
hg = Hostgroup(
"vm",
self.nb,
self.nb_api_version,
logger=self.logger,
nested_sitegroup_flag=config["traverse_site_groups"],
nested_region_flag=config["traverse_regions"],
nb_groups=nb_site_groups,
nb_regions=nb_regions,
)
# Generate hostgroup based on hostgroup format
if isinstance(hg_format, list):
self.hostgroups = [hg.generate(f) for f in hg_format]
else:
self.hostgroups.append(hg.generate(hg_format))
def set_vm_template(self):
"""Set Template for VMs. Overwrites default class
to skip a lookup of custom fields."""