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:
parent
5a1dfd23f8
commit
bf641ae368
@ -40,14 +40,20 @@ or
|
|||||||
Running Kingbird client
|
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_REGION_NAME=RegionOne
|
||||||
$ export OS_USER_DOMAIN_ID=default
|
$ export OS_USER_DOMAIN_ID=default
|
||||||
$ export OS_PROJECT_NAME=<project_name>
|
$ export OS_PROJECT_NAME=<project_name>
|
||||||
$ export OS_IDENTITY_API_VERSION=<identity_version>
|
$ export OS_IDENTITY_API_VERSION=<identity_version>
|
||||||
$ export OS_PASSWORD=<password>
|
$ 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_USERNAME=<user_name>
|
||||||
$ export OS_TENANT_NAME=<tenant_name>
|
$ export OS_TENANT_NAME=<tenant_name>
|
||||||
|
$ export OS_VOLUME_API_VERSION=<volume_version>
|
||||||
|
|
||||||
To make sure Kingbird client works, type:
|
To make sure Kingbird client works, type:
|
||||||
|
|
||||||
|
@ -38,12 +38,12 @@ class Client(object):
|
|||||||
endpoint_type='publicURL', service_type='synchronization',
|
endpoint_type='publicURL', service_type='synchronization',
|
||||||
auth_token=None, user_id=None, cacert=None, insecure=False,
|
auth_token=None, user_id=None, cacert=None, insecure=False,
|
||||||
profile=None, auth_type='keystone', client_id=None,
|
profile=None, auth_type='keystone', client_id=None,
|
||||||
client_secret=None):
|
client_secret=None, session=None):
|
||||||
"""Kingbird communicates with Keystone to fetch necessary values."""
|
"""Kingbird communicates with Keystone to fetch necessary values."""
|
||||||
if kingbird_url and not isinstance(kingbird_url, six.string_types):
|
if kingbird_url and not isinstance(kingbird_url, six.string_types):
|
||||||
raise RuntimeError('Kingbird url should be a string.')
|
raise RuntimeError('Kingbird url should be a string.')
|
||||||
|
|
||||||
if auth_url:
|
if auth_url or session:
|
||||||
if auth_type == 'keystone':
|
if auth_type == 'keystone':
|
||||||
(kingbird_url, auth_token, project_id, user_id) = (
|
(kingbird_url, auth_token, project_id, user_id) = (
|
||||||
authenticate(
|
authenticate(
|
||||||
@ -57,6 +57,7 @@ class Client(object):
|
|||||||
service_type,
|
service_type,
|
||||||
auth_token,
|
auth_token,
|
||||||
user_id,
|
user_id,
|
||||||
|
session,
|
||||||
cacert,
|
cacert,
|
||||||
insecure
|
insecure
|
||||||
)
|
)
|
||||||
@ -92,7 +93,7 @@ def authenticate(kingbird_url=None, username=None,
|
|||||||
api_key=None, project_name=None, auth_url=None,
|
api_key=None, project_name=None, auth_url=None,
|
||||||
project_id=None, endpoint_type='publicURL',
|
project_id=None, endpoint_type='publicURL',
|
||||||
service_type='synchronization', auth_token=None, user_id=None,
|
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."""
|
"""Get token, project_id, user_id and Endpoint."""
|
||||||
if project_name and project_id:
|
if project_name and project_id:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
@ -104,27 +105,28 @@ def authenticate(kingbird_url=None, username=None,
|
|||||||
'Only user name or user id should be set'
|
'Only user name or user id should be set'
|
||||||
)
|
)
|
||||||
|
|
||||||
if auth_token:
|
if session is None:
|
||||||
auth = auth_plugin.Token(
|
if auth_token:
|
||||||
auth_url=auth_url,
|
auth = auth_plugin.Token(
|
||||||
token=auth_token,
|
auth_url=auth_url,
|
||||||
project_id=project_id,
|
token=auth_token,
|
||||||
project_name=project_name)
|
project_id=project_id,
|
||||||
|
project_name=project_name)
|
||||||
|
|
||||||
elif api_key and (username or user_id):
|
elif api_key and (username or user_id):
|
||||||
auth = auth_plugin.Password(
|
auth = auth_plugin.Password(
|
||||||
auth_url=auth_url,
|
auth_url=auth_url,
|
||||||
username=username,
|
username=username,
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
password=api_key,
|
password=api_key,
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
project_name=project_name)
|
project_name=project_name)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('You must either provide a valid token or'
|
raise RuntimeError('You must either provide a valid token or'
|
||||||
'a password (api_key) and a user.')
|
'a password (api_key) and a user.')
|
||||||
if auth:
|
if auth:
|
||||||
session = ks_session.Session(auth=auth)
|
session = ks_session.Session(auth=auth)
|
||||||
|
|
||||||
if session:
|
if session:
|
||||||
token = session.get_token()
|
token = session.get_token()
|
||||||
|
62
kingbirdclient/osc/plugin.py
Normal file
62
kingbirdclient/osc/plugin.py
Normal 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
|
Loading…
x
Reference in New Issue
Block a user