Skip to content
Snippets Groups Projects
Commit effca722 authored by garciadeblas's avatar garciadeblas
Browse files

Revert "Revert "Revert "Bug 2376 fixed: Performing NS-Update through CLI"""


This reverts commit 89aa4e1c.

Change-Id: I8ab8d7b91d4aff60f43da0000fefb4fad9d177c5
Signed-off-by: default avatargarciadeblas <gerardo.garciadeblas@telefonica.com>
parent eaed23be
No related branches found
No related tags found
No related merge requests found
Pipeline #17966 passed with stage
in 3 minutes and 28 seconds
......@@ -139,72 +139,17 @@ def vnf_scale(
)
def process_update_params(ctx, param, value):
update_dict = {}
args = value
for i in range(len(args)):
if args[i].lower() == "--updatetype":
if i + 1 >= len(args) or args[i + 1].startswith("--"):
raise ClientException("No updateType is provided")
else:
update_dict["updateType"] = args[i + 1]
if update_dict.get("updateType") == "OPERATE_VNF":
if i + 2 >= len(args) or args[i + 2].startswith("--"):
raise ClientException(
"Whether the operate vnf is start,stop or rebuild needs to be specified"
)
else:
update_dict["changeStateTo"] = args[i + 2]
if args[i] == "--vdu":
if i + 1 >= len(args) or args[i + 1].startswith("--"):
raise ClientException("No vdu-id is provided")
else:
update_dict["vdu_id"] = args[i + 1]
elif args[i] == "--count-index":
if i + 1 >= len(args) or args[i + 1].startswith("--"):
raise ClientException("No count-index is provided")
else:
update_dict["count-index"] = int(args[i + 1])
elif args[i] == "--run-day1":
if i + 1 >= len(args) or args[i + 1].startswith("--"):
raise ClientException("No count-index is provided")
else:
update_dict["run-day1"] = True
elif args[i] == "--vnf":
if i + 1 >= len(args) or args[i + 1].startswith("--"):
raise ClientException("No vnf is provided")
else:
update_dict["vnfInstanceId"] = args[i + 1]
elif args[i] == "--vnfd-name":
if i + 1 >= len(args) or args[i + 1].startswith("--"):
raise ClientException("No vnf is provided")
else:
update_dict["vnfdId"] = args[i + 1]
if not update_dict.get("updateType"):
raise ClientException("updateType should be specified")
allowed_update_types = (
"CHANGE_VNFPKG",
"REMOVE_VNF",
"OPERATE_VNF",
"VERTICAL_SCALE",
)
if update_dict["updateType"] not in allowed_update_types:
raise ClientException(
f"updateType should be one of the allowed types: {allowed_update_types}"
)
ctx.params["update_params"] = update_dict
return
@click.command(
name="ns-update",
context_settings=dict(
ignore_unknown_options=True,
),
@click.command(name="ns-update", short_help="executes an update of a Network Service.")
@click.argument("ns_name")
@click.option(
"--updatetype", required=True, type=str, help="available types: CHANGE_VNFPKG"
)
@click.argument("ns_name", required=True)
@click.argument(
"args", nargs=-1, type=click.UNPROCESSED, callback=process_update_params
@click.option(
"--config",
required=True,
type=str,
help="extra information for update operation as YAML/JSON inline string as --config"
" '{changeVnfPackageData:[{vnfInstanceId: xxx, vnfdId: yyy}]}'",
)
@click.option(
"--timeout", required=False, default=None, type=int, help="timeout in seconds"
......@@ -217,84 +162,26 @@ def process_update_params(ctx, param, value):
help="do not return the control immediately, but keep it until the operation is completed, or timeout",
)
@click.pass_context
def ns_update(ctx, ns_name, args, update_params, timeout, wait):
"""NS-Update - updates based on the updateType
NS_NAME: name or ID of the NS instance
updateType:CHANGEVNF_PKG
\b
Options:
--updateType CHANGE_VNFPKG
--vnf VNF instance ID or VNF id in the NS [required]
--vnfd-name VNFD ID or VNFD name [required]
updateType:REMOVE_VNF
\b
Options:
--updateType REMOVE_VNF
--vnf VNF instance ID or VNF id in the NS [required]
updateType:OPERATE_VNF
def ns_update(ctx, ns_name, updatetype, config, timeout, wait):
"""Executes an update of a Network Service.
\b
Options:
--updateType OPERATE_VNF (start, stop or rebuild) [required]
--vnf VNF instance ID or VNF id in the NS [required]
--vdu VDU-ID which should be operated [required]
--count-index count-index of the specfied VDU-ID [0 by Default]
--run-day1 True or False to run day1 operations [False by Default]
The update will check new revisions of the Network Functions that are part of the
Network Service, and it will update them if needed.
Sample update command: osm ns-update ns_instance_id --updatetype CHANGE_VNFPKG
--config '{changeVnfPackageData: [{vnfInstanceId: id_x,vnfdId: id_y}]}' --timeout 300 --wait
\b
Options:
--updateType VERTICAL_SCALE
--vnf VNF instance ID or VNF id in the NS [required]
--vnfd-name VNFD ID or VNFD name [required]
--vdu VDU-ID which should be vertical scaled [required]
\b
Example:
updateType: CHANGE_VNFPKG
osm ns-update NS_NAME|NS_ID --updateType CHANGE_VNFPKG --vnf MEMBER_VNF_INDEX|VNFINSTANCEID --vnfd-name VNFDID|VNFD_NAME
updateType: REMOVE_VNF
osm ns-update NS_NAME|NS_ID --updateType REMOVE_VNF --vnf MEMBER_VNF_INDEX|VNFINSTANCEID
updateType: OPERATE_VNF
osm ns-update NS_NAME|NS_ID --updateType OPERATE_VNF (start, stop or rebuild) --vdu VDUID --count-index COUNT_INDEX
--run-day1 True|False --vnf MEMBER_VNF_INDEX|VNFINSTANCEID
updateType: VERTICAL_SCALE
osm ns-update NS_NAME|NS_ID --updateType VERTICAL_SCALE --vnf MEMBER_VNF_INDEX|VNFINSTANCEID --vnfd-name VNFDID|VNFD_NAME
--vdu VDUID
NS_NAME: Network service instance name or ID.
"""
params = ctx.params["update_params"]
vnf_id = params["vnfInstanceId"]
if params.get("vnfdId"):
if not validate_uuid4(params.get("vnfdId")):
vnfd_list = ctx.obj.vnfd.get(params.get("vnfdId"))
params["vnfdId"] = vnfd_list["_id"]
else:
params["vnfdId"] = params["vnfdId"]
if not validate_uuid4(vnf_id):
vnf_filter = f"member-vnf-index-ref={vnf_id}"
vnf_list = ctx.obj.vnf.list(ns=ns_name, filter=vnf_filter)
if len(vnf_list) == 0:
raise ClientException(
f"No VNF found in NS {ns_name} with filter {vnf_filter}"
)
elif len(vnf_list) == 1:
params["vnfInstanceId"] = vnf_list[0]["_id"]
params["timeout"] = timeout
op_data = {
"timeout": timeout,
"updateType": updatetype,
}
if config:
op_data["config"] = yaml.safe_load(config)
utils.check_client_version(ctx.obj, ctx.command.name)
ctx.obj.ns.update(ns_name, params, wait=wait)
ctx.obj.ns.update(ns_name, op_data, wait=wait)
def process_common_heal_params(heal_vnf_dict, args):
......
......@@ -541,33 +541,21 @@ class Ns(object):
# Check update parameters availability according to update type
if op_data["updateType"] == "CHANGE_VNFPKG":
op_data["changeVnfPackageData"] = {}
op_data["changeVnfPackageData"]["vnfInstanceId"] = data.get(
"vnfInstanceId"
)
op_data["changeVnfPackageData"]["vnfdId"] = data.get("vnfdId")
elif op_data["updateType"] == "REMOVE_VNF":
op_data["removeVnfInstanceId"] = data.get("vnfInstanceId")
elif op_data["updateType"] == "OPERATE_VNF":
op_data["operateVnfData"] = {}
op_data["operateVnfData"]["vnfInstanceId"] = data.get("vnfInstanceId")
op_data["operateVnfData"]["changeStateTo"] = data.get("changeStateTo")
op_data["operateVnfData"]["additionalParam"] = {}
op_data["operateVnfData"]["additionalParam"]["vdu_id"] = data.get(
"vdu_id"
)
op_data["operateVnfData"]["additionalParam"]["count-index"] = data.get(
"count-index", 0
)
op_data["operateVnfData"]["additionalParam"]["run-day1"] = data.get(
"run-day1", False
)
elif op_data["updateType"] == "VERTICAL_SCALE":
op_data["verticalScaleVnf"] = {}
op_data["verticalScaleVnf"]["vnfInstanceId"] = data.get("vnfInstanceId")
op_data["verticalScaleVnf"]["vnfdId"] = data.get("vnfdId")
op_data["verticalScaleVnf"]["vduId"] = data.get("vdu_id")
op_data["verticalScaleVnf"]["countIndex"] = 0
if not (
data["config"]["changeVnfPackageData"][0].get("vnfInstanceId")
and data["config"]["changeVnfPackageData"][0].get("vnfdId")
):
raise ClientException("you must set both vnfInstanceId and vnfdId")
# Fill up op_data
op_data["changeVnfPackageData"] = {}
op_data["changeVnfPackageData"]["vnfInstanceId"] = data["config"][
"changeVnfPackageData"
][0].get("vnfInstanceId")
op_data["changeVnfPackageData"]["vnfdId"] = data["config"][
"changeVnfPackageData"
][0].get("vnfdId")
if data.get("timeout"):
op_data["timeout_ns_update"] = data["timeout"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment