diff --git a/README.rst b/README.rst index c6019b0..a3a8882 100644 --- a/README.rst +++ b/README.rst @@ -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= $ export OS_IDENTITY_API_VERSION= $ export OS_PASSWORD= -$ export OS_AUTH_URL=http://:5000/ +$ export OS_AUTH_TYPE=password +$ export OS_AUTH_URL=http:///identity $ export OS_USERNAME= $ export OS_TENANT_NAME= +$ export OS_VOLUME_API_VERSION= To make sure Kingbird client works, type: diff --git a/kingbirdclient/api/v1/client.py b/kingbirdclient/api/v1/client.py index 9faf374..2cebcd5 100644 --- a/kingbirdclient/api/v1/client.py +++ b/kingbirdclient/api/v1/client.py @@ -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() diff --git a/kingbirdclient/osc/plugin.py b/kingbirdclient/osc/plugin.py new file mode 100644 index 0000000..b967528 --- /dev/null +++ b/kingbirdclient/osc/plugin.py @@ -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='', + 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