server: sanitize VM names in _get_vm_dns_entries
...using the same method as 15-hostname in OpenNebula/addon-context-linuxmaster
parent
9b47eb8f08
commit
9ca71db458
|
@ -1,3 +1,5 @@
|
|||
import re
|
||||
|
||||
from onedns import zone
|
||||
from onedns import resolver
|
||||
from onedns import exception
|
||||
|
@ -5,6 +7,9 @@ from onedns.clients import one
|
|||
from onedns.logger import log
|
||||
|
||||
|
||||
_BAD_CHARS = re.compile('[^-a-zA-Z0-9]')
|
||||
|
||||
|
||||
class OneDNS(resolver.DynamicResolver):
|
||||
"""
|
||||
This class provides convenience methods for adding/removing VMs to the
|
||||
|
@ -19,15 +24,21 @@ class OneDNS(resolver.DynamicResolver):
|
|||
if not hasattr(vm.template, 'nics'):
|
||||
raise exception.NoNetworksError(vm)
|
||||
|
||||
def _sanitize_name(self, name):
|
||||
name = _BAD_CHARS.sub('-', name)
|
||||
return name.strip('-')
|
||||
|
||||
def _get_vm_dns_entries(self, vm):
|
||||
self._check_for_networks(vm)
|
||||
entries = {}
|
||||
hostname = vm.name
|
||||
hostname = self._sanitize_name(vm.name)
|
||||
primary_ip = vm.template.nics[0].ip
|
||||
entries[hostname] = primary_ip
|
||||
for nic in vm.template.nics[1:]:
|
||||
nicname = "{hostname}-{id}".format(hostname=hostname,
|
||||
id=nic.nic_id)
|
||||
nicname = self._sanitize_name("{hostname}-{id}".format(
|
||||
id=nic.nic_id,
|
||||
hostname=hostname
|
||||
))
|
||||
entries[nicname] = nic.ip
|
||||
return entries
|
||||
|
||||
|
|
Loading…
Reference in New Issue