From: garciadeblas Date: Mon, 14 May 2018 16:22:40 +0000 (+0200) Subject: fixes for ns-alarm-create and ns-metric-export, disabled ns-alarm-delete X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F42%2F6142%2F3;p=osm%2Fosmclient.git fixes for ns-alarm-create and ns-metric-export, disabled ns-alarm-delete Change-Id: Ia3ea21d8b6d3eca158e0cded6ec34e7ac3a2313e Signed-off-by: garciadeblas --- diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py index bcca77a..1fc824e 100755 --- a/osmclient/scripts/osm.py +++ b/osmclient/scripts/osm.py @@ -1120,16 +1120,18 @@ def sdnc_show(ctx, name): @click.option('--threshold_value', prompt=True, help='threshold value that, when crossed, an alarm is triggered') @click.option('--threshold_operator', prompt=True, - help='threshold operator describing the comparison (GE, LE, GT, LT, EQ') + help='threshold operator describing the comparison (GE, LE, GT, LT, EQ)') @click.option('--statistic', default='AVERAGE', help='statistic (AVERAGE, MINIMUM, MAXIMUM, COUNT, SUM)') @click.pass_context 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_name'] = ns + 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 @@ -1145,20 +1147,20 @@ def ns_alarm_create(ctx, name, ns, vnf, vdu, metric, severity, exit(1) -@cli.command(name='ns-alarm-delete') -@click.argument('name') -@click.pass_context -def ns_alarm_delete(ctx, name): - '''deletes an alarm - - NAME: name of the alarm to be deleted - ''' - try: - check_client_version(ctx.obj, ctx.command.name) - ctx.obj.ns.delete_alarm(name) - except ClientException as inst: - print(inst.message) - exit(1) +#@cli.command(name='ns-alarm-delete') +#@click.argument('name') +#@click.pass_context +#def ns_alarm_delete(ctx, name): +# '''deletes an alarm +# +# NAME: name of the alarm to be deleted +# ''' +# try: +# check_client_version(ctx.obj, ctx.command.name) +# ctx.obj.ns.delete_alarm(name) +# except ClientException as inst: +# print(inst.message) +# exit(1) #################### @@ -1180,8 +1182,10 @@ def ns_alarm_delete(ctx, name): 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_name'] = ns + 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 @@ -1190,11 +1194,11 @@ def ns_metric_export(ctx, ns, vnf, vdu, metric, interval): try: check_client_version(ctx.obj, ctx.command.name) if not interval: - ctx.obj.ns.export_metric(metric_data) + print '{}'.format(ctx.obj.ns.export_metric(metric_data)) else: i = 1 while True: - ctx.obj.ns.export_metric(metric_data) + print '{} {}'.format(ctx.obj.ns.export_metric(metric_data),i) time.sleep(int(interval)) i+=1 except ClientException as inst: diff --git a/osmclient/sol005/ns.py b/osmclient/sol005/ns.py index 945e622..30bbe02 100644 --- a/osmclient/sol005/ns.py +++ b/osmclient/sol005/ns.py @@ -238,22 +238,19 @@ class Ns(object): raise ClientException(message) def create_alarm(self, alarm): - ns = self.get(alarm['ns_name']) - alarm['ns_id'] = ns['_id'] - alarm.pop('ns_name') data = {} data["create_alarm_request"] = {} data["create_alarm_request"]["alarm_create_request"] = alarm try: http_code, resp = self._http.post_cmd(endpoint='/test/message/alarm_request', postfields_dict=data) - if resp: - resp = json.loads(resp) - #print 'RESP: {}'.format(resp) - if not resp: - raise ClientException('unexpected response from server: '.format( - resp)) - print 'Alarm created' + if http_code in (200, 201, 202, 204): + #resp = json.loads(resp) + #print 'RESP: {}'.format(resp) + print 'Alarm created' + else: + raise ClientException('unexpected response from server: code: {}, resp: {}'.format( + http_code, resp)) except ClientException as exc: message="failed to create alarm: alarm {}\nerror:\n{}".format( alarm, @@ -268,13 +265,13 @@ class Ns(object): try: http_code, resp = self._http.post_cmd(endpoint='/test/message/alarm_request', postfields_dict=data) - if resp: - resp = json.loads(resp) - #print 'RESP: {}'.format(resp) - if not resp: - raise ClientException('unexpected response from server: '.format( - resp)) - print 'Alarm deleted' + if http_code in (200, 201, 202, 204): + #resp = json.loads(resp) + #print 'RESP: {}'.format(resp) + print 'Alarm deleted' + else: + raise ClientException('unexpected response from server: code: {}, resp: {}'.format( + http_code, resp)) except ClientException as exc: message="failed to delete alarm: alarm {}\nerror:\n{}".format( alarm, @@ -282,21 +279,18 @@ class Ns(object): raise ClientException(message) def export_metric(self, metric): - ns = self.get(metric['ns_name']) - metric['ns_id'] = ns['_id'] - metric.pop('ns_name') data = {} data["read_metric_data_request"] = metric try: http_code, resp = self._http.post_cmd(endpoint='/test/message/metric_request', postfields_dict=data) - if resp: - resp = json.loads(resp) - #print 'RESP: {}'.format(resp) - if not resp: - raise ClientException('unexpected response from server: '.format( - resp)) - print 'Metric exported' + if http_code in (200, 201, 202, 204): + #resp = json.loads(resp) + #print 'RESP: {}'.format(resp) + return 'Metric exported' + else: + raise ClientException('unexpected response from server: code: {}, resp: {}'.format( + http_code, resp)) except ClientException as exc: message="failed to export metric: metric {}\nerror:\n{}".format( metric,