Switch Adjutant service type to Admin-Logic

Change-Id: Ic173891bfdd109d8d0fe1038d0ec10184da0e4e6
This commit is contained in:
Adrian Turjak 2020-02-20 11:46:23 +13:00
parent c0f32f26b3
commit 03c00a10d9
11 changed files with 44 additions and 52 deletions

View File

@ -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.

View File

@ -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

View File

@ -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='<registration-version>',
'--os-admin-logic-version',
metavar='<admin-logic-version>',
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

View File

@ -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))

View File

@ -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:

View File

@ -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)

View File

@ -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))

View File

@ -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))

View File

@ -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)

View File

@ -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)

View File

@ -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