|
1 | | -# bps_restpy |
| 1 | +## The IxNetwork Python Client |
| 2 | +[](https://pypi.org/project/breakingpoint-restpy) |
| 3 | +[](https://pypi.python.org/pypi/breakingpoint-restpy) |
| 4 | +[](https://en.wikipedia.org/wiki/MIT_License) |
| 5 | +[](https://pepy.tech/project/breakingpoint-restpy) |
| 6 | + |
| 7 | +## Install the package |
| 8 | +``` |
| 9 | +pip install --upgrade breakingpoint-restpy |
| 10 | +``` |
| 11 | + |
| 12 | +## Start scripting |
| 13 | +```python |
| 14 | +"""This script demonstrates how to get started with bps_restpy scripting. |
| 15 | +
|
| 16 | +# Title: Python Script Sample To Run a Canned Test. |
| 17 | +# Actions: |
| 18 | +# 1. Login to BPS box |
| 19 | +# 2. Reserve ports |
| 20 | +# 3. Load a test from the box and start the run |
| 21 | +# 4. Wait for the test to finish |
| 22 | +# 5. Get test result |
| 23 | +# 6. Get and print the Synopsis page from report |
| 24 | +# 7. Unreserve ports |
| 25 | +# 8. Logout |
| 26 | +
|
| 27 | +
|
| 28 | +#================ |
| 29 | +
|
| 30 | +######################################## |
| 31 | +import time, sys, os |
| 32 | +# Import corresponding BPS RESTv2 python2.7/ 3 library from outside the folder with samples. |
| 33 | +sys.path.insert(1, os.path.dirname(os.getcwd())) |
| 34 | +if sys.version_info[0] >= 3: |
| 35 | + from bps_restpy.bps_restpy import BPS, pp |
| 36 | +else: |
| 37 | + from bps_restpy.bps_restpy3 import BPS, pp |
| 38 | +
|
| 39 | +######################################## |
| 40 | +
|
| 41 | +
|
| 42 | +######################################## |
| 43 | +# Demo script global variables |
| 44 | +######################################## |
| 45 | +# Demo script global variables |
| 46 | +canned_test_name = 'AppSim' |
| 47 | +#bps system info |
| 48 | +bps_system = '<BPS_BOX_IP/HOSTNAME>' |
| 49 | +bpsuser = 'bps user' |
| 50 | +bpspass = 'bps pass' |
| 51 | +
|
| 52 | +
|
| 53 | +slot_number = 2 |
| 54 | +port_list = [0, 1] |
| 55 | +
|
| 56 | +######################################## |
| 57 | +
|
| 58 | +
|
| 59 | +######################################## |
| 60 | +# Login to BPS box |
| 61 | +bps = BPS(bps_system, bpsuser, bpspass) |
| 62 | +bps.login() |
| 63 | +
|
| 64 | +
|
| 65 | +######################################## |
| 66 | +print("Load a canned test: ") |
| 67 | +bps.testmodel.load(canned_test_name) |
| 68 | +
|
| 69 | +######################################## |
| 70 | +print("Reserve Ports") |
| 71 | +for p in port_list: |
| 72 | + bps.topology.reserve([{'slot': slot_number, 'port': p, 'group': 2}]) |
| 73 | +
|
| 74 | +
|
| 75 | +######################################## |
| 76 | +print("Run test and Get Stats:") |
| 77 | +test_id_json = bps.testmodel.run(modelname=canned_test_name, group=2) |
| 78 | +testid = str( test_id_json["runid"] ) |
| 79 | +run_id = 'TEST-' + testid |
| 80 | +print("Test Run Id: %s"%run_id) |
| 81 | +
|
| 82 | +#get the ids for all tests running on the chassis |
| 83 | +runningTests_Ids = [test['id'] for test in bps.topology.runningTest.get()] |
| 84 | +#wait while the test is still running |
| 85 | +while run_id in runningTests_Ids: |
| 86 | + run_state = bps.topology.runningTest[run_id].get() |
| 87 | + #print progress if test started |
| 88 | + try: print ('progress: %s%% , runtime %ss' % (run_state['progress'], run_state['runtime'] )) |
| 89 | + except: print ("Starting...") |
| 90 | + time.sleep(2) |
| 91 | + #update the current running tests |
| 92 | + runningTests_Ids = [test['id'] for test in bps.topology.runningTest.get()] |
| 93 | +
|
| 94 | +print("~The test finished the execution.") |
| 95 | +results = bps.reports.search(searchString=canned_test_name, limit=10, sort="endTime", sortorder="descending") |
| 96 | +result = results[0] |
| 97 | +print ("%s execution duration %s ended with status: %s " % (result['name'], result['duration'], result['result']) ) |
| 98 | +
|
| 99 | +#getting 3.4 Section: Synopsys Summary of Results from the Report |
| 100 | +tabledata = bps.reports.getReportTable(runid=testid, sectionId="3.4") |
| 101 | +pp(tabledata) |
| 102 | +
|
| 103 | +print ("Unreserving the ports") |
| 104 | +for p in port_list: |
| 105 | + bps.topology.unreserve([{'slot': slot_number, 'port': p, 'group': 2}]) |
| 106 | +
|
| 107 | +bps.logout() |
| 108 | +``` |
| 109 | +
|
| 110 | +## Documentation |
| 111 | +Documentation is available using the following methods: |
| 112 | +* [Online web based documentation and samples](https://github.com/OpenIxia/BreakingPoint) |
| 113 | +* On your BreakingPoint System RestApi found near the BreakingPoint App |
| 114 | +* Documentation available in the online doc browser is also inlined in each class, property and method and can be viewed using the python help command |
| 115 | + ```python |
| 116 | + from bps_restpy.testplatform.testplatform import TestPlatform |
| 117 | + |
| 118 | + #login to your Breaking Point System |
| 119 | + help(BPS) |
| 120 | + bps = BPS('your_bps_IP_or_FQDN', 'admin', 'admin') |
| 121 | + |
| 122 | + help(bps.testmodel.importModel) |
| 123 | + |
| 124 | + ``` |
| 125 | +
|
| 126 | +## Additional Samples |
| 127 | +Visit the [OpenIxia breakingpoint-restpy sample site maintained by solution architects](https://github.com/OpenIxia/BreakingPoint) for in depth end-to-end samples that demonstrate the following: |
| 128 | +* building a configuration |
| 129 | + * from scratch |
| 130 | + * from an existing IxNetwork configuration |
| 131 | +* running the configuration |
| 132 | + * connecting ports to hardware |
| 133 | + * starting protocols |
| 134 | + * starting traffic |
| 135 | +* getting statistics |
| 136 | + * port stats |
| 137 | + * traffic stats |
| 138 | +
|
| 139 | +
|
0 commit comments