Skip to content

Commit

Permalink
prefixed names: replace all none alphanumeric chars
Browse files Browse the repository at this point in the history
Libvirt network name must be only alpha-numeric, while our network names
can be anything(net-01, net-02 for example). So when generating a
prefixed name of a resource, replace all none-alphanumeric chars with a
'L'. The prefixed name is always a combination of part of a random
string(uuid) and the original name in the spec, and is an internal
implementation detail, so I think this should be safe.

Signed-off-by: Nadav Goldin <[email protected]>
  • Loading branch information
nvgoldin committed Jul 1, 2017
1 parent 6efafbe commit dd048df
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 4 additions & 1 deletion docs/LagoInitFile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,15 @@ domains

nets
----
``<name>``: The name of the network.
``<name>``: 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
Expand Down
1 change: 1 addition & 0 deletions lago/providers/libvirt/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import functools
import logging
import time
import re
from copy import deepcopy

from lxml import etree as ET
Expand Down
15 changes: 10 additions & 5 deletions lago/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import logging
import os
import uuid

import re
import yaml

from lago import log_utils, plugins, utils
Expand Down Expand Up @@ -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(
Expand All @@ -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):
Expand Down

0 comments on commit dd048df

Please sign in to comment.