Merge "Change all references of nsx_v3 to nsx." into stable/pike
[apex-tripleo-heat-templates.git] / tools / roles-data-generate.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Red Hat, Inc.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
15 # under the License.
16 #
17
18 import argparse
19 import collections
20 import os
21 import sys
22
23 from tripleo_common.utils import roles as rolesutils
24
25 __tht_root_dir = os.path.dirname(os.path.dirname(__file__))
26 __tht_roles_dir = os.path.join(__tht_root_dir, 'roles')
27
28
29 def parse_opts(argv):
30     parser = argparse.ArgumentParser(
31         description='Generate roles_data.yaml for requested roles. NOTE: '
32                     'This is a stripped down version of what is provided by '
33                     'the tripleoclient. The tripleoclient should be used for '
34                     'additional functionality.')
35     parser.add_argument('--roles-path', metavar='<roles directory>',
36                         help="Filesystem path containing the roles yaml files",
37                         default=__tht_roles_dir)
38     parser.add_argument('roles', nargs="+", metavar='<role>',
39                         help='List of roles to use to generate the '
40                              'roles_data.yaml file')
41     opts = parser.parse_args(argv[1:])
42
43     return opts
44
45 opts = parse_opts(sys.argv)
46
47 roles = collections.OrderedDict.fromkeys(opts.roles)
48 print(rolesutils.generate_roles_data_from_directory(opts.roles_path,
49                                                     roles.keys()))