Skip to content

[FR] VM name mapping/relation with regex #465

Open

Description

@marvinwankersteen

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.

Activity

  1. changed the title [-]VM name mapping/relation with regex[/-] [+][FR] VM name mapping/relation with regex[/+] on Jun 23, 2025
  2. marvinwankersteen commented on Jun 23, 2025

    @marvinwankersteen
    Author

    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.

  3. bb-Ricardo commented on Jun 23, 2025

    @bb-Ricardo
    Owner

    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.

    Great that you found a workaround. Currently there is no native implementation to do this.

  4. added a commit that references this issue on Oct 10, 2026
    b17d3f5
  5. semx commented on Oct 10, 2026

    @semx
    Collaborator

    Implemented in development (#590), in the image ghcr.io/bb-ricardo/netbox-sync:development. vm_name_regex is applied to the vCenter name before anything else; the named group name becomes the NetBox name and an optional group description fills the description, so your example ^(?P<name>[^ (]+)(?: \((?P<description>.*)\))?$ turns web01 (production) into web01 with the description production. Names the regex does not match are used as they are. One thing to expect on an existing NetBox: VMs whose name changes are found again by MAC, IP or serial and renamed in place, so the first run with the option is a one-off rename.

    Could you try it against your vCenter? Run with -n first, then a real run and a second one (the second should change nothing in NetBox), and say what came out, here or in the call for testing: #592. Nothing changes unless the option is set, so pulling the image is safe. It goes into 1.10.0, the next feature release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions