Revision b8fd7d84 kamaki/cli/config.py

b/kamaki/cli/config.py
35 35
from logging import getLogger
36 36

  
37 37
from collections import defaultdict
38
from ConfigParser import RawConfigParser, NoOptionError, NoSectionError
38
from ConfigParser import RawConfigParser, NoOptionError, NoSectionError, Error
39 39
from re import match
40 40

  
41 41
from kamaki.cli.errors import CLISyntaxError
......
47 47
    from kamaki.clients.utils.ordereddict import OrderedDict
48 48

  
49 49

  
50
class InvalidCloudNameError(Error):
51
    """A valid cloud name is accepted by this regex: ([@#$:-\w]+)"""
52

  
53

  
50 54
log = getLogger(__name__)
51 55

  
52 56
# Path to the file that stores the configuration
......
121 125

  
122 126
    @staticmethod
123 127
    def _cloud_name(full_section_name):
124
        matcher = match(CLOUD_PREFIX + ' "(\w+)"', full_section_name)
125
        return matcher.groups()[0] if matcher else None
128
        if not full_section_name.startswith(CLOUD_PREFIX + ' '):
129
            return None
130
        matcher = match(CLOUD_PREFIX + ' "([@#$:\-\w]+)"', full_section_name)
131
        if matcher:
132
            return matcher.groups()[0]
133
        else:
134
            icn = full_section_name[len(CLOUD_PREFIX) + 1:]
135
            raise InvalidCloudNameError('Invalid Cloud Name %s' % icn)
126 136

  
127 137
    def rescue_old_file(self):
128 138
        lost_terms = []
......
319 329
        """
320 330
        prefix = CLOUD_PREFIX + '.'
321 331
        if section.startswith(prefix):
322
            return self.set_cloud(section[len(prefix)], option, value)
332
            cloud = self._cloud_name(
333
                CLOUD_PREFIX + ' "' + section[len(prefix):] + '"')
334
            return self.set_cloud(cloud, option, value)
323 335
        if section not in RawConfigParser.sections(self):
324 336
            self.add_section(section)
325 337
        RawConfigParser.set(self, section, option, value)

Also available in: Unified diff