Renamed ns-scale-vdu to vnf-scale. Refactored scale code from osm.py to ns.py 73/6973/2
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Tue, 27 Nov 2018 12:28:57 +0000 (13:28 +0100)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Tue, 27 Nov 2018 14:18:14 +0000 (15:18 +0100)
Change-Id: Ifd16183f02a7f4b7e8a7cab3bba84de611f0b671
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osmclient/scripts/osm.py
osmclient/sol005/ns.py

index 1fe8c36..625defe 100755 (executable)
@@ -1567,9 +1567,9 @@ def ns_action(ctx,
         exit(1)
 
 
-@cli.command(name='ns-scale-vdu')
+@cli.command(name='vnf-scale')
 @click.argument('ns_name' )
-@click.option('--vnf-name', prompt=True, help="member-vnf-index to scale")
+@click.option('vnf-name', prompt=True, help="member-vnf-index to scale")
 @click.option('--scaling-group', prompt=True, help="scaling-group-descriptor name to use")
 @click.option('--scale-in', default=False, is_flag=True, help="performs a scale in operation")
 @click.option('--scale-out', default=False, is_flag=True, help="performs a scale out operation (by default)")
@@ -1580,28 +1580,16 @@ def ns_scale_vdu(ctx,
               scaling_group,
               scale_in,
               scale_out):
-    """executes a VNF VDU scale over a NS instance
+    """executes a VNF scale (adding/removing VDUs)
 
     NS_NAME: name or ID of the NS instance
+    VNF_NAME: member-vnf-index in the NS to be scaled
     """
     try:
         check_client_version(ctx.obj, ctx.command.name)
-        op_data={}
         if not scale_in and not scale_out:
             scale_out = True
-            # print("You must provide scale type with option '--vnf-scale-in' or '--vnf-scale-out'")
-            # exit(1)
-        op_data["scaleType"] = "SCALE_VNF"
-        op_data["scaleVnfData"] = {}
-        if scale_in:
-            op_data["scaleVnfData"]["scaleVnfType"] = "SCALE_IN"
-        else:
-            op_data["scaleVnfData"]["scaleVnfType"] = "SCALE_OUT"
-        op_data["scaleVnfData"]["scaleByStepData"] = {
-            "member-vnf-index": vnf_name,
-            "scaling-group-descriptor": scaling_group,
-        }
-        ctx.obj.ns.exec_op(ns_name, op_name='scale', op_data=op_data)
+        ctx.obj.ns.scale_vnf(ns_name, vnf_name, scaling_group, scale_in, scale_out)
     except ClientException as inst:
         print((inst.message))
         exit(1)
index 387bcd5..bda7c3e 100644 (file)
@@ -287,6 +287,27 @@ class Ns(object):
                     exc.message)
             raise ClientException(message)
 
+    def scale_vnf(self, ns_name, vnf_name, scaling_group, scale_in, scale_out):
+        """Scales a VNF by adding/removing VDUs
+        """
+        try:
+            op_data={}
+            op_data["scaleType"] = "SCALE_VNF"
+            op_data["scaleVnfData"] = {}
+            if scale_in:
+                op_data["scaleVnfData"]["scaleVnfType"] = "SCALE_IN"
+            else:
+                op_data["scaleVnfData"]["scaleVnfType"] = "SCALE_OUT"
+            op_data["scaleVnfData"]["scaleByStepData"] = {
+                "member-vnf-index": vnf_name,
+                "scaling-group-descriptor": scaling_group,
+            }
+            self.exec_op(ns_name, op_name='scale', op_data=op_data)
+        except ClientException as exc:
+            message="failed to scale vnf {} of ns {}:\nerror:\n{}".format(
+                    vnf_name, ns_name, exc.message)
+            raise ClientException(message)
+
     def create_alarm(self, alarm):
         data = {}
         data["create_alarm_request"] = {}