From 6fd130998f7862a3d3498b3a505c8309aba62fee Mon Sep 17 00:00:00 2001 From: Michael McGrath Date: Mon, 10 Mar 2008 19:43:24 -0500 Subject: [PATCH] added additional quicknesses to the script. 1) The script now takes about 6 seconds to run against my workstation. 2) User Groups are only created if the host has those users on that OS 3) total IO transfer against a sample migration takes about 2.1M Compression takes that down to about 1.3M. It will likely be worth having our proxy servers do this compression for us. --- fas/client/fasClient | 38 +++++++++++++++++++------------------- fas/fas/user.py | 21 ++++++++++++++++++--- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/fas/client/fasClient b/fas/client/fasClient index 607a03f..d059f89 100755 --- a/fas/client/fasClient +++ b/fas/client/fasClient @@ -238,7 +238,7 @@ class MakeShellAccounts(BaseClient): shadow_file = codecs.open(self.temp + '/shadow.txt', mode='w', encoding='utf-8') os.chmod(self.temp + '/shadow.txt', 00400) if not self.people: - self.people = self.people_list() + self.people_list() for person in self.people: username = person['username'] if self.valid_user(username): @@ -281,23 +281,25 @@ class MakeShellAccounts(BaseClient): def groups_text(self, groups=None, people=None): i = 0 file = open(self.temp + '/group.txt', 'w') - if not groups: - groups = self.group_list() - if not people: - people = self.people_list() - - ''' First create all of our users/groups combo ''' - for person in people: - uid = person['id'] - if self.valid_user_group(uid): - username = person['username'] - file.write("=%i %s:x:%i:\n" % (uid, username, uid)) - file.write("0%i %s:x:%i:\n" % (i, username, uid)) - file.write(".%s %s:x:%i:\n" % (username, username, uid)) - i = i + 1 - + if not self.groups: + self.group_list() + if not self.people: + self.people_list() usernames = self.usernames() - for group in groups: + ''' First create all of our users/groups combo ''' + for person in self.people: + uid = person['id'] + try: + if self.valid_user(usernames[uid]): + username = person['username'] + file.write("=%i %s:x:%i:\n" % (uid, username, uid)) + file.write("0%i %s:x:%i:\n" % (i, username, uid)) + file.write(".%s %s:x:%i:\n" % (username, username, uid)) + i = i + 1 + except KeyError: + continue + + for group in self.groups: gid = group['id'] name = group['name'] try: @@ -314,7 +316,6 @@ class MakeShellAccounts(BaseClient): file.write("0%i %s:x:%i:%s\n" % (i, name, gid, memberships)) file.write(".%s %s:x:%i:%s\n" % (name, name, gid, memberships)) i = i + 1 - file.close() def group_list(self, search='*'): @@ -336,7 +337,6 @@ class MakeShellAccounts(BaseClient): def people_list(self, search='*'): params = {'search' : search} self.people = self.send_request('user/list', auth=True, input=params)['people'] - return self.people def email_list(self, search='*'): params = {'search' : search} diff --git a/fas/fas/user.py b/fas/fas/user.py index cf8bb4e..7d0cead 100644 --- a/fas/fas/user.py +++ b/fas/fas/user.py @@ -5,6 +5,8 @@ import cherrypy import turbomail +import sqlalchemy + import os import re import gpgme @@ -280,10 +282,23 @@ class User(controllers.Controller): def list(self, search="a*"): '''List users ''' + re_search = re.sub(r'\*', r'%', search).lower() - people = People.query.filter(People.username.like(re_search)).order_by('username') - if people.count() < 0: - turbogears.flash(_("No users found matching '%s'") % search) + if self.jsonRequest(): + people = [] + peoplesql = sqlalchemy.select([People.c.id, People.c.username, People.c.human_name, People.c.ssh_key, People.c.password]) + persons = peoplesql.execute() + for person in persons: + people.append({ + 'id' : person[0], + 'username' : person[1], + 'human_name' : person[2], + 'ssh_key' : person[3], + 'password' : person[4]}) + else: + people = People.query.filter(People.username.like(re_search)).order_by('username') + if people.count() < 0: + turbogears.flash(_("No users found matching '%s'") % search) return dict(people=people, search=search) @identity.require(turbogears.identity.not_anonymous())