Add `osm ns-update` command
[osm/osmclient.git] / osmclient / sol005 / ns.py
index f4366b2..e1a4f69 100644 (file)
@@ -471,6 +471,54 @@ class Ns(object):
             )
             raise ClientException(message)
 
+    def update(self, ns_name, data, wait=False):
+        """Update NS instance.
+
+        This function calls the NBI in order to perform an update operation
+        on a Network Service instance.
+
+        Args:
+            ns_name: (str)
+            data: (dict)
+            wait: (boolean)
+
+        Returns:
+            None
+
+        """
+        self._logger.debug("")
+        self._client.get_token()
+        try:
+            op_data = {"updateType": data.pop("updateType")}
+
+            # Check update parameters availability according to update type
+            if op_data["updateType"] == "CHANGE_VNFPKG":
+                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"]
+
+            op_id = self.exec_op(ns_name, op_name="update", op_data=op_data, wait=wait)
+            print(str(op_id))
+
+        except ClientException as exc:
+            message = "failed to update ns {}:\nerror:\n{}".format(ns_name, str(exc))
+            raise ClientException(message)
+
     def create_alarm(self, alarm):
         self._logger.debug("")
         self._client.get_token()