Fixing SFC

Fixes the changes made in RO to allow SFC to be working again.
Takes care of the dependencies when deleting the different parts,
such as SFIs, SFs, Classifications and SFPs.

Change-Id: Ifc408fae6ea33b6e1c7c0096106150069b62cc91
Signed-off-by: Eduardo Sousa <esousa@whitestack.com>
diff --git a/osm_ro/vim_thread.py b/osm_ro/vim_thread.py
index 089e7b9..388b4d0 100644
--- a/osm_ro/vim_thread.py
+++ b/osm_ro/vim_thread.py
@@ -1063,15 +1063,14 @@
     def new_sfi(self, task):
         vim_sfi_id = None
         try:
-            params = task["params"]
+            dep_id = "TASK-" + str(task["extra"]["depends_on"][0])
             task_id = task["instance_action_id"] + "." + str(task["task_index"])
-            depends = task.get("depends")
             error_text = ""
-            interfaces = task.get("depends").values()[0].get("extra").get("params")[5]
+            interfaces = task.get("depends").get(dep_id).get("extra").get("interfaces").keys()
             # At the moment, every port associated with the VM will be used both as ingress and egress ports.
             # Bear in mind that different VIM connectors might support SFI differently. In the case of OpenStack, only the
             # first ingress and first egress ports will be used to create the SFI (Port Pair).
-            port_id_list = [interfaces[0].get("vim_id")]
+            port_id_list = [interfaces[0]]
             name = "sfi-%s" % task["item_id"][:8]
             # By default no form of IETF SFC Encapsulation will be used
             vim_sfi_id = self.vim.new_sfi(name, port_id_list, port_id_list, sfc_encap=False)
@@ -1112,12 +1111,11 @@
     def new_sf(self, task):
         vim_sf_id = None
         try:
-            params = task["params"]
             task_id = task["instance_action_id"] + "." + str(task["task_index"])
-            depends = task.get("depends")
             error_text = ""
+            depending_tasks = [ "TASK-" + str(dep_id) for dep_id in task["extra"]["depends_on"]]
             #sfis = task.get("depends").values()[0].get("extra").get("params")[5]
-            sfis = task.get("depends").values()
+            sfis = [task.get("depends").get(dep_task) for dep_task in depending_tasks]
             sfi_id_list = []
             for sfi in sfis:
                 sfi_id_list.append(sfi.get("vim_id"))
@@ -1163,9 +1161,9 @@
         try:
             params = task["params"]
             task_id = task["instance_action_id"] + "." + str(task["task_index"])
-            depends = task.get("depends")
+            depending_task = "TASK-" + str(task.get("extra").get("depends_on")[0])
             error_text = ""
-            interfaces = task.get("depends").values()[0].get("extra").get("params")[5]
+            interfaces = task.get("depends").get(depending_task).get("vim_interfaces").keys()
             # Bear in mind that different VIM connectors might support Classifications differently.
             # In the case of OpenStack, only the first VNF attached to the classifier will be used
             # to create the Classification(s) (the "logical source port" of the "Flow Classifier").
@@ -1187,7 +1185,7 @@
             if '/' not in destination_ip:
                 destination_ip += '/32'
             definition = {
-                    "logical_source_port": interfaces[0].get("vim_id"),
+                    "logical_source_port": interfaces[0],
                     "protocol": ip_proto,
                     "source_ip_prefix": source_ip,
                     "destination_ip_prefix": destination_ip,
@@ -1238,12 +1236,11 @@
         try:
             params = task["params"]
             task_id = task["instance_action_id"] + "." + str(task["task_index"])
-            depends = task.get("depends")
+            depending_tasks = [task.get("depends").get("TASK-" + str(tsk_id)) for tsk_id in task.get("extra").get("depends_on")]
             error_text = ""
-            deps = task.get("depends").values()
             sf_id_list = []
             classification_id_list = []
-            for dep in deps:
+            for dep in depending_tasks:
                 vim_id = dep.get("vim_id")
                 resource = dep.get("item")
                 if resource == "instance_sfs":