Add Cinder client

Change-Id: Ie5b39e2f48715df8c226c8b28faba6d3b909b033
reference: https://review.openstack.org/#/c/474038/
blueprint:implement-flex-volume-driver
This commit is contained in:
zengchen 2017-06-23 16:34:22 +08:00
parent 720ab1c1dd
commit abc4a65b5f
4 changed files with 58 additions and 0 deletions

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from kuryr.lib import config as kuryr_config
import os
from oslo_config import cfg
from oslo_log import log as logging
@ -37,9 +39,25 @@ flexvolume_driver_opts = [
]
cinder_group = cfg.OptGroup(
'cinder',
title='Cinder Options',
help=_('Configuration options for OpenStack Cinder'))
cinder_opts = [
cfg.StrOpt('region_name',
default=os.environ.get('REGION'),
help=_('Region name of this node. This is used when picking'
' the URL in the service catalog.')),
]
CONF = cfg.CONF
logging.register_options(CONF)
CONF.register_opts(flexvolume_driver_opts, flexvolume_driver_group.name)
CONF.register_opts(cinder_opts, group=cinder_group.name)
kuryr_config.register_keystoneauth_opts(CONF, cinder_group.name)
def init(args, **kwargs):

View File

@ -0,0 +1,33 @@
# 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.
from cinderclient import client as cinder_client
from kuryr.lib import utils as kuryr_utils
from fuxi_kubernetes.common import config as local_config
def _get_keystone_session(conf_group, **kwargs):
auth_plugin = kuryr_utils.get_auth_plugin(conf_group)
session = kuryr_utils.get_keystone_session(conf_group, auth_plugin)
return session, auth_plugin
def get_cinder_client(*args, **kwargs):
session, auth_plugin = _get_keystone_session(
local_config.cinder_group.name)
return cinder_client.Client(
session=session, auth=auth_plugin,
region_name=local_config.CONF[
local_config.cinder_group.name].region_name,
version=2)

View File

@ -15,12 +15,14 @@ __all__ = [
]
import itertools
from kuryr.lib import opts as kuryr_opts
from oslo_log import _options
from fuxi_kubernetes.common import config
def list_fuxi_k8s_opts():
auth_opts = kuryr_opts.get_keystoneauth_conf_options()
return [
('DEFAULT',
@ -28,4 +30,7 @@ def list_fuxi_k8s_opts():
(config.flexvolume_driver_group.name,
itertools.chain(config.flexvolume_driver_opts,)),
(config.cinder_group.name,
itertools.chain(config.cinder_opts, auth_opts,)),
]

View File

@ -4,5 +4,7 @@
pbr!=2.1.0,>=2.0.0 # Apache-2.0
oslo.serialization>=1.10.0 # Apache-2.0
python-cinderclient>=3.1.0 # Apache-2.0
stevedore>=1.20.0 # Apache-2.0
Flask!=0.11,<1.0,>=0.10 # BSD
kuryr-lib>=0.5.0 # Apache-2.0