blob: 48e3d9f66bb52ebf87e6ce51095ed34121a673f8 [file] [log] [blame]
Dennis Dmitrieve56c8b92017-06-16 01:53:16 +03001# Copyright 2013 - 2016 Mirantis, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15from __future__ import print_function
16
17import argparse
18import os
19import sys
20import yaml
21
22from reclass_tools import walk_models
23
24
25def execute(params):
26
27 results = walk_models.get_all_reclass_params(
28 params.paths,
Dennis Dmitrieve56c8b92017-06-16 01:53:16 +030029 verbose=params.verbose)
30
31 print(yaml.dump(results))
32
33
34def dump_params(args=None):
35 if args is None:
36 args = sys.argv[1:]
37
38 parser = argparse.ArgumentParser(
39 formatter_class=argparse.RawTextHelpFormatter,
40 description="")
Dennis Dmitrieve56c8b92017-06-16 01:53:16 +030041 parser.add_argument('--verbose', dest='verbose', action='store_const', const=True,
42 help='Show verbosed output.', default=False)
43 parser.add_argument('paths', help='Paths to search for *.yml files.', nargs='+')
44
45 if len(args) == 0:
46 args = ['-h']
47
48 params = parser.parse_args(args)
Dennis Dmitriev672bd442017-06-16 18:13:54 +030049 results = walk_models.get_all_reclass_params(
50 params.paths,
Dennis Dmitriev672bd442017-06-16 18:13:54 +030051 verbose=params.verbose)
52
53 print(yaml.dump(results))
54
55
Dennis Dmitriev6bd44252017-06-22 17:33:40 +030056def show_key(args=None):
57 remove_key(args=args, pretend=True)
58
59
60def remove_key(args=None, pretend=False):
Dennis Dmitriev672bd442017-06-16 18:13:54 +030061 if args is None:
62 args = sys.argv[1:]
63
Dennis Dmitriev6bd44252017-06-22 17:33:40 +030064 key_parser = argparse.ArgumentParser(add_help=False)
65 if pretend:
66 key_parser_help = (
67 'Key name to find in reclass model files, for example:'
68 ' reclass-show-key parameters.linux.network.interface'
69 ' /path/to/model/')
70 else:
71 key_parser_help = (
72 'Key name to remove from reclass model files, for example:'
73 ' reclass-remove-key parameters.linux.network.interface'
74 ' /path/to/model/')
75 key_parser.add_argument('key_name', help=key_parser_help)
76
77 parser = argparse.ArgumentParser(parents=[key_parser],
Dennis Dmitriev672bd442017-06-16 18:13:54 +030078 formatter_class=argparse.RawTextHelpFormatter,
79 description="")
Dennis Dmitriev672bd442017-06-16 18:13:54 +030080 parser.add_argument('--verbose', dest='verbose', action='store_const', const=True,
81 help='Show verbosed output.', default=False)
82 parser.add_argument('paths', help='Paths to search for *.yml files.', nargs='+')
Dennis Dmitriev6bd44252017-06-22 17:33:40 +030083
Dennis Dmitriev672bd442017-06-16 18:13:54 +030084 if len(args) == 0:
85 args = ['-h']
86
87 params = parser.parse_args(args)
88 results = walk_models.remove_reclass_parameter(
89 params.paths,
Dennis Dmitriev6bd44252017-06-22 17:33:40 +030090 params.key_name,
91 verbose=params.verbose,
92 pretend=pretend)
Dennis Dmitriev1110ac52017-06-22 21:07:37 +030093
Dennis Dmitrievde847d92017-06-26 18:58:05 +030094
Dennis Dmitriev1110ac52017-06-22 21:07:37 +030095def inventory_list(args=None):
96 try:
97 from reclass_tools import reclass_models
98 except ImportError:
99 print("Please run this tool on the salt-master node with installed 'reclass'")
100 return
101
102 parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter,
103 description="")
Dennis Dmitriev94239b12017-06-23 13:18:38 +0300104 parser.add_argument('--domain', '-d', dest='domain',
105 help=('Show only the nodes which names are ended with the specified domain, for example:'
106 ' reclass-inventory-list -d example.local'))
Dennis Dmitriev1110ac52017-06-22 21:07:37 +0300107
108 params = parser.parse_args(args)
109
Dennis Dmitrievde847d92017-06-26 18:58:05 +0300110 inventory = reclass_models.inventory_list(domain=params.domain)
111
112 print('\n'.join(sorted(inventory.keys())))
113
114def vcp_list(args=None):
115 try:
116 from reclass_tools import reclass_models
117 except ImportError:
118 print("Please run this tool on the salt-master node with installed 'reclass'")
119 return
120
121 parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter,
122 description="")
123 parser.add_argument('--domain', '-d', dest='domain',
124 help=('Show only the nodes which names are ended with the specified domain, for example:'
125 ' reclass-inventory-list -d example.local'))
126
127 params = parser.parse_args(args)
128
129 vcp_node_names = reclass_models.vcp_list(domain=params.domain)
130 print('\n'.join(sorted(vcp_node_names)))
131