blob: 768cf60d77675fe3f2fe47f103e60b7a79bd1b9b [file] [log] [blame]
srikanth116e6e82014-08-19 07:22:37 -07001#!/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
22import re
23import sys
24import json
25import urllib2
26from sdncon.rest.views import do_instance
27
28def 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