From db0231584905cbcc37ee08ad8e7ea951661bc948 Mon Sep 17 00:00:00 2001 From: Dolph Mathews Date: Wed, 10 Oct 2012 22:09:11 +0000 Subject: [PATCH] bootstrap a keystone user (e.g. admin) in one cmd Change-Id: I67ec8cad0f1893113f8041d8bffb9a078a8b9bbe --- keystoneclient/contrib/__init__.py | 0 keystoneclient/contrib/bootstrap/__init__.py | 0 keystoneclient/contrib/bootstrap/shell.py | 28 ++++++++++++++++++++ keystoneclient/shell.py | 2 ++ 4 files changed, 30 insertions(+) create mode 100644 keystoneclient/contrib/__init__.py create mode 100644 keystoneclient/contrib/bootstrap/__init__.py create mode 100644 keystoneclient/contrib/bootstrap/shell.py diff --git a/keystoneclient/contrib/__init__.py b/keystoneclient/contrib/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/keystoneclient/contrib/bootstrap/__init__.py b/keystoneclient/contrib/bootstrap/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/keystoneclient/contrib/bootstrap/shell.py b/keystoneclient/contrib/bootstrap/shell.py new file mode 100644 index 00000000..e6bdc514 --- /dev/null +++ b/keystoneclient/contrib/bootstrap/shell.py @@ -0,0 +1,28 @@ +from keystoneclient import utils +from keystoneclient.v2_0 import client + + +@utils.arg('--user-name', metavar='', default='admin', dest='user', + help='The name of the user to be created (default="admin").') +@utils.arg('--pass', metavar='', required=True, dest='passwd', + help='The password for the new user.') +@utils.arg('--role-name', metavar='', default='admin', dest='role', + help='The name of the role to be created and granted to the user ' + '(default="admin").') +@utils.arg('--tenant-name', metavar='', default='admin', + dest='tenant', + help='The name of the tenant to be created (default="admin").') +def do_bootstrap(kc, args): + """Grants a new role to a new user on a new tenant, after creating each.""" + tenant = kc.tenants.create(tenant_name=args.tenant) + role = kc.roles.create(name=args.role) + user = kc.users.create(name=args.user, password=args.passwd, email=None) + kc.roles.add_user_role(user=user, role=role, tenant=tenant) + + # verify the result + user_client = client.Client( + username=args.user, + password=args.passwd, + tenant_name=args.tenant, + auth_url=kc.management_url) + user_client.authenticate() diff --git a/keystoneclient/shell.py b/keystoneclient/shell.py index 64d2d2b7..126e0829 100644 --- a/keystoneclient/shell.py +++ b/keystoneclient/shell.py @@ -28,6 +28,7 @@ from keystoneclient import exceptions as exc from keystoneclient import utils from keystoneclient.v2_0 import shell as shell_v2_0 from keystoneclient.generic import shell as shell_generic +from keystoneclient.contrib.bootstrap import shell as shell_bootstrap def env(*vars, **kwargs): @@ -190,6 +191,7 @@ class OpenStackIdentityShell(object): self._find_actions(subparsers, actions_module) self._find_actions(subparsers, shell_generic) + self._find_actions(subparsers, shell_bootstrap) self._find_actions(subparsers, self) self._add_bash_completion_subparser(subparsers)