)
-@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"
)
"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)
# 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,