Add "version-list" for listing REST API versions
Nova provides REST API versions. This patch adds a subcommand "version-list" for outputting the versions. Change-Id: I1b40ad57912aa740c0b1d9221018aba9b13a5436
This commit is contained in:
parent
deef71af93
commit
67585ab36e
@ -26,6 +26,7 @@ import glob
|
||||
import hashlib
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
|
||||
import requests
|
||||
@ -446,6 +447,15 @@ class HTTPClient(object):
|
||||
def _cs_request(self, url, method, **kwargs):
|
||||
if not self.management_url:
|
||||
self.authenticate()
|
||||
if url is None:
|
||||
# To get API version information, it is necessary to GET
|
||||
# a nova endpoint directly without "v2/<tenant-id>".
|
||||
magic_tuple = parse.urlsplit(self.management_url)
|
||||
scheme, netloc, path, query, frag = magic_tuple
|
||||
path = re.sub(r'v[1-9]/[a-z0-9]+$', '', path)
|
||||
url = parse.urlunsplit((scheme, netloc, path, None, None))
|
||||
else:
|
||||
url = self.management_url + url
|
||||
|
||||
# Perform the request once. If we get a 401 back then it
|
||||
# might be because the auth token expired, so try to
|
||||
@ -455,8 +465,7 @@ class HTTPClient(object):
|
||||
if self.projectid:
|
||||
kwargs['headers']['X-Auth-Project-Id'] = self.projectid
|
||||
|
||||
resp, body = self._time_request(self.management_url + url, method,
|
||||
**kwargs)
|
||||
resp, body = self._time_request(url, method, **kwargs)
|
||||
return resp, body
|
||||
except exceptions.Unauthorized as e:
|
||||
try:
|
||||
@ -467,8 +476,7 @@ class HTTPClient(object):
|
||||
self.keyring_saved = False
|
||||
self.authenticate()
|
||||
kwargs['headers']['X-Auth-Token'] = self.auth_token
|
||||
resp, body = self._time_request(self.management_url + url,
|
||||
method, **kwargs)
|
||||
resp, body = self._time_request(url, method, **kwargs)
|
||||
return resp, body
|
||||
except exceptions.Unauthorized:
|
||||
raise e
|
||||
|
@ -109,6 +109,37 @@ class ClientTest(utils.TestCase):
|
||||
verify=mock.ANY)]
|
||||
self.assertEqual(mock_request.call_args_list, expected)
|
||||
|
||||
@mock.patch.object(novaclient.client.HTTPClient, 'request',
|
||||
return_value=(200, "{'versions':[]}"))
|
||||
def _check_version_url(self, management_url, version_url, mock_request):
|
||||
projectid = '25e469aa1848471b875e68cde6531bc5'
|
||||
instance = novaclient.client.HTTPClient(user='user',
|
||||
password='password',
|
||||
projectid=projectid,
|
||||
auth_url="http://www.blah.com")
|
||||
instance.auth_token = 'foobar'
|
||||
instance.management_url = management_url % projectid
|
||||
instance.version = 'v2.0'
|
||||
|
||||
# If passing None as the part of url, a client accesses the url which
|
||||
# doesn't include "v2/<projectid>" for getting API version info.
|
||||
instance.get(None)
|
||||
mock_request.assert_called_once_with(version_url, 'GET',
|
||||
headers=mock.ANY)
|
||||
mock_request.reset_mock()
|
||||
|
||||
# Otherwise, a client accesses the url which includes "v2/<projectid>".
|
||||
instance.get('servers')
|
||||
url = instance.management_url + 'servers'
|
||||
mock_request.assert_called_once_with(url, 'GET', headers=mock.ANY)
|
||||
|
||||
def test_client_version_url(self):
|
||||
self._check_version_url('http://foo.com/v2/%s', 'http://foo.com/')
|
||||
|
||||
def test_client_version_url_with_project_name(self):
|
||||
self._check_version_url('http://foo.com/nova/v2/%s',
|
||||
'http://foo.com/nova/')
|
||||
|
||||
def test_get_client_class_v3(self):
|
||||
output = novaclient.client.get_client_class('3')
|
||||
self.assertEqual(output, novaclient.v3.client.Client)
|
||||
|
@ -41,6 +41,7 @@ from novaclient.v1_1 import server_groups
|
||||
from novaclient.v1_1 import servers
|
||||
from novaclient.v1_1 import services
|
||||
from novaclient.v1_1 import usage
|
||||
from novaclient.v1_1 import versions
|
||||
from novaclient.v1_1 import virtual_interfaces
|
||||
from novaclient.v1_1 import volume_snapshots
|
||||
from novaclient.v1_1 import volume_types
|
||||
@ -107,6 +108,7 @@ class Client(object):
|
||||
self.images = images.ImageManager(self)
|
||||
self.limits = limits.LimitsManager(self)
|
||||
self.servers = servers.ServerManager(self)
|
||||
self.versions = versions.VersionManager(self)
|
||||
|
||||
# extensions
|
||||
self.agents = agents.AgentsManager(self)
|
||||
|
@ -3654,3 +3654,10 @@ def do_server_group_get(cs, args):
|
||||
"""Get a specific server group."""
|
||||
server_group = cs.server_groups.get(args.id)
|
||||
_print_server_group_details([server_group])
|
||||
|
||||
|
||||
def do_version_list(cs, args):
|
||||
"""List all API versions."""
|
||||
result = cs.versions.list()
|
||||
columns = ["Id", "Status", "Updated"]
|
||||
utils.print_list(result, columns)
|
||||
|
35
novaclient/v1_1/versions.py
Normal file
35
novaclient/v1_1/versions.py
Normal file
@ -0,0 +1,35 @@
|
||||
# Copyright 2014 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
version interface
|
||||
"""
|
||||
|
||||
from novaclient import base
|
||||
|
||||
|
||||
class Version(base.Resource):
|
||||
"""
|
||||
Compute REST API information
|
||||
"""
|
||||
def __repr__(self):
|
||||
return "<Version>"
|
||||
|
||||
|
||||
class VersionManager(base.ManagerWithFind):
|
||||
resource_class = Version
|
||||
|
||||
def list(self):
|
||||
"""List all versions."""
|
||||
return self._list(None, "versions")
|
Loading…
x
Reference in New Issue
Block a user