~ubuntu-branches/ubuntu/trusty/python-keystoneclient/trusty-proposed

« back to all changes in this revision

Viewing changes to keystoneclient/v2_0/shell.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-01-18 07:44:54 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20130118074454-g7w5blpynohn1s48
Tags: 1:0.2.2-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#    under the License.
17
17
 
18
18
import argparse
 
19
import getpass
19
20
 
20
21
from keystoneclient.v2_0 import client
21
22
from keystoneclient import utils
43
44
def do_user_list(kc, args):
44
45
    """List users"""
45
46
    users = kc.users.list(tenant_id=args.tenant_id)
46
 
    utils.print_list(users, ['id', 'name', 'enabled', 'email'])
 
47
    utils.print_list(users, ['id', 'name', 'enabled', 'email'],
 
48
                     order_by='name')
47
49
 
48
50
 
49
51
@utils.arg('id', metavar='<user-id>', help='User ID to display')
108
110
    kc.users.update_password(args.id, args.passwd)
109
111
 
110
112
 
 
113
@utils.arg('--current-password', metavar='<current-password>',
 
114
           dest='currentpasswd', required=False, help='Current password, '
 
115
                'Defaults to the password as set by --os-password or '
 
116
                'OS_PASSWORD')
 
117
@utils.arg('--new-password ', metavar='<new-password>', dest='newpasswd',
 
118
           required=False, help='Desired new password')
 
119
def do_password_update(kc, args):
 
120
    """Update own password"""
 
121
 
 
122
    # we are prompting for these passwords if they are not passed in
 
123
    # this gives users the option not to have their password
 
124
    # appear in bash history etc..
 
125
    currentpasswd = args.os_password
 
126
    if args.currentpasswd is not None:
 
127
        currentpasswd = args.currentpasswd
 
128
    if currentpasswd is None:
 
129
        currentpasswd = getpass.getpass('Current Password: ')
 
130
 
 
131
    newpasswd = args.newpasswd
 
132
    while newpasswd is None:
 
133
        passwd1 = getpass.getpass('New Password: ')
 
134
        passwd2 = getpass.getpass('Repeat New Password: ')
 
135
        if passwd1 == passwd2:
 
136
            newpasswd = passwd1
 
137
 
 
138
    kc.users.update_own_password(currentpasswd, newpasswd)
 
139
 
 
140
    if args.os_password != newpasswd:
 
141
        print "You should update the password you are using to authenticate "\
 
142
              "to match your new password"
 
143
 
 
144
 
111
145
@utils.arg('id', metavar='<user-id>', help='User ID to delete')
112
146
def do_user_delete(kc, args):
113
147
    """Delete user"""
117
151
def do_tenant_list(kc, args):
118
152
    """List all tenants"""
119
153
    tenants = kc.tenants.list()
120
 
    utils.print_list(tenants, ['id', 'name', 'enabled'])
 
154
    utils.print_list(tenants, ['id', 'name', 'enabled'], order_by='name')
121
155
 
122
156
 
123
157
@utils.arg('id', metavar='<tenant-id>', help='Tenant ID to display')
189
223
def do_service_list(kc, args):
190
224
    """List all services in Service Catalog"""
191
225
    services = kc.services.list()
192
 
    utils.print_list(services, ['id', 'name', 'type', 'description'])
 
226
    utils.print_list(services, ['id', 'name', 'type', 'description'],
 
227
                     order_by='name')
193
228
 
194
229
 
195
230
@utils.arg('id', metavar='<service-id>', help='Service ID to display')
208
243
def do_role_list(kc, args):
209
244
    """List all roles"""
210
245
    roles = kc.roles.list()
211
 
    utils.print_list(roles, ['id', 'name'])
 
246
    utils.print_list(roles, ['id', 'name'], order_by='name')
212
247
 
213
248
 
214
249
@utils.arg('id', metavar='<role-id>', help='Role ID to display')
277
312
        role.user_id = args.user_id
278
313
        role.tenant_id = args.tenant_id
279
314
 
280
 
    utils.print_list(roles, ['id', 'name', 'user_id', 'tenant_id'])
 
315
    utils.print_list(roles, ['id', 'name', 'user_id', 'tenant_id'],
 
316
                     order_by='name')
281
317
 
282
318
 
283
319
@utils.arg('--user-id', metavar='<user-id>', help='User ID')
285
321
@utils.arg('--tenant-id', metavar='<tenant-id>', help='Tenant ID')
286
322
@utils.arg('--tenant_id', help=argparse.SUPPRESS)
287
323
def do_ec2_credentials_create(kc, args):
288
 
    """Create EC2-compatibile credentials for user per tenant"""
 
324
    """Create EC2-compatible credentials for user per tenant"""
289
325
    if not args.tenant_id:
290
326
        # use the authenticated tenant id as a default
291
327
        args.tenant_id = kc.auth_tenant_id
301
337
@utils.arg('--access', metavar='<access-key>', required=True,
302
338
           help='Access Key')
303
339
def do_ec2_credentials_get(kc, args):
304
 
    """Display EC2-compatibile credentials"""
 
340
    """Display EC2-compatible credentials"""
305
341
    if not args.user_id:
306
342
        # use the authenticated user id as a default
307
343
        args.user_id = kc.auth_user_id
313
349
@utils.arg('--user-id', metavar='<user-id>', help='User ID')
314
350
@utils.arg('--user_id', help=argparse.SUPPRESS)
315
351
def do_ec2_credentials_list(kc, args):
316
 
    """List EC2-compatibile credentials for a user"""
 
352
    """List EC2-compatible credentials for a user"""
317
353
    if not args.user_id:
318
354
        # use the authenticated user id as a default
319
355
        args.user_id = kc.auth_user_id
333
369
@utils.arg('--access', metavar='<access-key>', required=True,
334
370
           help='Access Key')
335
371
def do_ec2_credentials_delete(kc, args):
336
 
    """Delete EC2-compatibile credentials"""
 
372
    """Delete EC2-compatible credentials"""
337
373
    if not args.user_id:
338
374
        # use the authenticated user id as a default
339
375
        args.user_id = kc.auth_user_id