~0x44/nova/config-drive

« back to all changes in this revision

Viewing changes to nova/api/openstack/common.py

  • Committer: Lvov Maxim
  • Date: 2011-07-26 05:50:05 UTC
  • mfrom: (1320 nova)
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: usrleon@gmail.com-20110726055005-7olsp0giqup3pao7
merge with trunk, resolve conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
167
167
        msg = _('href does not contain version')
168
168
        raise ValueError(msg)
169
169
    return new_href
 
170
 
 
171
 
 
172
def get_version_from_href(href):
 
173
    """Returns the api version in the href.
 
174
 
 
175
    Returns the api version in the href.
 
176
    If no version is found, 1.0 is returned
 
177
 
 
178
    Given: 'http://www.nova.com/123'
 
179
    Returns: '1.0'
 
180
 
 
181
    Given: 'http://www.nova.com/v1.1'
 
182
    Returns: '1.1'
 
183
 
 
184
    """
 
185
    try:
 
186
        #finds the first instance that matches /v#.#/
 
187
        version = re.findall(r'[/][v][0-9]+\.[0-9]+[/]', href)
 
188
        #if no version was found, try finding /v#.# at the end of the string
 
189
        if not version:
 
190
            version = re.findall(r'[/][v][0-9]+\.[0-9]+$', href)
 
191
        version = re.findall(r'[0-9]+\.[0-9]', version[0])[0]
 
192
    except IndexError:
 
193
        version = '1.0'
 
194
    return version