[FR] VM name mapping/relation with regex
Hi,
thanks for the tool, which has worked great so far.
We have created the VMs in a other VMware cluster according to the following scheme: <hostname> (<description>).
However, the VMs should only be created in Netbox with <hostname> as name and <description> as description.
The latter is not absolutely necessary.
Can this be implemented relatively easily, possibly with a "small" adjustment in the script? I was thinking of a similar option with regex to the existing relations that can be set in the config file.
I think I found a workaround.
The option strip_vm_domain_name = True can be used with the following change in https://github.com/bb-Ricardo/netbox-sync/blob/main/module/sources/vmware/connection.py:
@@ -10,6 +10,7 @@
import datetime
import pprint
import ssl
+import re
from ipaddress import ip_address, ip_interface
from urllib.parse import unquote
from itertools import zip_longest
@@ -2088,7 +2089,8 @@ class VMWareHandler(SourceBase):
name = get_string_or_none(grab(obj, "name"))
if name is not None and self.settings.strip_vm_domain_name is True:
- name = name.split(".")[0]
+ name = re.split(r'[ \(]', name)[0]
#
# Filtering
The dry-run looks good.
I think I found a workaround.
The option
strip_vm_domain_name = Truecan be used with the following change in https://github.com/bb-Ricardo/netbox-sync/blob/main/module/sources/vmware/connection.py:@@ -10,6 +10,7 @@ import datetime import pprint import ssl +import re from ipaddress import ip_address, ip_interface from urllib.parse import unquote from itertools import zip_longest @@ -2088,7 +2089,8 @@ class VMWareHandler(SourceBase): name = get_string_or_none(grab(obj, "name"))
if name is not None and self.settings.strip_vm_domain_name is True:
name = name.split(".")[0]
name = re.split(r'[ \(]', name)[0] # # FilteringThe dry-run looks good.
Great that you found a workaround. Currently there is no native implementation to do this.