diff --git a/docs/LagoInitFile.rst b/docs/LagoInitFile.rst index 6ee9c2ed..af3c49e1 100644 --- a/docs/LagoInitFile.rst +++ b/docs/LagoInitFile.rst @@ -164,12 +164,15 @@ domains nets ---- -````: The name of the network. +````: The name of the network, should be an alphanumeric string. + Currently we do not enforce that it is only alphanumeric, + but we might do so in the future. type(string) Type of the network. May be `nat` or `bridge`. + .. _Templates: Templates.html .. _`virt-customize`: http://libguestfs.org/virt-customize.1.html .. _lago-ost-plugin: https://github.com/lago-project/lago-ost-plugin/blob/master/setup.cfg diff --git a/lago/virt.py b/lago/virt.py index 20a6029b..dc3e4ded 100644 --- a/lago/virt.py +++ b/lago/virt.py @@ -23,7 +23,7 @@ import logging import os import uuid - +import re import yaml from lago import log_utils, plugins, utils @@ -126,10 +126,15 @@ def prefixed_name(self, unprefixed_name, max_length=0): will adapt the given name and the length of the uuid ot fit it Returns: - str: prefixed identifier for the given unprefixed name + str: prefixed identifier for the given unprefixed name, with all + none alphanumeric characters in the unprefixed name replaced + with a 'L' """ + + not_alphanumeric = re.compile(r'[^a-zA-Z0-9]') + unprefixed_name = not_alphanumeric.sub('L', unprefixed_name) if max_length == 0: - prefixed_name = '%s-%s' % (self.uuid[:8], unprefixed_name) + prefixed_name = '%s%s' % (self.uuid[:8], unprefixed_name) else: if max_length < 6: raise RuntimeError( @@ -147,8 +152,8 @@ def prefixed_name(self, unprefixed_name, max_length=0): hashed_name = hashlib.sha1(unprefixed_name).hexdigest() unprefixed_name = hashed_name[:name_max_length] - prefixed_name = '%s-%s' % (_uuid, unprefixed_name) - + prefixed_name = '%s%s' % (_uuid, unprefixed_name) + LOGGER.debug('prefixed_name %s', prefixed_name) return prefixed_name def virt_path(self, *args):