diff options
| author | Ziad Sawalha <github@highbridgellc.com> | 2011-04-21 11:20:19 -0500 |
|---|---|---|
| committer | Ziad Sawalha <github@highbridgellc.com> | 2011-04-21 11:20:19 -0500 |
| commit | f7479387cff81c91a7c5cede7c0d511d15dfc269 (patch) | |
| tree | a78d2d4591c1ac5ec4d3c2d86f193960f19e3d90 | |
| parent | 5abebbd69c65c67d3198411438fce12aee3e3b32 (diff) | |
SQL Alchemy additions
| -rw-r--r-- | keystone/db/sqlalchemy/api.py | 5 | ||||
| -rw-r--r-- | management/useradd.py | 25 |
2 files changed, 20 insertions, 10 deletions
diff --git a/keystone/db/sqlalchemy/api.py b/keystone/db/sqlalchemy/api.py index 597896a4..3ceb7f9e 100644 --- a/keystone/db/sqlalchemy/api.py +++ b/keystone/db/sqlalchemy/api.py @@ -53,3 +53,8 @@ def tenant_delete(id, session=None): tenant_ref = tenant_get(id, session) session.delete(tenant_ref) +def user_create(values): + user_ref = models.User() + user_ref.update(values) + user_ref.save() + return user_ref diff --git a/management/useradd.py b/management/useradd.py index 6d70f2fc..4d67cc38 100644 --- a/management/useradd.py +++ b/management/useradd.py @@ -14,8 +14,9 @@ # limitations under the License.
import optparse
-import os
-import sqlite3
+from keystone.db.sqlalchemy import api
+from keystone.db.sqlalchemy import models
+
def main():
usage = "usage: %prog username password"
@@ -26,14 +27,18 @@ def main(): else:
username = args[0]
password = args[1]
- dbpath = os.path.abspath(
- os.path.join(os.path.dirname(__file__),'../db/keystone.db'))
- con = sqlite3.connect(dbpath)
- cur = con.cursor()
- cur.execute(
- "INSERT INTO users VALUES ('%s', '%s')" % (username, password))
- con.commit()
- con.close()
+ try:
+ u = models.User()
+ u.id = username
+ u.email = username
+ u.password = password
+ u.enabled = True
+ api.user_create(u)
+ print 'user', u.id, 'created.'
+ return
+ except Exception, e:
+ raise #e, ('User %s already exists' % username)
+
if __name__ == '__main__':
main()
|
