Add hardware type for Ampere Hawk server
[ta/hw-detector.git] / src / hw_detector / hw_detect_cli.py
1 #!/usr/bin/python
2
3 # Copyright 2019 Nokia
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain 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,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 import sys
18 import argparse
19 import pprint
20 import hw_detector.hw_detect_lib as hw
21 from hw_detector.hw_exception import HWException
22
23 def dump_data(data):
24     pp = pprint.PrettyPrinter(indent=4)
25     pp.pprint(data)
26
27 def local_dump(args):
28     data = hw.get_local_hw_data()
29     dump_data(data)
30
31 def remote_dump(args):
32     ip = args.ip
33     user = args.user
34     passw = args.passwd
35     priv = args.priv
36     try:
37         data = hw.get_hw_data(ip, user, passw, priv, False)
38     except HWException as e:
39         data = "Detect failed: {}".format(str(e))
40     dump_data(data)
41
42 def main():
43     parser = argparse.ArgumentParser(description='HW detector cli')
44     subparsers = parser.add_subparsers()
45     local_group = subparsers.add_parser('local')
46     remote_group = subparsers.add_parser('remote')
47
48     remote_group.add_argument('--ip', type=str, required=True, help='IP')
49     remote_group.add_argument('--user', type=str, required=True, help='User')
50     remote_group.add_argument('--passwd', type=str, required=True, help='Password')
51     remote_group.add_argument('--priv', type=str, required=False, default='ADMINISTRATOR', help='Privilege level (default: ADMINISTRATOR)')
52     local_group.set_defaults(func=local_dump)
53     remote_group.set_defaults(func=remote_dump)
54
55     args = parser.parse_args(sys.argv[1:])
56     args.func(args)
57 if __name__ == '__main__':
58     main()