Andrea Campanella | 6d77423 | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | import requests |
| 4 | import sys |
| 5 | import tapiHelper |
| 6 | |
| 7 | from requests.auth import HTTPBasicAuth |
| 8 | |
| 9 | if len(sys.argv) < 3: |
| 10 | print "usage: execute-tapi-context-get-call onos-node state" |
| 11 | sys.exit(1) |
| 12 | |
| 13 | node = sys.argv[1] |
| 14 | state = sys.argv[2] #if empty tapi context must be empty, if full it needs to contain all devices and ports |
| 15 | |
| 16 | if state != "empty" and len(sys.argv) == 3: |
| 17 | print "usage: execute-tapi-context-get-call onos-node full devices links ports" |
| 18 | sys.exit(1) |
| 19 | |
| 20 | request = 'http://' + node + ':8181/onos/restconf/data/tapi-common:context' |
| 21 | tapiContext = tapiHelper.get_context(request) |
| 22 | |
| 23 | if state == "empty": |
| 24 | uuid = tapiContext['tapi-common:context']['tapi-topology:topology-context']['topology'][0]['uuid'] |
| 25 | if uuid == "": |
| 26 | print "empty uuid" |
| 27 | sys.exit(1) |
| 28 | print "@stc tapi topology uuid=" + uuid |
| 29 | sys.exit(0) |
| 30 | |
| 31 | if state == "full": |
Boyuan Yan | d346e26 | 2019-02-14 12:04:15 -0800 | [diff] [blame] | 32 | devices = int(sys.argv[3]) |
| 33 | links = int(sys.argv[4]) |
| 34 | ports = int(sys.argv[5]) |
| 35 | dev_num = len(tapiContext['tapi-common:context']['tapi-topology:topology-context']['topology'][0]['node']) |
| 36 | directed_link_num = len(tapiContext['tapi-common:context']['tapi-topology:topology-context']['topology'][0]['link']) |
| 37 | port_num = 0 |
| 38 | for x in range(dev_num): |
| 39 | port_num=port_num+len(tapiContext['tapi-common:context']['tapi-topology:topology-context']['topology'][0]['node'][x]['owned-node-edge-point']) |
| 40 | print "device\tlink\tport\n%i\t%i\t%i" % (dev_num, directed_link_num/2, port_num) |
| 41 | assert devices == dev_num |
| 42 | assert links == directed_link_num/2 |
| 43 | assert ports == port_num |
| 44 | print "Topology infomation checking passed." |
Andrea Campanella | 6d77423 | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 45 | sys.exit(0) |
| 46 | |
| 47 | sys.exit(1) |
| 48 | |
| 49 | |
| 50 | |
| 51 | |