| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 1 | """ |
| 2 | For now only a dummy client. Connects to the zerorpc interface of the |
| 3 | emulator and performs some actions (start/stop/list). |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 4 | |
| 5 | We will provide a full CLI here later on which looks like: |
| 6 | |
| 7 | cli compute start dc1 my_name flavor_a |
| 8 | cli network create dc1 11.0.0.0/24 |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 9 | """ |
| 10 | import time |
| peusterm | 056fd45 | 2016-01-12 15:32:25 +0100 | [diff] [blame^] | 11 | import pprint |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 12 | import zerorpc |
| 13 | |
| 14 | |
| 15 | def main(): |
| peusterm | 056fd45 | 2016-01-12 15:32:25 +0100 | [diff] [blame^] | 16 | pp = pprint.PrettyPrinter(indent=4) |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 17 | print "Example CLI client" |
| 18 | # create connection to remote Mininet instance |
| 19 | c = zerorpc.Client() |
| 20 | c.connect("tcp://127.0.0.1:4242") |
| 21 | |
| 22 | # do some API tests |
| peusterm | e609269 | 2016-01-11 16:32:58 +0100 | [diff] [blame] | 23 | print c.compute_action_start("dc2", "d1") |
| peusterm | c3b977e | 2016-01-12 10:09:35 +0100 | [diff] [blame] | 24 | print c.compute_action_start("dc2", "d2") |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 25 | |
| peusterm | 4e98b63 | 2016-01-12 14:08:07 +0100 | [diff] [blame] | 26 | time.sleep(1) |
| 27 | print c.compute_list("dc2") |
| 28 | |
| 29 | time.sleep(1) |
| peusterm | 056fd45 | 2016-01-12 15:32:25 +0100 | [diff] [blame^] | 30 | pp.pprint(c.compute_status("dc2", "d1")) |
| 31 | pp.pprint(c.compute_status("dc2", "d2")) |
| peusterm | 4e98b63 | 2016-01-12 14:08:07 +0100 | [diff] [blame] | 32 | |
| 33 | time.sleep(5) |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 34 | |
| peusterm | e609269 | 2016-01-11 16:32:58 +0100 | [diff] [blame] | 35 | print c.compute_action_stop("dc2", "d1") |
| peusterm | c3b977e | 2016-01-12 10:09:35 +0100 | [diff] [blame] | 36 | print c.compute_action_stop("dc2", "d2") |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 37 | |
| 38 | |
| 39 | if __name__ == '__main__': |
| 40 | main() |