From: adurti Date: Fri, 31 May 2024 09:09:05 +0000 (+0530) Subject: Feature 11011: Multiple NS deletion in OSM(osm client) X-Git-Tag: release-v16.0-start~2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=c08599f12dff8633e3b7514de61a74fd873a28b8;p=osm%2Fosmclient.git Feature 11011: Multiple NS deletion in OSM(osm client) Change-Id: I57edad436dc466640041332eb68fda37215aa05f Signed-off-by: adurti --- diff --git a/osmclient/cli_commands/ns.py b/osmclient/cli_commands/ns.py index ad07a11..972bfa3 100755 --- a/osmclient/cli_commands/ns.py +++ b/osmclient/cli_commands/ns.py @@ -376,8 +376,18 @@ def ns_create( ) -@click.command(name="ns-delete", short_help="deletes a NS instance") -@click.argument("name") +def process_ns_multi_delete_params(ctx, param, value): + ns_id_list = [] + for ns_id in value: + ns_id_list.append(ns_id) + ctx.params["ns_id_list"] = ns_id_list + return + + +@click.command(name="ns-delete", short_help="deletes NS instances") +@click.argument( + "names", nargs=-1, type=click.UNPROCESSED, callback=process_ns_multi_delete_params +) @click.option( "--force", is_flag=True, help="forces the deletion bypassing pre-conditions" ) @@ -396,14 +406,26 @@ def ns_create( "until the operation is completed, or timeout", ) @click.pass_context -def ns_delete(ctx, name, force, config, wait): - """deletes a NS instance +def ns_delete(ctx, names, ns_id_list, force, config, wait): + """deletes NS instances - NAME: name or ID of the NS instance to be deleted + NAMES: names or IDs of the NS instances to be deleted """ logger.debug("") - if not force: - ctx.obj.ns.delete(name, config=config, wait=wait) + ns_id_list = ctx.params["ns_id_list"] + if len(ns_id_list) > 25: + raise ClientException("Cannot delete more than 25 instances") + if len(ns_id_list) > 1: + ns_id_dict = {} + ns_id_dict["ns_ids"] = [] + for name in ns_id_list: + nsr = ctx.obj.ns.get(name) + ns_id_dict["ns_ids"].append(nsr["_id"]) + ctx.obj.ns.multi_delete(ns_id_dict) else: - utils.check_client_version(ctx.obj, "--force") - ctx.obj.ns.delete(name, force, config=config, wait=wait) + name = ns_id_list[0] + if not force: + ctx.obj.ns.delete(name, config=config, wait=wait) + else: + utils.check_client_version(ctx.obj, "--force") + ctx.obj.ns.delete(name, force, config=config, wait=wait) diff --git a/osmclient/sol005/ns.py b/osmclient/sol005/ns.py index 236674f..29232c1 100644 --- a/osmclient/sol005/ns.py +++ b/osmclient/sol005/ns.py @@ -153,6 +153,19 @@ class Ns(object): # msg = resp raise ClientException("failed to delete ns {} - {}".format(name, msg)) + def multi_delete(self, ns_id_dict): + self._client.get_token() + self._apiResource = "/ns_instances_terminate" + self._apiBase = "{}{}{}".format( + self._apiName, self._apiVersion, self._apiResource + ) + http_code, resp = self._http.post_cmd(self._apiBase, postfields_dict=ns_id_dict) + if http_code == 202: + print("Deletion in progress") + else: + msg = resp or "" + raise ClientException("failed to delete ns - {}".format(msg)) + def create( self, nsd_name,