command_sets.py 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Copyright (C) 2012 Internet Systems Consortium.
  2. #
  3. # Permission to use, copy, modify, and distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
  8. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  9. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  10. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  12. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  14. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. # This file provides a built-in set of 'execute' commands, for common
  16. # functions, such as adding an initial auth server.
  17. # By calling the function prepare_execute_commands, the
  18. # commands in the command_sets map are added to the virtual
  19. # component called 'execute'. This is done in bindctl_main.
  20. from bindctl.moduleinfo import *
  21. # The name of the 'virtual' command set execution module in bindctl
  22. EXECUTE_MODULE_NAME = 'execute'
  23. # This is a map of command names to lists
  24. # Each element in the set should itself be a dict containing:
  25. # 'description': A string with a description of the command set
  26. # 'commands': A list of bindctl commands
  27. command_sets = {
  28. 'init_authoritative_server': {
  29. 'description':
  30. 'Configure and run a basic Authoritative server, with default '+
  31. 'SQLite3 backend, and xfrin and xfrout functionality',
  32. 'commands':
  33. [
  34. '!echo adding Authoritative server component',
  35. 'config add /Boss/components b10-auth',
  36. 'config set /Boss/components/b10-auth/kind needed',
  37. 'config set /Boss/components/b10-auth/special auth',
  38. '!echo adding Xfrin component',
  39. 'config add /Boss/components b10-xfrin',
  40. 'config set /Boss/components/b10-xfrin/address Xfrin',
  41. 'config set /Boss/components/b10-xfrin/kind dispensable',
  42. '!echo adding Xfrout component',
  43. 'config add /Boss/components b10-xfrout',
  44. 'config set /Boss/components/b10-xfrout/address Xfrout',
  45. 'config set /Boss/components/b10-xfrout/kind dispensable',
  46. '!echo adding Zone Manager component',
  47. 'config add /Boss/components b10-zonemgr',
  48. 'config set /Boss/components/b10-zonemgr/address Zonemgr',
  49. 'config set /Boss/components/b10-zonemgr/kind dispensable',
  50. '!echo Components added. Please enter "config commit" to',
  51. '!echo finalize initial setup and run the components.'
  52. ]
  53. }
  54. }
  55. def has_command_set(name):
  56. return name in command_sets
  57. def get_commands(name):
  58. return command_sets[name]['commands']
  59. def get_description(name):
  60. return command_sets[name]['description']
  61. # For each
  62. def prepare_execute_commands(tool):
  63. """This function is called by bindctl_main, and sets up the commands
  64. defined here for use in bindctl."""
  65. # common parameter
  66. param_show = ParamInfo(name="show", type="string", optional=True,
  67. desc="Show the list of commands without executing them")
  68. # The command module
  69. module = ModuleInfo(name=EXECUTE_MODULE_NAME,
  70. desc="Execute a given set of commands")
  71. # Command to execute a file
  72. cmd = CommandInfo(name="file", desc="Read commands from file")
  73. param = ParamInfo(name="filename", type="string", optional=False,
  74. desc="File to read the set of commands from.")
  75. cmd.add_param(param)
  76. cmd.add_param(param_show)
  77. module.add_command(cmd)
  78. # and loop through all command sets defined above
  79. for name in command_sets:
  80. cmd = CommandInfo(name=name, desc=get_description(name))
  81. cmd.add_param(param_show)
  82. module.add_command(cmd)
  83. tool.add_module_info(module)