srikanth | 116e6e8 | 2014-08-19 07:22:37 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # |
| 4 | # Copyright (c) 2013 Big Switch Networks, Inc. |
| 5 | # |
| 6 | # Licensed under the Eclipse Public License, Version 1.0 (the |
| 7 | # "License"); you may not use this file except in compliance with the |
| 8 | # License. You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.eclipse.org/legal/epl-v10.html |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 15 | # implied. See the License for the specific language governing |
| 16 | # permissions and limitations under the License. |
| 17 | # |
| 18 | # Query REST API, return dictionary with alias to DPID mappings. |
| 19 | # |
| 20 | |
| 21 | #Importing modules |
| 22 | import re |
| 23 | import sys |
| 24 | import json |
| 25 | import urllib2 |
| 26 | from sdncon.rest.views import do_instance |
| 27 | |
| 28 | def aliasDict(request): |
| 29 | |
| 30 | # Query JSON from API and load into dictionary |
| 31 | rawdict = json.loads(do_instance(request, 'switch-alias').content) |
| 32 | |
| 33 | # Dictionaries |
| 34 | aliasdict = {} |
| 35 | |
| 36 | # Step through master 'alias' list, extract entry for each dictionary. |
| 37 | for index_query,value1_query in enumerate(rawdict): |
| 38 | |
| 39 | # get needed entries in 'alias' |
| 40 | aliasdict[value1_query.get('switch','ERR')] = value1_query.get('id',' ') |
| 41 | |
| 42 | return aliasdict |