Open Kilda Java Documentation
deploy-flow-rules.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright 2017 Telstra Open Source
3 #
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 
17 import requests
18 from base64 import b64encode
19 
20 url = "http://localhost:8088/api/v1/flows"
21 headers = {
22  'Content-Type': 'application/json',
23  'correlation_id': 'deploy-flow-1',
24  'Authorization': 'Basic %s' % b64encode(b"kilda:kilda").decode("ascii")
25  }
26 
27 #
28 # This models one of the first flows used by ATDD. It sends the request to teh NB API so that
29 # kilda will construct the flow path rules.
30 # TODO: would be better to pull from the same data, ensure code bases on synchronized..
31 # at the moment, this is hardcoded here, and ATDD has a separate source.
32 #
33 
34 j_data = {"flowid":"c3none",
35  "source":
36  {"switch-id":"de:ad:be:ef:00:00:00:02", "port-id":1, "vlan-id":0},
37  "destination":
38  {"switch-id":"de:ad:be:ef:00:00:00:04", "port-id":2, "vlan-id":0},
39  "maximum-bandwidth":10000,
40  "description":"c3none",
41  "last-updated":"null"}
42 result = requests.put(url, json=j_data, headers=headers)
43 
44 print result.status_code
45 print result.text
46 
47 
48 
49