diff --git a/modules/hostgroups.py b/modules/hostgroups.py index c008dbe..4c64f40 100644 --- a/modules/hostgroups.py +++ b/modules/hostgroups.py @@ -42,14 +42,11 @@ class Hostgroup(): # Add default formatting options # Check if a site is configured. A site is optional for VMs format_options["region"] = None - format_options["location"] = None format_options["site_group"] = None if self.nb.site: if self.nb.site.region: format_options["region"] = self.generate_parents("region", str(self.nb.site.region)) - if self.nb.location: - format_options["location"] = str(self.nb.location) if self.nb.site.group: format_options["site_group"] = self.generate_parents("site_group", str(self.nb.site.group)) @@ -61,11 +58,14 @@ class Hostgroup(): # Variables only applicable for devices if self.type == "dev": format_options["manufacturer"] = self.nb.device_type.manufacturer.name + format_options["location"] = str(self.nb.location) if self.nb.location else None # Variables only applicable for VM's if self.type == "vm": - format_options["cluster"] = self.nb.cluster.name - format_options["cluster_type"] = self.nb.cluster.type.name - + # Check if a cluster is configured. Could also be configured in a site. + if self.nb.cluster: + format_options["cluster"] = self.nb.cluster.name + format_options["cluster_type"] = self.nb.cluster.type.name + self.format_options = format_options def generate(self, hg_format=None): diff --git a/modules/virtualMachine.py b/modules/virtual_machine.py similarity index 76% rename from modules/virtualMachine.py rename to modules/virtual_machine.py index d1ab41b..ba58311 100644 --- a/modules/virtualMachine.py +++ b/modules/virtual_machine.py @@ -1,13 +1,13 @@ """Module that hosts all functions for virtual machine processing""" +from os import sys from modules.device import PhysicalDevice from modules.hostgroups import Hostgroup from modules.exceptions import TemplateError try: from config import ( traverse_site_groups, - traverse_regions, - template_cf + traverse_regions ) except ModuleNotFoundError: print("Configuration file config.py not found in main directory." @@ -35,7 +35,12 @@ class VirtualMachine(PhysicalDevice): except TemplateError as e: self.logger.warning(e) return True - - def set_template(self, **kwargs): - """Simple wrapper fur underlying functions""" - self.set_vm_template() \ No newline at end of file + + def set_template(self, prefer_config_context=None, overrule_custom=None): + """ + This wrapper takes the original function and + overwrites it with the set_vm_template function. + This function (set_template) is used by several + other functions such as the consistency check in the parent class. + """ + self.set_vm_template() diff --git a/netbox_zabbix_sync.py b/netbox_zabbix_sync.py index e3f023a..306f3f4 100755 --- a/netbox_zabbix_sync.py +++ b/netbox_zabbix_sync.py @@ -8,7 +8,7 @@ from os import environ, path, sys from pynetbox import api from zabbix_utils import ZabbixAPI, APIRequestError, ProcessingError from modules.device import PhysicalDevice -from modules.virtualMachine import VirtualMachine +from modules.virtual_machine import VirtualMachine from modules.tools import convert_recordset, proxy_prepper from modules.exceptions import EnvironmentVarError, HostgroupError, SyncError try: