From 03c00a10d9d96da5a096bafa3b62e442866a3499 Mon Sep 17 00:00:00 2001 From: Adrian Turjak Date: Thu, 20 Feb 2020 11:46:23 +1300 Subject: [PATCH] Switch Adjutant service type to Admin-Logic Change-Id: Ic173891bfdd109d8d0fe1038d0ec10184da0e4e6 --- README.rst | 2 +- adjutantclient/common/http.py | 2 +- adjutantclient/osc/plugin.py | 30 ++++++++++---------------- adjutantclient/osc/v1/notifications.py | 6 +++--- adjutantclient/osc/v1/quota.py | 8 +++---- adjutantclient/osc/v1/signup.py | 2 +- adjutantclient/osc/v1/status.py | 2 +- adjutantclient/osc/v1/tasks.py | 12 +++++------ adjutantclient/osc/v1/tokens.py | 8 +++---- adjutantclient/osc/v1/users.py | 20 ++++++++--------- setup.cfg | 4 ++-- 11 files changed, 44 insertions(+), 52 deletions(-) diff --git a/README.rst b/README.rst index 8ab3e3e..dfcbb66 100644 --- a/README.rst +++ b/README.rst @@ -33,7 +33,7 @@ You can use the API with a keystone session: If you use a clouds.yaml file os_client_config can also be used: >>> import os_client_config - >>> sess = os_client_config.make_rest_client('registration') + >>> sess = os_client_config.make_rest_client('admin-logic') >>> adjutant = Client('1', session=sess) A few of the endpoints (users.password_forgot(), token.submit(), signup, token.get()) don't require authentication. diff --git a/adjutantclient/common/http.py b/adjutantclient/common/http.py index 14b59a9..be4f5ac 100644 --- a/adjutantclient/common/http.py +++ b/adjutantclient/common/http.py @@ -132,7 +132,7 @@ def _construct_http_client(endpoint=None, username=None, password=None, kwargs['endpoint_override'] = endpoint if 'service_type' not in kwargs: - kwargs['service_type'] = 'registration' + kwargs['service_type'] = 'admin-logic' if 'interface' not in kwargs and endpoint_type: kwargs['interface'] = endpoint_type diff --git a/adjutantclient/osc/plugin.py b/adjutantclient/osc/plugin.py index 00f16ad..5609e36 100644 --- a/adjutantclient/osc/plugin.py +++ b/adjutantclient/osc/plugin.py @@ -18,10 +18,10 @@ from osc_lib import utils LOG = logging.getLogger(__name__) -DEFAULT_OS_REGISTRATION_VERSION = '1' +DEFAULT_OS_ADMIN_LOGIC_VERSION = '1' DEFAULT_API_VERSION = '1' -API_VERSION_OPTION = 'os_registration_version' -API_NAME = "registration" +API_VERSION_OPTION = 'os_admin_logic_version' +API_NAME = "admin_logic" API_VERSIONS = { "1": "adjutantclient.v1.client.Client", } @@ -47,17 +47,9 @@ def make_client(instance): kwargs = {'region_name': instance.region_name} if instance.session: - kwargs.update({'session': instance.session, - 'service_type': API_NAME}) + kwargs.update({'session': instance.session}) else: - endpoint = instance.get_endpoint_for_service_type( - API_NAME, - region_name=instance.region_name, - interface=instance.interface, - ) - - kwargs.update({'endpoint': endpoint, - 'auth_url': instance.auth.auth_url, + kwargs.update({'auth_url': instance.auth.auth_url, 'username': instance.auth_ref.username, 'token': instance.auth_ref.auth_token}) @@ -69,12 +61,12 @@ def make_client(instance): def build_option_parser(parser): """Hook to add global options.""" parser.add_argument( - '--os-registration-version', - metavar='', + '--os-admin-logic-version', + metavar='', default=utils.env( - 'OS_REGISTRATION_VERSION', - default=DEFAULT_OS_REGISTRATION_VERSION), + 'OS_ADMIN_LOGIC_VERSION', + default=DEFAULT_OS_ADMIN_LOGIC_VERSION), help=('Client version, default=' + - DEFAULT_OS_REGISTRATION_VERSION + - ' (Env: DEFAULT_OS_REGISTRATION_VERSION)')) + DEFAULT_OS_ADMIN_LOGIC_VERSION + + ' (Env: DEFAULT_OS_ADMIN_LOGIC_VERSION)')) return parser diff --git a/adjutantclient/osc/v1/notifications.py b/adjutantclient/osc/v1/notifications.py index cc74703..4c92bd6 100644 --- a/adjutantclient/osc/v1/notifications.py +++ b/adjutantclient/osc/v1/notifications.py @@ -46,7 +46,7 @@ class NotificationList(command.Lister): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic kwargs = {} if parsed_args.filters: @@ -74,7 +74,7 @@ class NotificationShow(command.ShowOne): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic return _show_notification(parsed_args.notification_id, client, parsed_args.formatter) @@ -89,6 +89,6 @@ class NotificationAcknowledge(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic resp = client.notifications.acknowledge(note_list=parsed_args.note_ids) print('Success', ' '.join(resp.notes)) diff --git a/adjutantclient/osc/v1/quota.py b/adjutantclient/osc/v1/quota.py index 42ca7e5..ff7662e 100644 --- a/adjutantclient/osc/v1/quota.py +++ b/adjutantclient/osc/v1/quota.py @@ -39,7 +39,7 @@ class QuotaShow(command.Lister): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic if not parsed_args.region: quota_data = client.quota.get() @@ -76,7 +76,7 @@ class QuotaSizes(command.Lister): """ def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic quota_data = client.quota.get() @@ -98,7 +98,7 @@ class QuotaTasks(command.Lister): """ def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic quota_data = client.quota.get() @@ -137,7 +137,7 @@ class QuotaUpdate(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic if parsed_args.regions: status = client.quota.update(parsed_args.size, parsed_args.regions) else: diff --git a/adjutantclient/osc/v1/signup.py b/adjutantclient/osc/v1/signup.py index 707d72f..ad70d24 100644 --- a/adjutantclient/osc/v1/signup.py +++ b/adjutantclient/osc/v1/signup.py @@ -58,7 +58,7 @@ class Signup(command.Command): # user wanting to access and submit a sign up (I.E. an admin) self.app.client_manager._auth_required = True self.app.client_manager.setup_auth() - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic else: client = adjutant_client.Client(1, parsed_args.bypass_url) diff --git a/adjutantclient/osc/v1/status.py b/adjutantclient/osc/v1/status.py index 41a92d3..f99e7a4 100644 --- a/adjutantclient/osc/v1/status.py +++ b/adjutantclient/osc/v1/status.py @@ -25,7 +25,7 @@ class Status(command.Command): """Lists adjutant tasks. """ def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic status = client.status.get().json() print(json.dumps(status, indent=2)) diff --git a/adjutantclient/osc/v1/tasks.py b/adjutantclient/osc/v1/tasks.py index 8973957..e173c2a 100644 --- a/adjutantclient/osc/v1/tasks.py +++ b/adjutantclient/osc/v1/tasks.py @@ -56,7 +56,7 @@ class TaskList(command.Lister): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic kwargs = {'filters': parsed_args.filters} @@ -88,7 +88,7 @@ class TaskShow(command.ShowOne): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic return _show_task(parsed_args.task_id, client, parsed_args.formatter) @@ -103,7 +103,7 @@ class TaskApprove(command.ShowOne): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic client.tasks.approve(parsed_args.task_id) return _show_task(parsed_args.task_id, client, parsed_args.formatter) @@ -119,7 +119,7 @@ class TaskCancel(command.ShowOne): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic client.tasks.cancel(task_id=parsed_args.task_id) return _show_task(parsed_args.task_id, client, parsed_args.formatter) @@ -138,7 +138,7 @@ class TaskUpdate(command.ShowOne): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic client.tasks.update(task_id=parsed_args.task_id, data=json.loads(parsed_args.data)) return _show_task(parsed_args.task_id, client, parsed_args.formatter) @@ -154,6 +154,6 @@ class TaskTokenReissue(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic resp = client.tokens.reissue(task_id=parsed_args.task_id) print('Success', ' '.join(resp.notes)) diff --git a/adjutantclient/osc/v1/tokens.py b/adjutantclient/osc/v1/tokens.py index 38d6d83..f07df0e 100644 --- a/adjutantclient/osc/v1/tokens.py +++ b/adjutantclient/osc/v1/tokens.py @@ -49,7 +49,7 @@ class TokenList(command.Lister): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic return _list_tokens(client, parsed_args.filters) @@ -71,7 +71,7 @@ class TokenShow(command.ShowOne): if not parsed_args.bypass_url: self.app.client_manager._auth_required = True self.app.client_manager.setup_auth() - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic else: client = adjutant_client.Client("1", parsed_args.bypass_url) token = client.tokens.get(parsed_args.token) @@ -91,7 +91,7 @@ class TokenSubmit(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic resp = client.tokens.submit( parsed_args.token, json.loads(parsed_args.data)) print('Success', ' '.join(resp.notes)) @@ -101,7 +101,7 @@ class TokenClear(command.Lister): """Clear Expired tokens, admin only.""" def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic resp = client.tokens.clear_expired() print('Success. ' + ' '.join(resp.json()['notes'])) return _list_tokens(client) diff --git a/adjutantclient/osc/v1/users.py b/adjutantclient/osc/v1/users.py index 051ecc2..2b437ac 100644 --- a/adjutantclient/osc/v1/users.py +++ b/adjutantclient/osc/v1/users.py @@ -29,7 +29,7 @@ class UserList(command.Lister): """Lists users in the currently scoped project. """ def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic project_users = client.users.list() headers = [ 'id', 'name', 'email', 'roles', 'cohort', 'status'] @@ -53,7 +53,7 @@ class UserShow(command.ShowOne): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic # This ends up for names doing multiple requests, it may # be better to do something slightly different here user_id = utils.find_resource(client.users, parsed_args.user) @@ -85,7 +85,7 @@ class UserInvite(command.Command): def take_action(self, parsed_args): if not parsed_args.roles: parsed_args.roles = ['Member'] - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic client.users.invite( username=parsed_args.username, email=parsed_args.email, role_list=parsed_args.roles) @@ -104,7 +104,7 @@ class UserInviteCancel(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic for user in parsed_args.user: try: user_id = client.users.find(name=user).id @@ -128,7 +128,7 @@ class UserRoleAdd(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic role = utils.find_resource(client.managed_roles, parsed_args.role) user = utils.find_resource(client.users, parsed_args.user) @@ -150,7 +150,7 @@ class UserRoleRemove(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic role = utils.find_resource(client.managed_roles, parsed_args.role) user = utils.find_resource(client.users, parsed_args.user) @@ -169,7 +169,7 @@ class UserRoleList(command.Lister): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic user = utils.find_resource(client.users, parsed_args.user) kwargs = {'user': user.id} @@ -181,7 +181,7 @@ class UserRoleList(command.Lister): class ManageableRolesList(command.Lister): """ Lists roles able to be managed by the current user """ def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic roles = client.managed_roles.list() headers = ['id', 'name'] @@ -205,7 +205,7 @@ class PasswordReset(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic data = {'email': parsed_args.email} if parsed_args.username: @@ -240,7 +240,7 @@ class PasswordForgot(command.Command): if not parsed_args.bypass_url: self.app.client_manager._auth_required = True self.app.client_manager.setup_auth() - client = self.app.client_manager.registration + client = self.app.client_manager.admin_logic else: client = adjutant_client.Client(1, parsed_args.bypass_url) diff --git a/setup.cfg b/setup.cfg index 64195f2..f0c3495 100644 --- a/setup.cfg +++ b/setup.cfg @@ -23,9 +23,9 @@ packages = [entry_points] openstack.cli.extension = - registration = adjutantclient.osc.plugin + admin_logic = adjutantclient.osc.plugin -openstack.registration.v1 = +openstack.admin_logic.v1 = admin_task_list = adjutantclient.osc.v1.tasks:TaskList admin_task_show = adjutantclient.osc.v1.tasks:TaskShow admin_task_approve = adjutantclient.osc.v1.tasks:TaskApprove