python utility to manage a tripleo based cloud
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.

overcloud_parameters.py 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  2. # not use this file except in compliance with the License. You may obtain
  3. # a copy of the License at
  4. #
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. #
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  10. # License for the specific language governing permissions and limitations
  11. # under the License.
  12. import argparse
  13. import logging
  14. import simplejson
  15. import yaml
  16. from osc_lib.i18n import _
  17. from tripleoclient import command
  18. from tripleoclient import exceptions
  19. from tripleoclient import utils
  20. from tripleoclient.workflows import parameters
  21. class SetParameters(command.Command):
  22. """Set a parameters for a plan"""
  23. log = logging.getLogger(__name__ + ".CreatePlan")
  24. def get_parser(self, prog_name):
  25. parser = super(SetParameters, self).get_parser(prog_name)
  26. parser.add_argument(
  27. 'name',
  28. help=_('The name of the plan, which is used for the Swift '
  29. 'container, Mistral environment and Heat stack names.'))
  30. parser.add_argument('file_in', type=argparse.FileType('r'))
  31. return parser
  32. def take_action(self, parsed_args):
  33. self.log.debug("take_action(%s)" % parsed_args)
  34. if parsed_args.file_in.name.endswith('.json'):
  35. params = simplejson.load(parsed_args.file_in)
  36. elif parsed_args.file_in.name.endswith('.yaml'):
  37. params = yaml.safe_load(parsed_args.file_in)
  38. else:
  39. raise exceptions.InvalidConfiguration(
  40. _("Invalid file extension for %s, must be json or yaml") %
  41. parsed_args.file_in.name)
  42. if 'parameter_defaults' in params:
  43. params = params['parameter_defaults']
  44. clients = self.app.client_manager
  45. workflow_client = clients.workflow_engine
  46. name = parsed_args.name
  47. parameters.update_parameters(
  48. workflow_client,
  49. container=name,
  50. parameters=params
  51. )
  52. class GenerateFencingParameters(command.Command):
  53. """Generate fencing parameters"""
  54. log = logging.getLogger(__name__ + ".GenerateFencing")
  55. def get_parser(self, prog_name):
  56. parser = super(GenerateFencingParameters, self).get_parser(prog_name)
  57. parser.add_argument('-a', '--action', dest='fence_action',
  58. help=_('DEPRECATED: This option is ignored.'))
  59. parser.add_argument('--delay', type=int,
  60. help=_('Wait DELAY seconds before fencing is '
  61. 'started'))
  62. parser.add_argument('--ipmi-lanplus',
  63. dest='ipmi_lanplus',
  64. default=True,
  65. action='store_true',
  66. help=_('DEPRECATED: This is the default.'))
  67. parser.add_argument('--ipmi-no-lanplus',
  68. dest='ipmi_lanplus',
  69. action='store_false',
  70. help=_('Do not use Lanplus. Defaults to: false'))
  71. parser.add_argument('--ipmi-cipher', type=int,
  72. help=_('Ciphersuite to use (same as ipmitool -C '
  73. 'parameter.'))
  74. parser.add_argument('--ipmi-level',
  75. help=_('Privilegel level on IPMI device. Valid '
  76. 'levels: callback, user, operator, '
  77. 'administrator.'))
  78. parser.add_argument('--output', type=argparse.FileType('w'),
  79. help=_('Write parameters to a file'))
  80. parser.add_argument('instackenv', type=argparse.FileType('r'))
  81. return parser
  82. def take_action(self, parsed_args):
  83. nodes_config = utils.parse_env_file(parsed_args.instackenv)
  84. workflow_input = {
  85. 'nodes_json': nodes_config,
  86. 'delay': parsed_args.delay,
  87. 'ipmi_level': parsed_args.ipmi_level,
  88. 'ipmi_cipher': parsed_args.ipmi_cipher,
  89. 'ipmi_lanplus': parsed_args.ipmi_lanplus,
  90. }
  91. result = parameters.generate_fencing_parameters(
  92. self.app.client_manager, **workflow_input)
  93. fencing_parameters = yaml.safe_dump(result, default_flow_style=False)
  94. if parsed_args.output:
  95. parsed_args.output.write(fencing_parameters)
  96. else:
  97. print(fencing_parameters)