Spring CLI changes to work with onos-next: partial
diff --git a/cli/c_actions.py b/cli/c_actions.py
index debece3..05a2eeb 100755
--- a/cli/c_actions.py
+++ b/cli/c_actions.py
@@ -1823,23 +1823,44 @@
else:
result = []
import fmtcnv
- if (onos == 1) and (url == 'links'):
- for entry in entries:
- src = entry.get('src')
- dst = entry.get('dst')
- for tempEntry in entries:
- if cmp(src, tempEntry.get('dst')) == 0:
- if cmp(dst, tempEntry.get('src')) == 0:
- entries.remove(tempEntry)
- result.append({
- 'src-switch' : fmtcnv.print_switch_and_alias(entry['src']['dpid']),
- 'src-port' : entry['src']['portNumber'],
- 'src-port-state' : 0,
- 'dst-switch' : fmtcnv.print_switch_and_alias(entry['dst']['dpid']),
- 'dst-port' : entry['dst']['portNumber'],
- 'dst-port-state' : 0,
- 'type' : entry['type'],
- })
+ if (url == 'links'):
+ if (onos == 1):
+ for entry in entries:
+ src = entry.get('src')
+ dst = entry.get('dst')
+ for tempEntry in entries:
+ if cmp(src, tempEntry.get('dst')) == 0:
+ if cmp(dst, tempEntry.get('src')) == 0:
+ entries.remove(tempEntry)
+ result.append({
+ 'src-switch' : fmtcnv.print_switch_and_alias(entry['src']['dpid']),
+ 'src-port' : entry['src']['portNumber'],
+ 'src-port-state' : 0,
+ 'dst-switch' : fmtcnv.print_switch_and_alias(entry['dst']['dpid']),
+ 'dst-port' : entry['dst']['portNumber'],
+ 'dst-port-state' : 0,
+ 'type' : entry['type'],
+ })
+ elif onos == 2:
+ entries = entries.get('links')
+ for entry in entries:
+ src = entry.get('src')
+ dst = entry.get('dst')
+ for tempEntry in entries:
+ if cmp(src, tempEntry.get('dst')) == 0:
+ if cmp(dst, tempEntry.get('src')) == 0:
+ entries.remove(tempEntry)
+ result.append({
+ #'src-switch' : fmtcnv.print_switch_and_alias(entry['src']['device']),
+ 'src-switch' : entry['src']['device'],
+ 'src-port' : entry['src']['port'],
+ 'src-port-state' : 0,
+ #'dst-switch' : fmtcnv.print_switch_and_alias(entry['dst']['device']),
+ 'dst-switch' : entry['dst']['device'],
+ 'dst-port' : entry['dst']['port'],
+ 'dst-port-state' : 0,
+ 'type' : None,
+ })
else:
result = entries
diff --git a/cli/rest_to_model.py b/cli/rest_to_model.py
index 7ef25a9..ab7a2f7 100755
--- a/cli/rest_to_model.py
+++ b/cli/rest_to_model.py
@@ -406,64 +406,88 @@
switch_match = data.get('dpid')
switch_prefix = data.get('dpid__startswith')
- # this synthetic obj_type's name is 'switches' in an attempt
- # to disabigutate it from 'class Switch'
- #TODO: Need figure out a better way to get url (Through sdncon framework)
- url = "http://%s/rest/v1/mastership" % sdnsh.controller
- try:
- result2 = sdnsh.store.rest_simple_request(url)
- check_rest_result(result2)
- mastership_data = json.loads(result2)
- except Exception, e:
- if sdnsh.description: # description debugging
- print "get_model_from_url: failed request %s: '%s'" % (url, e)
- entries = []
- for entry in entries:
- dpid = entry.get('dpid')
- if(dpid in mastership_data.keys()):
- #As there is only one master for switch
- controller = mastership_data[dpid][0].get('controllerId')
- else:
- controller = None
- if switch_match and switch_match != entry['dpid']:
- continue
- if switch_prefix and not entry['dpid'].startswith(switch_prefix):
- continue
- if onos == 1:
+ if onos == 1:
+ # this synthetic obj_type's name is 'switches' in an attempt
+ # to disabigutate it from 'class Switch'
+ #TODO: Need figure out a better way to get url (Through sdncon framework)
+ url = "http://%s/rest/v1/mastership" % sdnsh.controller
+ try:
+ result2 = sdnsh.store.rest_simple_request(url)
+ check_rest_result(result2)
+ mastership_data = json.loads(result2)
+ except Exception, e:
+ if sdnsh.description: # description debugging
+ print "get_model_from_url: failed request %s: '%s'" % (url, e)
+ entries = []
+ for entry in entries:
+ dpid = entry.get('dpid')
+ if(dpid in mastership_data.keys()):
+ #As there is only one master for switch
+ controller = mastership_data[dpid][0].get('controllerId')
+ else:
+ controller = None
+ if switch_match and switch_match != entry['dpid']:
+ continue
+ if switch_prefix and not entry['dpid'].startswith(switch_prefix):
+ continue
+ if onos == 1:
+ result.append({
+ 'dpid' : entry['dpid'],
+ 'switch-alias' : entry['stringAttributes']['name'],
+ 'connected-since' : entry['stringAttributes']['ConnectedSince'],
+ 'ip-address' : entry['stringAttributes']['remoteAddress'],
+ 'type' : entry['stringAttributes']['type'],
+ 'controller' : controller
+ })
+ else:
+ attrs = entry['attributes']
+ actions = entry['actions']
+ capabilities = entry['capabilities']
+ inet_address = entry.get('inetAddress')
+ ip_address = ''
+ tcp_port = ''
+ if inet_address:
+ # Current Java value looks like: /192.168.2.104:38420
+ inet_parts = inet_address.split(':')
+ ip_address = inet_parts[0][1:]
+ tcp_port = inet_parts[1]
+
+ result.append({
+ 'dpid' : entry['dpid'],
+ 'connected-since' : entry['connectedSince'],
+ 'ip-address' : ip_address,
+ 'tcp-port' : tcp_port,
+ 'actions' : actions,
+ 'capabilities' : capabilities,
+ 'dp-desc' : attrs.get('DescriptionData', ''),
+ 'fast-wildcards' : attrs.get('FastWildcards', ''),
+ 'supports-nx-role' : attrs.get('supportsNxRole', ''),
+ 'supports-ofpp-flood' : attrs.get('supportsOfppFlood', ''),
+ 'supports-ofpp-table' : attrs.get('supportsOfppTable', ''),
+ 'core-switch' : False,
+ })
+ elif onos == 2:
+ for entry in entries.get('devices'):
+ dpid = entry.get('id')
+ #if(dpid in mastership_data.keys()):
+ #As there is only one master for switch
+ # controller = mastership_data[dpid][0].get('controllerId')
+ #else:
+ # controller = None
+ if switch_match and switch_match != entry['id']:
+ continue
+ if switch_prefix and not entry['id'].startswith(switch_prefix):
+ continue
+ switchType = entry['mfr'] + '' + \
+ entry['hw'] + '' + entry['sw'] + '' + \
+ entry['annotations']['protocol']
result.append({
- 'dpid' : entry['dpid'],
- 'switch-alias' : entry['stringAttributes']['name'],
- 'connected-since' : entry['stringAttributes']['ConnectedSince'],
- 'ip-address' : entry['stringAttributes']['remoteAddress'],
- 'type' : entry['stringAttributes']['type'],
- 'controller' : controller
- })
- else:
- attrs = entry['attributes']
- actions = entry['actions']
- capabilities = entry['capabilities']
- inet_address = entry.get('inetAddress')
- ip_address = ''
- tcp_port = ''
- if inet_address:
- # Current Java value looks like: /192.168.2.104:38420
- inet_parts = inet_address.split(':')
- ip_address = inet_parts[0][1:]
- tcp_port = inet_parts[1]
-
- result.append({
- 'dpid' : entry['dpid'],
- 'connected-since' : entry['connectedSince'],
- 'ip-address' : ip_address,
- 'tcp-port' : tcp_port,
- 'actions' : actions,
- 'capabilities' : capabilities,
- 'dp-desc' : attrs.get('DescriptionData', ''),
- 'fast-wildcards' : attrs.get('FastWildcards', ''),
- 'supports-nx-role' : attrs.get('supportsNxRole', ''),
- 'supports-ofpp-flood' : attrs.get('supportsOfppFlood', ''),
- 'supports-ofpp-table' : attrs.get('supportsOfppTable', ''),
- 'core-switch' : False,
+ 'dpid' : entry['id'],
+ 'switch-alias' : None,
+ 'connected-since' : None,
+ 'ip-address' : entry['annotations']['channelId'],
+ 'type' : switchType,
+ 'controller' : None
})
# now add switch-config
diff --git a/sdncon/rest/views.py b/sdncon/rest/views.py
index 3bcc48a..94efc75 100755
--- a/sdncon/rest/views.py
+++ b/sdncon/rest/views.py
@@ -56,7 +56,10 @@
def controller_url(*elements):
- CONTROLLER_URL_PREFIX = "http://%s:%s/wm/" % (controller_rest_ip, controller_rest_port)
+ if onos == 2:
+ CONTROLLER_URL_PREFIX = "http://%s:%s/" % (controller_rest_ip, controller_rest_port)
+ else:
+ CONTROLLER_URL_PREFIX = "http://%s:%s/wm/" % (controller_rest_ip, controller_rest_port)
return CONTROLLER_URL_PREFIX + '/'.join(elements)
class RestException(Exception):
@@ -717,18 +720,22 @@
def do_device(request):
if onos == 0:
return get_sdnplatform_query(request, "device")
- else:
+ elif onos == 1:
url = controller_url("onos", "topology", "hosts")
- if request.META['QUERY_STRING']:
- url += '?' + request.META['QUERY_STRING']
- return get_sdnplatform_response(url)
+ else:
+ url = controller_url("onos", "v1", "hosts")
+ if request.META['QUERY_STRING']:
+ url += '?' + request.META['QUERY_STRING']
+ return get_sdnplatform_response(url)
@safe_rest_view
def do_switches(request):
if onos == 0:
url = controller_url("core", "controller", "switches", "json")
- else:
+ elif onos == 1:
url = controller_url("onos", "topology", "switches")
+ else:
+ url = controller_url("onos", "v1", "devices")
if request.META['QUERY_STRING']:
url += '?' + request.META['QUERY_STRING']
return get_sdnplatform_response(url)
@@ -776,8 +783,10 @@
def do_links(request):
if onos == 0:
url = controller_url("topology", "links", "json")
- else:
+ elif onos == 1:
url = controller_url("onos", "topology", "links")
+ else:
+ url = controller_url("onos", "v1", "links")
if request.META['QUERY_STRING']:
url += '?' + request.META['QUERY_STRING']
return get_sdnplatform_response(url)