Dennis Dmitriev | e56c8b9 | 2017-06-16 01:53:16 +0300 | [diff] [blame] | 1 | # 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 | |
| 15 | from __future__ import print_function |
| 16 | |
| 17 | import argparse |
| 18 | import os |
| 19 | import sys |
| 20 | import yaml |
| 21 | |
| 22 | from reclass_tools import walk_models |
| 23 | |
| 24 | |
| 25 | def execute(params): |
| 26 | |
| 27 | results = walk_models.get_all_reclass_params( |
| 28 | params.paths, |
| 29 | identity_files=params.identity_files, |
| 30 | verbose=params.verbose) |
| 31 | |
| 32 | print(yaml.dump(results)) |
| 33 | |
| 34 | |
| 35 | def dump_params(args=None): |
| 36 | if args is None: |
| 37 | args = sys.argv[1:] |
| 38 | |
| 39 | parser = argparse.ArgumentParser( |
| 40 | formatter_class=argparse.RawTextHelpFormatter, |
| 41 | description="") |
| 42 | parser.add_argument('-i', dest='identity_files', |
| 43 | help=('For SSH connections, selects a file from which \n' |
| 44 | 'the identity (private key) for public key \n' |
| 45 | 'authentication is read. It is possible to have \n' |
| 46 | 'multiple -i options.'), |
| 47 | action='append') |
| 48 | parser.add_argument('--verbose', dest='verbose', action='store_const', const=True, |
| 49 | help='Show verbosed output.', default=False) |
| 50 | parser.add_argument('paths', help='Paths to search for *.yml files.', nargs='+') |
| 51 | |
| 52 | if len(args) == 0: |
| 53 | args = ['-h'] |
| 54 | |
| 55 | params = parser.parse_args(args) |
Dennis Dmitriev | 672bd44 | 2017-06-16 18:13:54 +0300 | [diff] [blame^] | 56 | results = walk_models.get_all_reclass_params( |
| 57 | params.paths, |
| 58 | identity_files=params.identity_files, |
| 59 | verbose=params.verbose) |
| 60 | |
| 61 | print(yaml.dump(results)) |
| 62 | |
| 63 | |
| 64 | def remove_key(args=None): |
| 65 | if args is None: |
| 66 | args = sys.argv[1:] |
| 67 | |
| 68 | parser = argparse.ArgumentParser( |
| 69 | formatter_class=argparse.RawTextHelpFormatter, |
| 70 | description="") |
| 71 | parser.add_argument('-i', dest='identity_files', |
| 72 | help=('For SSH connections, selects a file from which \n' |
| 73 | 'the identity (private key) for public key \n' |
| 74 | 'authentication is read. It is possible to have \n' |
| 75 | 'multiple -i options.'), |
| 76 | action='append') |
| 77 | parser.add_argument('--verbose', dest='verbose', action='store_const', const=True, |
| 78 | help='Show verbosed output.', default=False) |
| 79 | parser.add_argument('paths', help='Paths to search for *.yml files.', nargs='+') |
| 80 | parser.add_argument('--remove-key', '-r', dest='key', |
| 81 | help=('Remove key from reclass model, for example:' |
| 82 | ' reclass-remove-key -r parameters.linux.network.interface /path/to/model/')) |
| 83 | if len(args) == 0: |
| 84 | args = ['-h'] |
| 85 | |
| 86 | params = parser.parse_args(args) |
| 87 | results = walk_models.remove_reclass_parameter( |
| 88 | params.paths, |
| 89 | params.key, |
| 90 | identity_files=params.identity_files, |
| 91 | verbose=params.verbose) |