da49bfc74233a4311b4e1625945426bd30436c45
[csit.git] / resources / tools / trex / trex_server_info.py
1 #!/usr/bin/python
2
3 # Copyright (c) 2019 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 """This script uses T-REX stateless API to drive t-rex instance.
17
18 Requirements:
19 - T-REX: https://github.com/cisco-system-traffic-generator/trex-core
20  - compiled and running T-REX process (eg. ./t-rex-64 -i)
21  - trex.stl.api library
22 - Script must be executed on a node with T-REX instance
23
24 Functionality:
25 1. Verify the API functionality and get server information
26
27 """
28
29 import sys
30
31 sys.path.insert(0, "/opt/trex-core-2.54/scripts/automation/"+\
32                    "trex_control_plane/interactive/")
33 from trex.stl.api import *
34
35 def get_server_system_info():
36     """Check server info and quit.
37
38     :return: nothing
39     """
40     # create client
41     client = STLClient()
42
43     try:
44         # connect to server
45         client.connect()
46         # get server info
47         print(client.get_server_system_info())
48     except STLError as ex_error:
49         sys.stderr.write(str(ex_error))
50         sys.exit(1)
51     finally:
52         client.disconnect()
53
54
55 def main():
56     """Main function."""
57     get_server_system_info()
58
59
60 if __name__ == "__main__":
61     main()