From 30ffd5bf316c13129e5eec005fdb50aae5a6c565 Mon Sep 17 00:00:00 2001 From: Steve Kowalik Date: Thu, 1 May 2014 15:55:18 +1000 Subject: [PATCH] Add an init-keystone CLI To allow devtest to leverage the keystone initialization in this module, add a CLI script called init-keystone. Change-Id: I733fb1319b81ebc69845b08bd8ed9a933fa5d245 --- doc/source/usage.rst | 17 +++++++- os_cloud_config/cmd/__init__.py | 0 os_cloud_config/cmd/init_keystone.py | 58 ++++++++++++++++++++++++++++ requirements.txt | 1 + setup.cfg | 6 ++- 5 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 os_cloud_config/cmd/__init__.py create mode 100644 os_cloud_config/cmd/init_keystone.py diff --git a/doc/source/usage.rst b/doc/source/usage.rst index ac76049..54a2b3d 100644 --- a/doc/source/usage.rst +++ b/doc/source/usage.rst @@ -4,4 +4,19 @@ Usage To use os-cloud-config in a project:: - import os_cloud_config \ No newline at end of file + import os_cloud_config + +Initializing Keystone for a host:: + +The init-keystone command line utility initializes Keystone for use with +normal authentication by creating the admin and service tenants, the admin +and Member roles, the admin user, configure certificates and finally +registers the initial identity endpoint. + +For example:: + + init-keystone -o 192.0.2.1 -t unset -e admin@example.com -p unset -u root + +That acts on the 192.0.2.1 host, sets the admin token and the admin password +to the string "unset", the admin e-mail address to "admin@example.com", and +uses the root user to connect to the host via ssh to configure certificates. diff --git a/os_cloud_config/cmd/__init__.py b/os_cloud_config/cmd/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/os_cloud_config/cmd/init_keystone.py b/os_cloud_config/cmd/init_keystone.py new file mode 100644 index 0000000..fe5833c --- /dev/null +++ b/os_cloud_config/cmd/init_keystone.py @@ -0,0 +1,58 @@ +# Copyright (c) 2014 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import textwrap + +from os_cloud_config.keystone import initialize + + +def parse_args(): + description = textwrap.dedent(""" + Perform initial setup of keystone for a new cloud. + + This will create the admin and service tenants, the admin and Member + roles, the admin user, configure certificates and finally register the + initial identity endpoint, after which Keystone may be used with normal + authentication. + """) + parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, + description=description) + parser.add_argument('-o', '--host', dest='host', required=True, + help="ip/hostname of node where Keystone is running") + parser.add_argument('-t', '--admin-token', dest='admin_token', + help="admin token to use with Keystone's admin " + "endpoint", required=True) + parser.add_argument('-e', '--admin-email', dest='admin_email', + help="admin user's e-mail address to be set", + required=True) + parser.add_argument('-p', '--admin-password', dest='admin_password', + help="admin user's password to be set", + required=True) + parser.add_argument('-r', '--region', dest='region', default='regionOne', + help="region to create the endpoint in") + parser.add_argument('-s', '--ssl', dest='ssl', + help="ip/hostname to use as the ssl endpoint, if " + "required") + parser.add_argument('-u', '--user', dest='user', required=True, + help="user to connect to the Keystone node via ssh") + return parser.parse_args() + + +def main(): + args = parse_args() + initialize(args.host, args.admin_token, args.admin_email, + args.admin_password, args.region, args.ssl, args.user) diff --git a/requirements.txt b/requirements.txt index feb6427..84aa107 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ pbr>=0.6,<1.0 +argparse Babel>=1.3 python-keystoneclient>=0.6.0 oslo.config>=1.2.0 diff --git a/setup.cfg b/setup.cfg index badbb44..2f68404 100644 --- a/setup.cfg +++ b/setup.cfg @@ -23,6 +23,10 @@ classifier = packages = os_cloud_config +[entry_points] +console_scripts = + init-keystone = os_cloud_config.cmd.init_keystone:main + [build_sphinx] source-dir = doc/source build-dir = doc/build @@ -43,4 +47,4 @@ input_file = os_cloud_config/locale/os-cloud-config.pot [extract_messages] keywords = _ gettext ngettext l_ lazy_gettext mapping_file = babel.cfg -output_file = os_cloud_config/locale/os-cloud-config.pot \ No newline at end of file +output_file = os_cloud_config/locale/os-cloud-config.pot