Adding task-list and reissue-token
Change-Id: Ia39c70d9059abbaec837ae4204f3b26b7e178eb7
This commit is contained in:
@@ -17,6 +17,7 @@ from stacktaskclient.common import http
|
||||
from stacktaskclient.v1 import users
|
||||
from stacktaskclient.v1 import roles
|
||||
from stacktaskclient.v1 import tokens
|
||||
from stacktaskclient.v1 import tasks
|
||||
|
||||
|
||||
class Client(object):
|
||||
@@ -37,3 +38,4 @@ class Client(object):
|
||||
self.user_roles = roles.UserRolesManager(self.http_client)
|
||||
self.managed_roles = roles.ManagedRolesManager(self.http_client)
|
||||
self.tokens = tokens.TokenManager(self.http_client)
|
||||
self.tasks = tasks.TaskManager(self.http_client)
|
||||
|
||||
@@ -32,10 +32,12 @@ class ManagedRolesManager(base.ManagerWithFind):
|
||||
def list(self, **kwargs):
|
||||
"""Get a list of roles that can be managed.
|
||||
|
||||
:rtype: list of :class:`Users`
|
||||
:rtype: list of :class:`Roles`
|
||||
"""
|
||||
params = {}
|
||||
url = '/openstack/roles?%(params)s' % {'params': parse.urlencode(params, True)}
|
||||
url = '/openstack/roles?%(params)s' % {
|
||||
'params': parse.urlencode(params, True)
|
||||
}
|
||||
return self._list(url, 'roles')
|
||||
|
||||
def get(self, role_id):
|
||||
|
||||
@@ -13,27 +13,12 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import fnmatch
|
||||
import logging
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import strutils
|
||||
import six
|
||||
from six.moves.urllib import request
|
||||
import time
|
||||
import yaml
|
||||
import json
|
||||
|
||||
from stacktaskclient.common import deployment_utils
|
||||
from stacktaskclient.common import event_utils
|
||||
from stacktaskclient.common import http
|
||||
from stacktaskclient.common import template_format
|
||||
from stacktaskclient.common import template_utils
|
||||
from stacktaskclient.common import utils
|
||||
|
||||
from stacktaskclient.openstack.common._i18n import _
|
||||
from stacktaskclient.openstack.common._i18n import _LE
|
||||
from stacktaskclient.openstack.common._i18n import _LW
|
||||
|
||||
import stacktaskclient.exc as exc
|
||||
|
||||
@@ -70,7 +55,7 @@ def do_user_list(hc, args):
|
||||
help=_('Invite to a particular tenant id'))
|
||||
@utils.arg('email', metavar='<email>',
|
||||
help=_('Email address of user to invite'))
|
||||
def do_user_invite_send(hc, args):
|
||||
def do_user_invite(hc, args):
|
||||
"""
|
||||
Invites a user to become a member of a tenant.
|
||||
User does not need to have an existing openstack account.
|
||||
@@ -78,7 +63,8 @@ def do_user_invite_send(hc, args):
|
||||
roles = args.roles or ['Member']
|
||||
|
||||
if args.tenant:
|
||||
tenant_id = args.tenant # utils.find_resource(hc.tenants, args.tenant).id
|
||||
# utils.find_resource(hc.tenants, args.tenant).id
|
||||
tenant_id = args.tenant
|
||||
else:
|
||||
tenant_id = None
|
||||
|
||||
@@ -91,13 +77,51 @@ def do_user_invite_send(hc, args):
|
||||
print "400 Bad Request: " + e.message
|
||||
print e
|
||||
else:
|
||||
print "Invitation sent. (todo: print pending users)"
|
||||
print "Invitation sent. (todo: print only pending users)"
|
||||
do_user_list(hc, args)
|
||||
|
||||
|
||||
@utils.arg('--all-tenants',
|
||||
help=_('Display tasks from all tenants instead of just current'))
|
||||
def do_task_list(hc, args):
|
||||
"""
|
||||
Show all pending tasks in the current tenant
|
||||
"""
|
||||
fields = [
|
||||
'uuid', 'task_type', 'created_on',
|
||||
'approved_on', 'completed_on', 'actions', 'action_notes']
|
||||
tasks_list = hc.tasks.list()
|
||||
# split by type, and print with different fields
|
||||
# task_types = {}
|
||||
# for task in task_types:
|
||||
# task_types[task.task_type] = task
|
||||
utils.print_list(tasks_list, fields)
|
||||
|
||||
|
||||
@utils.arg('--task-id', metavar='<taskid>', required=True,
|
||||
help=_('Task ID.'))
|
||||
def do_task_reissue_token(hc, args):
|
||||
"""
|
||||
Re-issues the token for the provided pending task.
|
||||
"""
|
||||
try:
|
||||
resp = hc.tokens.reissue(task_id=args.task_id)
|
||||
except exc.HTTPNotFound as e:
|
||||
print e.message
|
||||
except exc.HTTPBadRequest as e:
|
||||
print e.message
|
||||
else:
|
||||
print 'Success:', ' '.join(resp.notes)
|
||||
do_user_list(hc, args)
|
||||
|
||||
|
||||
@utils.arg('token', metavar='<token>',
|
||||
help=_('Token id of the task'))
|
||||
def do_token_show(hc, args):
|
||||
"""Show details of this token, including the arguments required for submit"""
|
||||
"""
|
||||
Show details of this token
|
||||
including the arguments required for submit
|
||||
"""
|
||||
fields = ['required_fields', 'actions']
|
||||
try:
|
||||
tokens = hc.tokens.show(args.token)
|
||||
@@ -108,16 +132,6 @@ def do_token_show(hc, args):
|
||||
utils.print_list(tokens, fields, sortby_index=1)
|
||||
|
||||
|
||||
#@utils.arg('--all-tenants', help=_('Display tasks from all tenants instead of just current'))
|
||||
#def do_task_list(hc, args):
|
||||
# """
|
||||
# Show all pending tasks in the current tenant
|
||||
# """
|
||||
# fields = ['id', 'task_uuid', 'token_uuid', 'created_on', 'expires']
|
||||
# token_list = hc.tokens.list()
|
||||
# utils.print_list(token_list, fields)
|
||||
|
||||
|
||||
@utils.arg('token', metavar='<token>',
|
||||
help=_('Token id of the task'))
|
||||
@utils.arg('--password', metavar='<password>', required=True,
|
||||
@@ -184,7 +198,11 @@ def do_user_role_remove(hc, args):
|
||||
help=_('email of the user account to reset'))
|
||||
def do_user_password_forgot(rc, args):
|
||||
"""Request a password reset email for a user."""
|
||||
status = rc.http_client.post("/openstack/forgotpassword/")
|
||||
data = {"email": args.email}
|
||||
status = rc.http_client.post("/openstack/forgotpassword/", data=data)
|
||||
if status.status_code != 200:
|
||||
print "Failed: %s" % status.reason
|
||||
return
|
||||
|
||||
|
||||
@utils.arg('email', metavar='<email>',
|
||||
|
||||
41
stacktaskclient/v1/tasks.py
Normal file
41
stacktaskclient/v1/tasks.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# Copyright 2012 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from stacktaskclient.openstack.common.apiclient import base
|
||||
|
||||
|
||||
class Task(base.Resource):
|
||||
pass
|
||||
|
||||
|
||||
class TaskManager(base.ManagerWithFind):
|
||||
resource_class = Task
|
||||
|
||||
def get(self, user):
|
||||
return self._get("/tasks/%s" % base.getid(user))
|
||||
|
||||
def list(self, **kwargs):
|
||||
"""Get a list of tasks.
|
||||
|
||||
:rtype: list of :class:`Task`
|
||||
"""
|
||||
|
||||
params = {}
|
||||
url = '/tasks?%(params)s' % {
|
||||
'params': parse.urlencode(params, True)
|
||||
}
|
||||
return self._list(url, 'tasks')
|
||||
@@ -28,3 +28,11 @@ class TokenManager(base.BaseManager):
|
||||
url = 'tokens/%s' % token_id
|
||||
json = parameters
|
||||
return self._post(url, json)
|
||||
|
||||
def reissue(self, task_id):
|
||||
""" Given a task id, reissues the tokens associated with that task """
|
||||
url = 'tokens'
|
||||
json = {
|
||||
'task': task_id
|
||||
}
|
||||
return self._post(url, json)
|
||||
|
||||
Reference in New Issue
Block a user