~ntt-pf-lab/nova/lp703037

« back to all changes in this revision

Viewing changes to nova/auth/ldapdriver.py

  • Committer: Hisaharu Ishii
  • Date: 2011-01-21 11:04:02 UTC
  • mfrom: (572.1.25 nova)
  • Revision ID: ishii.hisaharu@lab.ntt.co.jp-20110121110402-29ict0qj0qvdl4dm
Merged with rev597

Show diffs side-by-side

added added

removed removed

Lines of Context:
146
146
    def create_user(self, name, access_key, secret_key, is_admin):
147
147
        """Create a user"""
148
148
        if self.__user_exists(name):
149
 
            raise exception.Duplicate("LDAP user %s already exists" % name)
 
149
            raise exception.Duplicate(_("LDAP user %s already exists") % name)
150
150
        if FLAGS.ldap_user_modify_only:
151
151
            if self.__ldap_user_exists(name):
152
152
                # Retrieve user by name
310
310
    def delete_user(self, uid):
311
311
        """Delete a user"""
312
312
        if not self.__user_exists(uid):
313
 
            raise exception.NotFound("User %s doesn't exist" % uid)
 
313
            raise exception.NotFound(_("User %s doesn't exist") % uid)
314
314
        self.__remove_from_all(uid)
315
315
        if FLAGS.ldap_user_modify_only:
316
316
            # Delete attributes
432
432
                       description, member_uids=None):
433
433
        """Create a group"""
434
434
        if self.__group_exists(group_dn):
435
 
            raise exception.Duplicate("Group can't be created because "
436
 
                                      "group %s already exists" % name)
 
435
            raise exception.Duplicate(_("Group can't be created because "
 
436
                                        "group %s already exists") % name)
437
437
        members = []
438
438
        if member_uids is not None:
439
439
            for member_uid in member_uids:
440
440
                if not self.__user_exists(member_uid):
441
 
                    raise exception.NotFound("Group can't be created "
442
 
                                             "because user %s doesn't exist" %
443
 
                                             member_uid)
 
441
                    raise exception.NotFound(_("Group can't be created "
 
442
                                               "because user %s doesn't exist")
 
443
                                             % member_uid)
444
444
                members.append(self.__uid_to_dn(member_uid))
445
445
        dn = self.__uid_to_dn(uid)
446
446
        if not dn in members:
455
455
    def __is_in_group(self, uid, group_dn):
456
456
        """Check if user is in group"""
457
457
        if not self.__user_exists(uid):
458
 
            raise exception.NotFound("User %s can't be searched in group "
459
 
                                     "because the user doesn't exist" % uid)
 
458
            raise exception.NotFound(_("User %s can't be searched in group "
 
459
                                       "because the user doesn't exist") % uid)
460
460
        if not self.__group_exists(group_dn):
461
461
            return False
462
462
        res = self.__find_object(group_dn,
467
467
    def __add_to_group(self, uid, group_dn):
468
468
        """Add user to group"""
469
469
        if not self.__user_exists(uid):
470
 
            raise exception.NotFound("User %s can't be added to the group "
471
 
                                     "because the user doesn't exist" % uid)
 
470
            raise exception.NotFound(_("User %s can't be added to the group "
 
471
                                       "because the user doesn't exist") % uid)
472
472
        if not self.__group_exists(group_dn):
473
 
            raise exception.NotFound("The group at dn %s doesn't exist" %
 
473
            raise exception.NotFound(_("The group at dn %s doesn't exist") %
474
474
                                     group_dn)
475
475
        if self.__is_in_group(uid, group_dn):
476
476
            raise exception.Duplicate(_("User %s is already a member of "
481
481
    def __remove_from_group(self, uid, group_dn):
482
482
        """Remove user from group"""
483
483
        if not self.__group_exists(group_dn):
484
 
            raise exception.NotFound("The group at dn %s doesn't exist" %
485
 
                                     group_dn)
 
484
            raise exception.NotFound(_("The group at dn %s doesn't exist")
 
485
                                     % group_dn)
486
486
        if not self.__user_exists(uid):
487
 
            raise exception.NotFound("User %s can't be removed from the "
488
 
                                     "group because the user doesn't exist" %
489
 
                                     uid)
 
487
            raise exception.NotFound(_("User %s can't be removed from the "
 
488
                                       "group because the user doesn't exist")
 
489
                                     % uid)
490
490
        if not self.__is_in_group(uid, group_dn):
491
 
            raise exception.NotFound("User %s is not a member of the group" %
492
 
                                     uid)
 
491
            raise exception.NotFound(_("User %s is not a member of the group")
 
492
                                     % uid)
493
493
        # NOTE(vish): remove user from group and any sub_groups
494
494
        sub_dns = self.__find_group_dns_with_member(group_dn, uid)
495
495
        for sub_dn in sub_dns:
509
509
    def __remove_from_all(self, uid):
510
510
        """Remove user from all roles and projects"""
511
511
        if not self.__user_exists(uid):
512
 
            raise exception.NotFound("User %s can't be removed from all "
513
 
                                     "because the user doesn't exist" % uid)
 
512
            raise exception.NotFound(_("User %s can't be removed from all "
 
513
                                       "because the user doesn't exist")
 
514
                                     % uid)
514
515
        role_dns = self.__find_group_dns_with_member(
515
516
                FLAGS.role_project_subtree, uid)
516
517
        for role_dn in role_dns: