Openstack plugin for Kingbird client

Added openstack plugin for Kingbird client that supports execution
of Kingbird commands with openstack client.

Change-Id: Ia164b4f5c9dbe388fe3d1cada38c3bc0af32c1e6
This commit is contained in:
Jyothi Saroja 2017-09-04 15:57:28 +05:30
parent 5a1dfd23f8
commit bf641ae368
3 changed files with 93 additions and 23 deletions

View File

@ -40,14 +40,20 @@ or
Running Kingbird client
-----------------------
If Kingbird authentication is enabled, provide the information about OpenStack
auth to environment variables. Type:
$ export OS_PROJECT_DOMAIN_ID=default
$ export OS_REGION_NAME=RegionOne
$ export OS_USER_DOMAIN_ID=default
$ export OS_PROJECT_NAME=<project_name>
$ export OS_IDENTITY_API_VERSION=<identity_version>
$ export OS_PASSWORD=<password>
$ export OS_AUTH_URL=http://<Keystone_host>:5000/<v3(or)v2.0>
$ export OS_AUTH_TYPE=password
$ export OS_AUTH_URL=http://<Keystone_host>/identity
$ export OS_USERNAME=<user_name>
$ export OS_TENANT_NAME=<tenant_name>
$ export OS_VOLUME_API_VERSION=<volume_version>
To make sure Kingbird client works, type:

View File

@ -38,12 +38,12 @@ class Client(object):
endpoint_type='publicURL', service_type='synchronization',
auth_token=None, user_id=None, cacert=None, insecure=False,
profile=None, auth_type='keystone', client_id=None,
client_secret=None):
client_secret=None, session=None):
"""Kingbird communicates with Keystone to fetch necessary values."""
if kingbird_url and not isinstance(kingbird_url, six.string_types):
raise RuntimeError('Kingbird url should be a string.')
if auth_url:
if auth_url or session:
if auth_type == 'keystone':
(kingbird_url, auth_token, project_id, user_id) = (
authenticate(
@ -57,6 +57,7 @@ class Client(object):
service_type,
auth_token,
user_id,
session,
cacert,
insecure
)
@ -92,7 +93,7 @@ def authenticate(kingbird_url=None, username=None,
api_key=None, project_name=None, auth_url=None,
project_id=None, endpoint_type='publicURL',
service_type='synchronization', auth_token=None, user_id=None,
cacert=None, insecure=False):
session=None, cacert=None, insecure=False):
"""Get token, project_id, user_id and Endpoint."""
if project_name and project_id:
raise RuntimeError(
@ -104,27 +105,28 @@ def authenticate(kingbird_url=None, username=None,
'Only user name or user id should be set'
)
if auth_token:
auth = auth_plugin.Token(
auth_url=auth_url,
token=auth_token,
project_id=project_id,
project_name=project_name)
if session is None:
if auth_token:
auth = auth_plugin.Token(
auth_url=auth_url,
token=auth_token,
project_id=project_id,
project_name=project_name)
elif api_key and (username or user_id):
auth = auth_plugin.Password(
auth_url=auth_url,
username=username,
user_id=user_id,
password=api_key,
project_id=project_id,
project_name=project_name)
elif api_key and (username or user_id):
auth = auth_plugin.Password(
auth_url=auth_url,
username=username,
user_id=user_id,
password=api_key,
project_id=project_id,
project_name=project_name)
else:
raise RuntimeError('You must either provide a valid token or'
'a password (api_key) and a user.')
if auth:
session = ks_session.Session(auth=auth)
else:
raise RuntimeError('You must either provide a valid token or'
'a password (api_key) and a user.')
if auth:
session = ks_session.Session(auth=auth)
if session:
token = session.get_token()

View File

@ -0,0 +1,62 @@
#
# 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.
"""OpenStackClient plugin for Sync service."""
import logging
from osc_lib import utils
LOG = logging.getLogger(__name__)
DEFAULT_SYNC_API_VERSION = '1'
API_VERSION_OPTION = 'os_sync_api_version'
API_NAME = 'sync_engine'
API_VERSIONS = {
'1': 'kingbirdclient.api.v1.client.Client',
}
def make_client(instance):
"""Return a sync_engine service client."""
version = instance._api_version[API_NAME]
sync_client = utils.get_client_class(
API_NAME,
version,
API_VERSIONS)
LOG.debug('Instantiating sync engine client: %s', sync_client)
kingbird_url = instance.get_endpoint_for_service_type(
'synchronization',
interface='publicURL'
)
client = sync_client(kingbird_url=kingbird_url, session=instance.session)
return client
def build_option_parser(parser):
"""Hook to add global options."""
parser.add_argument(
'--os-sync-api-version',
metavar='<sync-api-version>',
default=utils.env(
'OS_SYNC_API_VERSION',
default=DEFAULT_SYNC_API_VERSION),
help='SYNC API version, default=' +
DEFAULT_SYNC_API_VERSION +
' (Env: OS_SYNC_API_VERSION)')
return parser