bug 767: uniform role format
[osm/osmclient.git] / osmclient / scripts / osm.py
index b11ced4..83b4727 100755 (executable)
@@ -1329,7 +1329,6 @@ def pdu_create(ctx, name, pdu_type, interface, description, vim_account, descrip
         print((inst.message))
         exit(1)
 
-
 ####################
 # UPDATE operations
 ####################
@@ -1655,9 +1654,9 @@ def pdu_delete(ctx, name, force):
         exit(1)
 
 
-####################
+#################
 # VIM operations
-####################
+#################
 
 @cli.command(name='vim-create')
 @click.option('--name',
@@ -2104,7 +2103,7 @@ def sdnc_create(ctx,
         ctx.obj.sdnc.create(name, sdncontroller, wait=wait)
     except ClientException as inst:
         print((inst.message))
-
+        exit(1)
 
 @cli.command(name='sdnc-update', short_help='updates an SDN controller')
 @click.argument('name')
@@ -2204,7 +2203,7 @@ def sdnc_list(ctx, filter):
     except ClientException as inst:
         print((inst.message))
         exit(1)
-    table = PrettyTable(['name', 'id'])
+    table = PrettyTable(['sdnc name', 'id'])
     for sdnc in resp:
         table.add_row([sdnc['name'], sdnc['_id']])
     table.align = 'l'
@@ -2255,6 +2254,7 @@ def project_create(ctx, name):
         ctx.obj.project.create(name, project)
     except ClientException as inst:
         print(inst.message)
+        exit(1)
 
 
 @cli.command(name='project-delete')
@@ -2382,6 +2382,7 @@ def user_create(ctx, username, password, projects, project_role_mappings):
         ctx.obj.user.create(username, user)
     except ClientException as inst:
         print(inst.message)
+        exit(1)
 
 
 @cli.command(name='user-update')
@@ -2433,6 +2434,7 @@ def user_update(ctx, username, password, set_username, set_project, remove_proje
         ctx.obj.user.update(username, user)
     except ClientException as inst:
         print(inst.message)
+        exit(1)
 
 
 @cli.command(name='user-delete')
@@ -2521,19 +2523,21 @@ def user_show(ctx, name):
 def ns_alarm_create(ctx, name, ns, vnf, vdu, metric, severity,
                     threshold_value, threshold_operator, statistic):
     """creates a new alarm for a NS instance"""
-    ns_instance = ctx.obj.ns.get(ns)
-    alarm = {}
-    alarm['alarm_name'] = name
-    alarm['ns_id'] = ns_instance['_id']
-    alarm['correlation_id'] = ns_instance['_id']
-    alarm['vnf_member_index'] = vnf
-    alarm['vdu_name'] = vdu
-    alarm['metric_name'] = metric
-    alarm['severity'] = severity
-    alarm['threshold_value'] = int(threshold_value)
-    alarm['operation'] = threshold_operator
-    alarm['statistic'] = statistic
-    try:
+    # TODO: Check how to validate threshold_value.
+    # Should it be an integer (1-100), percentage, or decimal (0.01-1.00)?
+    try:
+        ns_instance = ctx.obj.ns.get(ns)
+        alarm = {}
+        alarm['alarm_name'] = name
+        alarm['ns_id'] = ns_instance['_id']
+        alarm['correlation_id'] = ns_instance['_id']
+        alarm['vnf_member_index'] = vnf
+        alarm['vdu_name'] = vdu
+        alarm['metric_name'] = metric
+        alarm['severity'] = severity
+        alarm['threshold_value'] = int(threshold_value)
+        alarm['operation'] = threshold_operator
+        alarm['statistic'] = statistic
         check_client_version(ctx.obj, ctx.command.name)
         ctx.obj.ns.create_alarm(alarm)
     except ClientException as inst:
@@ -2575,16 +2579,18 @@ def ns_alarm_create(ctx, name, ns, vnf, vdu, metric, severity,
 @click.pass_context
 def ns_metric_export(ctx, ns, vnf, vdu, metric, interval):
     """exports a metric to the internal OSM bus, which can be read by other apps"""
-    ns_instance = ctx.obj.ns.get(ns)
-    metric_data = {}
-    metric_data['ns_id'] = ns_instance['_id']
-    metric_data['correlation_id'] = ns_instance['_id']
-    metric_data['vnf_member_index'] = vnf
-    metric_data['vdu_name'] = vdu
-    metric_data['metric_name'] = metric
-    metric_data['collection_unit'] = 'WEEK'
-    metric_data['collection_period'] = 1
-    try:
+    # TODO: Check how to validate interval.
+    # Should it be an integer (seconds), or should a suffix (s,m,h,d,w) also be permitted?
+    try:
+        ns_instance = ctx.obj.ns.get(ns)
+        metric_data = {}
+        metric_data['ns_id'] = ns_instance['_id']
+        metric_data['correlation_id'] = ns_instance['_id']
+        metric_data['vnf_member_index'] = vnf
+        metric_data['vdu_name'] = vdu
+        metric_data['metric_name'] = metric
+        metric_data['collection_unit'] = 'WEEK'
+        metric_data['collection_period'] = 1
         check_client_version(ctx.obj, ctx.command.name)
         if not interval:
             print('{}'.format(ctx.obj.ns.export_metric(metric_data)))
@@ -2843,11 +2849,11 @@ def vnf_scale(ctx,
 
 @cli.command(name='role-create', short_help='creates a role')
 @click.argument('name')
-@click.option('--definition',
+@click.option('--permissions',
               default=None,
-              help='role definition using a dictionary')
+              help='role permissions using a dictionary')
 @click.pass_context
-def role_create(ctx, name, definition):
+def role_create(ctx, name, permissions):
     """
     Creates a new role.
 
@@ -2857,24 +2863,28 @@ def role_create(ctx, name, definition):
     """
     try:
         check_client_version(ctx.obj, ctx.command.name)
-        ctx.obj.role.create(name, definition)
+        ctx.obj.role.create(name, permissions)
     except ClientException as inst:
         print(inst.message)
+        exit(1)
 
 
 @cli.command(name='role-update', short_help='updates a role')
 @click.argument('name')
-@click.option('--definition',
+@click.option('--set-name',
               default=None,
-              help='add a new definition to the role')
+              help='change name of rle')
+# @click.option('--permissions',
+#               default=None,
+#               help='provide a yaml format dictionary with incremental changes. Values can be bool or None to delete')
 @click.option('--add',
               default=None,
-              help='add a resource access grant/denial')
+              help='yaml format dictionary with permission: True/False to access grant/denial')
 @click.option('--remove',
               default=None,
-              help='remove a resource access grant/denial')
+              help='yaml format list to remove a permission')
 @click.pass_context
-def role_update(ctx, name, definition, add, remove):
+def role_update(ctx, name, set_name, add, remove):
     """
     Updates a role.
 
@@ -2886,7 +2896,7 @@ def role_update(ctx, name, definition, add, remove):
     """
     try:
         check_client_version(ctx.obj, ctx.command.name)
-        ctx.obj.role.update(name, definition, add, remove)
+        ctx.obj.role.update(name, set_name, None, add, remove)
     except ClientException as inst:
         print(inst.message)
         exit(1)