X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=ta%2Fhw-detector.git;a=blobdiff_plain;f=src%2Fhw_detector%2Fhw_detect_cli.py;fp=src%2Fhw_detector%2Fhw_detect_cli.py;h=7a4e8b16bc9c0900dbc1fdfe7e7c722e4d6440ff;hp=0000000000000000000000000000000000000000;hb=16a99da97d1b95a14514ab8e7c0f75e43ba8c184;hpb=d772f6a70748051542c72cbcd9098f40a258cc2d diff --git a/src/hw_detector/hw_detect_cli.py b/src/hw_detector/hw_detect_cli.py new file mode 100644 index 0000000..7a4e8b1 --- /dev/null +++ b/src/hw_detector/hw_detect_cli.py @@ -0,0 +1,57 @@ +#!/usr/bin/python + +# Copyright 2019 Nokia + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import argparse +import pprint +import hw_detector.hw_detect_lib as hw +from hw_detector.hw_exception import HWException + +def dump_data(data): + pp = pprint.PrettyPrinter(indent=4) + pp.pprint(data) + +def local_dump(args): + data = hw.get_local_hw_data() + dump_data(data) + +def remote_dump(args): + ip = args.ip + user = args.user + passw = args.passwd + try: + data = hw.get_hw_data(ip, user, passw, False) + except HWException as e: + data = "Detect failed: {}".format(str(e)) + dump_data(data) + +def main(): + parser = argparse.ArgumentParser(description='HW detector cli') + subparsers = parser.add_subparsers() + local_group = subparsers.add_parser('local') + remote_group = subparsers.add_parser('remote') + + remote_group.add_argument('--ip', type=str, required=True, help='IP') + remote_group.add_argument('--user', type=str, required=True, help='User') + remote_group.add_argument('--passwd', type=str, required=True, help='Password') + + local_group.set_defaults(func=local_dump) + remote_group.set_defaults(func=remote_dump) + + args = parser.parse_args(sys.argv[1:]) + args.func(args) +if __name__ == '__main__': + main()