CLI minor fixes and cleanup
diff --git a/cli/cli/c_actions.py b/cli/cli/c_actions.py
index a7b95b5..ac30dc8 100755
--- a/cli/cli/c_actions.py
+++ b/cli/cli/c_actions.py
@@ -82,15 +82,20 @@
global tunnel_id,tunnel_dict
if sdnsh.description: # description debugging
print "tunnel_create:" , data
- if not tunnel_dict:
+ if data.has_key('tunnel-id'):
+ if (tunnel_id != None):
+ if sdnsh.description: # description debugging
+ print "tunnel_create: previous data is not cleaned up"
+ tunnel_id=None
+ tunnel_dict={}
tunnel_id=data['tunnel-id']
tunnel_dict[tunnel_id]=[]
- if sdnsh.description: # description debugging
- print "tunnel_create:" , tunnel_id, tunnel_dict
if data.has_key('node-label'):
tunnel_dict[tunnel_id].append(data['node-label'])
if data.has_key('adjacency-label'):
tunnel_dict[tunnel_id].append(data['adjacency-label'])
+ if sdnsh.description: # description debugging
+ print "tunnel_create:" , tunnel_id, tunnel_dict
def tunnel_config_exit():
global tunnel_id,tunnel_dict
@@ -103,15 +108,20 @@
obj_data = {}
obj_data['tunnel_id']=tunnel_id
obj_data['label_path']=entries
- data = sdnsh.store.rest_post_request(url_str,obj_data)
+ result = "fail"
+ try:
+ result = sdnsh.store.rest_post_request(url_str,obj_data)
+ except Exception, e:
+ errors = sdnsh.rest_error_to_dict(e)
+ print sdnsh.rest_error_dict_to_message(errors)
# LOOK! successful stuff should be returned in json too.
- if data != "success":
- result = json.loads(data)
- return result
+ tunnel_dict = {}
+ tunnel_id = None
+ if result != "success":
+ print "command failed"
else:
print "empty command"
#Clear the transit information
- tunnel_dict = {}
def tunnel_remove(data=None):
if sdnsh.description: # description debugging
@@ -120,18 +130,25 @@
url_str = "http://%s/rest/v1/tunnel/" % (sdnsh.controller)
obj_data = {}
obj_data['tunnel_id']=data['tunnel-id']
- data = sdnsh.store.rest_post_request(url_str,obj_data,'DELETE')
- if data != "deleted":
- result = json.loads(data)
- return result
+ result = "fail"
+ try:
+ result = sdnsh.store.rest_post_request(url_str,obj_data,'DELETE')
+ except Exception, e:
+ errors = sdnsh.rest_error_to_dict(e)
+ print sdnsh.rest_error_dict_to_message(errors)
+ if result != "deleted":
+ print "command failed"
policy_obj_data = {}
-flow = {}
def policy_create(data=None):
global policy_obj_data
if sdnsh.description: # description debugging
print "policy_create:" , data
if data.has_key('policy-id'):
+ if policy_obj_data:
+ if sdnsh.description: # description debugging
+ print "policy_create: previous data is not cleaned up"
+ policy_obj_data = {}
policy_obj_data['policy_id'] = data['policy-id']
policy_obj_data['policy_type'] = data['policy-type']
if data.has_key('src_ip'):
@@ -151,15 +168,18 @@
print "policy_config_exit entered", policy_obj_data
if policy_obj_data:
url_str = "http://%s/rest/v1/policy/" % (sdnsh.controller)
- data = sdnsh.store.rest_post_request(url_str,policy_obj_data)
- # LOOK! successful stuff should be returned in json too.
- if data != "success":
- result = json.loads(data)
- return result
+ result = "fail"
+ try:
+ result = sdnsh.store.rest_post_request(url_str,policy_obj_data)
+ except Exception, e:
+ errors = sdnsh.rest_error_to_dict(e)
+ print sdnsh.rest_error_dict_to_message(errors)
+ if result != "success":
+ print "command failed"
+ policy_obj_data = {}
else:
print "empty command"
#Clear the transit information
- policy_obj_data = {}
def policy_remove(data=None):
if sdnsh.description: # description debugging
@@ -168,11 +188,15 @@
url_str = "http://%s/rest/v1/policy/" % (sdnsh.controller)
obj_data = {}
obj_data['policy_id']=data['policy-id']
- data = sdnsh.store.rest_post_request(url_str,obj_data,'DELETE')
- if data != "deleted":
- result = json.loads(data)
- return result
-
+ result = "fail"
+ try:
+ result = sdnsh.store.rest_post_request(url_str,obj_data,'DELETE')
+ except Exception, e:
+ errors = sdnsh.rest_error_to_dict(e)
+ print sdnsh.rest_error_dict_to_message(errors)
+ if result != "deleted":
+ print "command failed"
+
def write_fields(obj_type, obj_id, data):
diff --git a/cli/cli/cli.py b/cli/cli/cli.py
index 0f807ce..e6987af 100755
--- a/cli/cli/cli.py
+++ b/cli/cli/cli.py
@@ -534,7 +534,7 @@
'ping', 'test', 'version',
'connect', 'watch', 'no' ]
- #self.command_nested_dict['enable'] = [ 'clear', 'end' ]
+ self.command_nested_dict['enable'] = [ 'clear', 'end' ]
#self.command_dict['config-internal'] = ['lint', 'permute']
diff --git a/cli/cli/desc/version200/policy.py b/cli/cli/desc/version200/policy.py
index 1ddd33c..2dee7c1 100644
--- a/cli/cli/desc/version200/policy.py
+++ b/cli/cli/desc/version200/policy.py
@@ -1,42 +1,6 @@
import command
import json
import fmtcnv
-"""
-POLICY_SUBMODE_COMMAND_DESCRIPTION = {
- 'name' : 'policy',
- 'short-help' : 'Enter policy submode, configure SR policy details',
- 'mode' : 'config',
- 'parent-field' : None,
- 'command-type' : 'config-submode',
- 'obj-type' : 'policy-config',
- 'submode-name' : 'config-policy',
- 'doc' : 'policy|policy',
- 'doc-example' : 'policy|tunnel-example',
- 'args' : (
- {
- 'field' : 'policy-id',
- 'type' : 'identifier',
- 'completion' : 'complete-object-field',
- 'syntax-help' : 'Enter a policy id',
- 'doc' : 'policy|policy',
- 'doc-include' : [ 'type-doc' ],
- 'action' : (
- {
- 'proc' : 'create-policy',
- },
- {
- 'proc' : 'push-mode-stack',
- },
- ),
- 'no-action': (
- {
- 'proc' : 'remove-policy',
- }
- ),
- }
- )
-}
-"""
POLICY_CONFIG_FORMAT = {
'policy-config' : {
'field-orderings' : {
@@ -92,7 +56,7 @@
'field' : 'policy-type',
'optional-for-no' : True,
'type' : 'enum',
- 'values' : ('tunnel','loadbalanced','avoid','deny'),
+ 'values' : ('tunnel-flow','loadbalanced','avoid','deny'),
'completion' : 'complete-object-field',
'syntax-help' : 'Enter a policy type',
'doc' : 'policy|policy',
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPolicyResource.java b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPolicyResource.java
index f1ad1ec..fc38eaa 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPolicyResource.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPolicyResource.java
@@ -57,10 +57,11 @@
new IPv4Net(createParams.getSrc_ip()) : null;
IPv4Net dst_ip = (createParams.getDst_ip() != null) ?
new IPv4Net(createParams.getDst_ip()) : null;
+ Byte protoType = (createParams.getProto_type() != null) ?
+ getProtoTypeByte(createParams.getProto_type()) : null;
boolean result = segmentRoutingService.createPolicy(
createParams.getPolicy_id(), null, null, null,
- src_ip, dst_ip,
- getProtoTypeByte(createParams.getProto_type()),
+ src_ip, dst_ip, protoType,
createParams.getSrc_tp_port(),
createParams.getDst_tp_port(),
createParams.getPriority(),