adds new config option vm_platform_relation

refs: #47
This commit is contained in:
Ricardo Bartels
2021-02-26 18:10:54 +01:00
parent 3effdd46b2
commit c69248ea15
2 changed files with 23 additions and 4 deletions
+16 -4
View File
@@ -70,6 +70,7 @@ class VMWareHandler:
"cluster_site_relation": None,
"host_site_relation": None,
"vm_tenant_relation": None,
"vm_platform_relation": None,
"dns_name_lookup": False,
"custom_dns_servers": None,
"set_primary_ip": "when-undefined",
@@ -180,14 +181,15 @@ class VMWareHandler:
config_settings[setting] = re_compiled
for relation_option in ["cluster_site_relation", "host_site_relation", "vm_tenant_relation"]:
for relation_option in ["cluster_site_relation", "host_site_relation",
"vm_tenant_relation", "vm_platform_relation"]:
if config_settings.get(relation_option) is None:
continue
relation_data = list()
relation_type = "tenant" if "tenant" in relation_option else "site"
relation_type = relation_option.split("_")[1]
for relation in config_settings.get(relation_option).split(","):
@@ -1933,8 +1935,18 @@ class VMWareHandler:
if site_name is None:
site_name = self.get_site_name(NBCluster, cluster_name)
platform = grab(obj, "config.guestFullName")
platform = get_string_or_none(grab(obj, "guest.guestFullName", fallback=platform))
# first check against vm_platform_relation
platform = None
for platform_relation in grab(self, "vm_platform_relation", fallback=list()):
object_regex = platform_relation.get("object_regex")
if object_regex.match(name):
platform = platform_relation.get("platform_name")
log.debug2(f"Found a match ({object_regex.pattern}) for {name}, using platform '{platform}'")
break
if platform is None:
platform = grab(obj, "config.guestFullName")
platform = get_string_or_none(grab(obj, "guest.guestFullName", fallback=platform))
hardware_devices = grab(obj, "config.hardware.device", fallback=list())
+7
View File
@@ -162,6 +162,13 @@ permitted_subnets = 172.16.0.0/12, 10.0.0.0/8, 192.168.0.0/16, fd00::/8
# value: defines the NetBox tenant name
#vm_tenant_relation = grafana.* = Infrastructure
# This option defines custom platforms if the VMWare created platforms are not suitable.
# This is done with a comma separated key = value list.
# key: defines a VM name as regex
# value: defines the NetBox platform name
#vm_platform_relation = xyz.* = centos7, pfsense.* = FreeBSD 11
# Attempt to collect asset tags from vCenter hosts
#collect_hardware_asset_tag = True