blob: 77c3cd4371c0121cc8f18c100923f70dfdd27265 [file] [log] [blame]
Andrea Campanella6d774232018-12-21 12:18:21 +01001#!/usr/bin/python3
2
3import requests
4import json
5import itertools
6
7#
8# Creates connectivity json
9#
10def tapi_input(sip_uuids):
11 create_input = {
12 "tapi-connectivity:input": {
13 "end-point" : [
14 {
15 "local-id": sip_uuids[0],
16 "service-interface-point": {
17 "service-interface-point-uuid" : sip_uuids[0]
18 }
19 }
20 ,
21 {
22 "local-id": sip_uuids[1],
23 "service-interface-point": {
24 "service-interface-point-uuid" : sip_uuids[1]
25 }
26 }
27 ]
28 }
29 }
30 return create_input
31
32#
33# Obtains TAPI context through restconf
34#
35def get_context(url_context):
36 resp = requests.get(url_context, auth=('onos', 'rocks'))
37 if resp.status_code != 200:
38 raise Exception('GET {}'.format(resp.status_code))
39 return resp.json()
40
41#
42# Requests a connectivity service
43#
44def request_connection(url_connectivity, context):
45 # All Context SIPs
46 sips = context["tapi-common:context"]["service-interface-point"]
47
48 # Sorted Photonic Media SIPs. filter is an iterable
49 esips = list(filter(is_dsr_media, sorted(sips, key=lambda sip: sip["name"][0]["value"])))
50 endpoints = [esips[0], esips[-1]]
51 sip_uuids = []
52 for sip in endpoints:
53 sip_uuids.append(sip["uuid"])
54 for uuid in sip_uuids:
55 print(uuid)
56
57 create_input_json = json.dumps(tapi_input(sip_uuids))
58 print (create_input_json)
59 headers = {'Content-type': 'application/json'}
60 resp = requests.post(url_connectivity, data=create_input_json, headers=headers, auth=('onos', 'rocks'))
61 if resp.status_code != 200:
62 raise Exception('POST {}'.format(resp.status_code))
63 return resp
64
65#
66# Filter method used to keep only SIPs that are photonic_media
67#
68def is_photonic_media(sip):
69 return sip["layer-protocol-name"]=="PHOTONIC_MEDIA"
70
71#
72# Filter method used to keep only SIPs that are DSR
73#
74def is_dsr_media(sip):
75 return sip["layer-protocol-name"]=="DSR"
76
77#
78# Processes the topology to verify the correctness
79#
80def process_topology():
81 # TODO use method to parse topology
82 # Getting the Topology
83 # topology = context["tapi-common:context"]["tapi-topology:topology-context"]["topology"][0]
84 # nodes = topology["node"];
85 # links = topology["link"];
86 noop
87
88#
89# Creates a connection first getting the context, parsing for SIPS and then issuing the request.
90#
91def create_connection(url_context, url_connectivity):
92 context = get_context(url_context)
93 return request_connection(url_connectivity, context)
94
95#
96# Obtains existing connectivity services
97#
98def get_connection(url_connectivity, uuid):
Boyuan Yan528fdba2019-02-15 12:24:43 -080099 # uuid is useless for this method
100 json = '{}'
Andrea Campanella6d774232018-12-21 12:18:21 +0100101 headers = {'Content-type': 'application/json'}
102 resp = requests.post(url_connectivity, data=json, headers=headers, auth=('onos', 'rocks'))
103 if resp.status_code != 200:
104 raise Exception('POST {}'.format(resp.status_code))
105 return resp
106
107
108
109
110
111