Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a domain name if not present in a vm's name #356

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions module/sources/vmware/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ def __init__(self):
bool,
description="strip domain part from VM name before syncing VM to NetBox",
default_value=False),
ConfigOption("add_vm_domain_name",
str,
description="If no domain, add this to it when syncing VM to NetBox",
config_example="example.com"),
ConfigOption("keep_vm_domain_name_filter",
str,
description="Pattern for which domain names we keep, vs adding bits or truncating",
config_example=".*example.(com|net)$"),
ConfigOptionGroup(title="tag source",
description="""\
sync tags assigned to clusters, hosts and VMs in vCenter to NetBox
Expand Down
9 changes: 8 additions & 1 deletion module/sources/vmware/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import datetime
import pprint
import ssl
import re
from ipaddress import ip_address, ip_interface
from urllib.parse import unquote

Expand Down Expand Up @@ -1984,7 +1985,13 @@ def add_virtual_machine(self, obj):

name = get_string_or_none(grab(obj, "name"))

if name is not None and self.settings.strip_vm_domain_name is True:
if name is not None and self.settings.keep_vm_domain_name_filter is not None:
vm_domain_name_pattern = re.compile(self.settings.keep_vm_domain_name_filter)
if vm_domain_name_pattern.search(name):
name = name
else:
name = name + "." + self.settings.add_vm_domain_name
elif name is not None and self.settings.strip_vm_domain_name is True:
name = name.split(".")[0]

#
Expand Down
6 changes: 6 additions & 0 deletions settings-example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@ password = super-secret
; strip domain part from VM name before syncing VM to NetBox
;strip_vm_domain_name = False

; domains we expect at end of FQDN:
;keep_vm_domain_name_pattern = .*(example\.com|example\.net)$

; add this domain if domain isn't an FQDN
;add_vm_domain_name = example.com

; tag source options

; sync tags assigned to clusters, hosts and VMs in vCenter to NetBox
Expand Down