Support Cinder V3 API in Karbor

The 3.0 Cinder API includes all v2 core APIs existing prior to
the introduction of microversions. The /v3 URL is used to call
3.0 APIs.
The 3.0 Cinder API can be supported by Karbor.

Change-Id: Idd3fef0f3b185a0592a4f42de1f67c6571ad99ad
This commit is contained in:
chenying 2016-11-06 23:58:16 +08:00
parent f2a16590e4
commit d4b52e2615
5 changed files with 22 additions and 21 deletions

View File

@ -80,7 +80,8 @@ class RequestContext(context.RequestContext):
self.service_catalog = [s for s in service_catalog
if s.get('type') in
('identity', 'compute', 'object-store',
'image', 'volume', 'volumev2', 'network')]
'image', 'volume', 'volumev2', 'network',
'volumev3')]
else:
# if list is empty or none
self.service_catalog = []

View File

@ -23,7 +23,7 @@ cinder_client_opts = [
cfg.StrOpt(SERVICE + '_endpoint',
help='URL of the cinder endpoint.'),
cfg.StrOpt(SERVICE + '_catalog_info',
default='volumev2:cinderv2:publicURL',
default='volumev3:cinderv3:publicURL',
help='Info to match when looking for cinder in the service '
'catalog. Format is: separated values of the form: '
'<service_type>:<service_name>:<endpoint_type> - '
@ -40,7 +40,7 @@ cinder_client_opts = [
cfg.CONF.register_opts(cinder_client_opts, group=SERVICE + '_client')
CINDERCLIENT_VERSION = '2'
CINDERCLIENT_VERSION = '3'
def create(context, conf):

View File

@ -66,10 +66,10 @@ def _get_karbor_client_from_creds():
def _get_cinder_client_from_creds():
api_version = ""
cloud_config = _get_cloud_config()
keystone_session = cloud_config.get_session_client("volumev2")
keystone_session = cloud_config.get_session_client("volumev3")
keystone_auth = cloud_config.get_auth()
region_name = cloud_config.get_region_name()
service_type = "volumev2"
service_type = "volumev3"
endpoint_type = "publicURL"
endpoint = keystone_auth.get_endpoint(
keystone_session,

View File

@ -21,9 +21,9 @@ class CinderClientTest(base.TestCase):
def setUp(self):
super(CinderClientTest, self).setUp()
service_catalog = [
{'type': 'volumev2',
'name': 'cinderv2',
'endpoints': [{'publicURL': 'http://127.0.0.1:8776/v2/abcd'}],
{'type': 'volumev3',
'name': 'cinderv3',
'endpoints': [{'publicURL': 'http://127.0.0.1:8776/v3/abcd'}],
},
]
self._context = RequestContext(user_id='admin',
@ -33,15 +33,15 @@ class CinderClientTest(base.TestCase):
def test_create_client_by_endpoint(self):
cfg.CONF.set_default('cinder_endpoint',
'http://127.0.0.1:8776/v2',
'http://127.0.0.1:8776/v3',
'cinder_client')
client = cinder.create(self._context, cfg.CONF)
self.assertEqual('volumev2', client.client.service_type)
self.assertEqual('http://127.0.0.1:8776/v2/abcd',
self.assertEqual('volumev3', client.client.service_type)
self.assertEqual('http://127.0.0.1:8776/v3/abcd',
client.client.management_url)
def test_create_client_by_catalog(self):
client = cinder.create(self._context, cfg.CONF)
self.assertEqual('volumev2', client.client.service_type)
self.assertEqual('http://127.0.0.1:8776/v2/abcd',
self.assertEqual('volumev3', client.client.service_type)
self.assertEqual('http://127.0.0.1:8776/v3/abcd',
client.client.management_url)

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from cinderclient.v2 import volumes
from cinderclient.v3 import volumes
from collections import namedtuple
import mock
@ -31,8 +31,8 @@ class VolumeProtectablePluginTest(base.TestCase):
def setUp(self):
super(VolumeProtectablePluginTest, self).setUp()
service_catalog = [
{'type': 'volumev2',
'endpoints': [{'publicURL': 'http://127.0.0.1:8776/v2/abcd'}],
{'type': 'volumev3',
'endpoints': [{'publicURL': 'http://127.0.0.1:8776/v3/abcd'}],
},
]
self._context = RequestContext(user_id='admin',
@ -42,19 +42,19 @@ class VolumeProtectablePluginTest(base.TestCase):
def test_create_client_by_endpoint(self):
cfg.CONF.set_default('cinder_endpoint',
'http://127.0.0.1:8776/v2',
'http://127.0.0.1:8776/v3',
'cinder_client')
plugin = VolumeProtectablePlugin(self._context)
self.assertEqual('volumev2',
self.assertEqual('volumev3',
plugin._client(self._context).client.service_type)
self.assertEqual('http://127.0.0.1:8776/v2/abcd',
self.assertEqual('http://127.0.0.1:8776/v3/abcd',
plugin._client(self._context).client.management_url)
def test_create_client_by_catalog(self):
plugin = VolumeProtectablePlugin(self._context)
self.assertEqual('volumev2',
self.assertEqual('volumev3',
plugin._client(self._context).client.service_type)
self.assertEqual('http://127.0.0.1:8776/v2/abcd',
self.assertEqual('http://127.0.0.1:8776/v3/abcd',
plugin._client(self._context).client.management_url)
def test_get_resource_type(self):