Revision 29be4062 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
......
128 132

  
129 133
    @staticmethod
130 134
    def _cloud_name(full_section_name):
131
        matcher = match(CLOUD_PREFIX + ' "(\w+)"', full_section_name)
132
        return matcher.groups()[0] if matcher else None
135
        if not full_section_name.startswith(CLOUD_PREFIX + ' '):
136
            return None
137
        matcher = match(CLOUD_PREFIX + ' "([@#$:\-\w]+)"', full_section_name)
138
        if matcher:
139
            return matcher.groups()[0]
140
        else:
141
            icn = full_section_name[len(CLOUD_PREFIX) + 1:]
142
            raise InvalidCloudNameError('Invalid Cloud Name %s' % icn)
133 143

  
134 144
    def rescue_old_file(self):
135 145
        lost_terms = []
......
326 336
        """
327 337
        prefix = CLOUD_PREFIX + '.'
328 338
        if section.startswith(prefix):
329
            return self.set_cloud(section[len(prefix)], option, value)
339
            cloud = self._cloud_name(
340
                CLOUD_PREFIX + ' "' + section[len(prefix):] + '"')
341
            return self.set_cloud(cloud, option, value)
330 342
        if section not in RawConfigParser.sections(self):
331 343
            self.add_section(section)
332 344
        RawConfigParser.set(self, section, option, value)

Also available in: Unified diff