Files
microstack/tools/init/init/main.py
Pete Vander Giessen c3ba4ee501 Delay creating external bridge until we are initializing
Previously, the snap set up a bridge using the default 10.20.20.0/24
network upon install. If there was a good reason not to use this
network (e.g., it already exists and is being used for another
purpose), MicroStack, and the host machine, could wind up in a broken
state.

This PR delays setting up the bridge until after we have given an
operator a chance to override the default settings.

This has been manually tested. To test, do the following:

1) Checkout the code, and run tox -e build
2) Run tools/make-a-microstack.sh
3) snapctl set config.network.ext-cidr and config.network.ext-gateway
4) Run microstack_init
5) Exit the snap shell and run microstack.launch

Change-Id: I9e268495f313b29d9781d80a2468fc0a1a450aa0
Closes-Bug: https://bugs.launchpad.net/microstack/+bug/1851521
2019-11-12 23:19:51 +00:00

130 lines
3.9 KiB
Python

"""Microstack Init
Initialize the databases and configuration files of a microstack
install.
We structure our init in the form of 'Question' classes, each of which
has an 'ask' routine, run in the order laid out in the
question_classes in the main function in this file.
.ask will either ask the user a question, and run the appropriate
routine in the Question class, or simply automatically run a routine
without input from the user (in the case of 'required' questions).
----------------------------------------------------------------------
Copyright 2019 Canonical Ltd
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 logging
import secrets
import string
import sys
from init.config import log
from init.shell import check
from init import questions
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--auto', '-a', action='store_true',
help='Run non interactively.')
parser.add_argument('--cluster-password')
parser.add_argument('--compute', action='store_true')
parser.add_argument('--control', action='store_true')
parser.add_argument('--debug', action='store_true')
args = parser.parse_args()
return args
def process_args(args):
"""Look through our args object and set the proper default config
values in our snap config, based on those args.
"""
auto = args.auto or args.control or args.compute
if args.compute or args.control:
check('snapctl', 'set', 'config.clustered=true')
if args.compute:
check('snapctl', 'set', 'config.cluster.role=compute')
if args.control:
# If both compute and control are passed for some reason, we
# wind up with the role of 'control', which is best, as a
# control node also serves as a compute node in our hyper
# converged architecture.
check('snapctl', 'set', 'config.cluster.role=control')
if args.cluster_password:
check('snapctl', 'set', 'config.cluster.password={}'.format(
args.cluster_password))
if auto and not args.cluster_password:
alphabet = string.ascii_letters + string.digits
password = ''.join(secrets.choice(alphabet) for i in range(10))
check('snapctl', 'set', 'config.cluster.password={}'.format(password))
if args.debug:
log.setLevel(logging.DEBUG)
return auto
def main() -> None:
args = parse_args()
auto = process_args(args)
question_list = [
questions.Clustering(),
questions.Dns(),
questions.NetworkSettings(),
questions.OsPassword(), # TODO: turn this off if COMPUTE.
questions.ForceQemu(),
# The following are not yet implemented:
# questions.VmSwappiness(),
# questions.FileHandleLimits(),
questions.DashboardAccess(),
questions.RabbitMq(),
questions.DatabaseSetup(),
questions.NovaHypervisor(),
questions.NovaControlPlane(),
questions.NeutronControlPlane(),
questions.GlanceSetup(),
questions.KeyPair(),
questions.SecurityRules(),
questions.PostSetup(),
]
for question in question_list:
if auto:
# Force all questions to be non-interactive if we passed --auto.
question.interactive = False
try:
question.ask()
except questions.ConfigError as e:
log.critical(e)
sys.exit(1)
if __name__ == '__main__':
main()