OpenStack in a snap!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

95 lines
3.1 KiB

  1. """Microstack Init
  2. Initialize the databases and configuration files of a microstack
  3. install.
  4. We structure our init in the form of 'Question' classes, each of which
  5. has an 'ask' routine, run in the order laid out in the
  6. question_classes in the main function in this file.
  7. .ask will either ask the user a question, and run the appropriate
  8. routine in the Question class, or simply automatically run a routine
  9. without input from the user (in the case of 'required' questions).
  10. ----------------------------------------------------------------------
  11. Copyright 2019 Canonical Ltd
  12. Licensed under the Apache License, Version 2.0 (the "License");
  13. you may not use this file except in compliance with the License.
  14. You may obtain a copy of the License at
  15. http://www.apache.org/licenses/LICENSE-2.0
  16. Unless required by applicable law or agreed to in writing, software
  17. distributed under the License is distributed on an "AS IS" BASIS,
  18. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. See the License for the specific language governing permissions and
  20. limitations under the License.
  21. """
  22. import sys
  23. from init.config import log
  24. from init import questions
  25. from init.shell import check
  26. # Figure out whether to prompt for user input, and which type of node
  27. # we're running.
  28. # TODO drop in argparse and formalize this.
  29. COMPUTE = '--compute' in sys.argv
  30. CONTROL = '--control' in sys.argv
  31. AUTO = ('--auto' in sys.argv) or COMPUTE or CONTROL
  32. def main() -> None:
  33. question_list = [
  34. questions.Dns(),
  35. questions.ExtGateway(),
  36. questions.ExtCidr(),
  37. questions.OsPassword(), # TODO: turn this off if COMPUTE.
  38. questions.IpForwarding(),
  39. questions.ForceQemu(),
  40. # The following are not yet implemented:
  41. # questions.VmSwappiness(),
  42. # questions.FileHandleLimits(),
  43. questions.RabbitMq(),
  44. questions.DatabaseSetup(),
  45. questions.NovaSetup(),
  46. questions.NeutronSetup(),
  47. questions.GlanceSetup(),
  48. questions.PostSetup(),
  49. ]
  50. # If we are setting up a "control" or "compute" node, override
  51. # some of the default yes/no questions.
  52. # TODO: move this into a nice little yaml parsing lib, and
  53. # allow people to pass in a config file from the command line.
  54. if CONTROL:
  55. check('snapctl', 'set', 'questions.nova-setup=false')
  56. if COMPUTE:
  57. check('snapctl', 'set', 'questions.rabbit-mq=false')
  58. check('snapctl', 'set', 'questions.database-setup=false')
  59. check('snapctl', 'set', 'questions.neutron-setup=false')
  60. check('snapctl', 'set', 'questions.glance-setup=false')
  61. for question in question_list:
  62. if AUTO:
  63. # If we are automatically answering questions, replace the
  64. # prompt for user input with a function that returns None,
  65. # causing the question to fall back to the already set
  66. # default
  67. question._input_func = lambda prompt: None
  68. try:
  69. question.ask()
  70. except questions.ConfigError as e:
  71. log.critical(e)
  72. sys.exit(1)
  73. if __name__ == '__main__':
  74. main()