JIRA Issue DOMINO-20 71/24571/1
authorUlas Kozat <ulas.kozat@gmail.com>
Sat, 19 Nov 2016 04:25:43 +0000 (20:25 -0800)
committerUlas Kozat <ulas.kozat@gmail.com>
Sat, 19 Nov 2016 04:25:43 +0000 (20:25 -0800)
Change-Id: I86a2b72d36c5807f384d39bd72305b9b4b36835c
Signed-off-by: Ulas Kozat <ulas.kozat@gmail.com>
lib/partitioner/partitioner.py
tests/test_partitioner.py

index 5177b1b..75adc63 100644 (file)
@@ -27,7 +27,7 @@ def partition_tosca(filepath, nodesite, tpl):
   for node in nodesite:
    for site in sitenodes:
      if node not in sitenodes[site]:
-       del tpl_local[site]['topology_template']['node_templates'][node] 
+       tpl_local[site]['topology_template']['node_templates'].pop(node,None) 
        rm_dependents(tpl_local[site]['topology_template']['node_templates'] , node)
        #remove from policy targets 
        if tpl_local[site]['topology_template'].has_key('policies'):
@@ -38,10 +38,10 @@ def partition_tosca(filepath, nodesite, tpl):
              # remove the rule if there is no target left!
              if len(rule[key]['targets']) is 0:
                tpl_local[site]['topology_template']['policies'].remove(rule)
-
   for site in sitenodes:
     tpl_l = tpl_local[site]
-    print tpl_l , '\n'
+    rm_orphans(tpl_l)
     file_paths[site] = filepath + '_part' + str(site) + '.yaml'
     fout = open(file_paths[site],'w')
  
@@ -125,3 +125,15 @@ def rm_dependents(node_template , node):
   #remove the dependents
   for i in range(len(del_list)):
      del node_template[del_list[i]]
+
+def rm_orphans(tpl):
+  nodes = tpl['topology_template']['node_templates']
+  keep_list = []
+  for node in nodes:
+    if nodes[node].has_key('requirements'):
+      for i in range(len(nodes[node]['requirements'])):
+        if nodes[node]['requirements'][i].has_key('virtualLink'):
+          keep_list.append(nodes[node]['requirements'][i]['virtualLink']['node'])
+  for node in list(nodes):   
+    if (nodes[node]['type'] == 'tosca.nodes.nfv.VL') and (node not in keep_list):
+      del nodes[node]
index 246f6ba..75ec817 100755 (executable)
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 
-import sys, os, glob
+import sys, os, glob, yaml
 
 sys.path.insert(0, glob.glob('./lib')[0])
 
-from toscaparser.tosca_template import ToscaTemplate
+#from toscaparser.tosca_template import ToscaTemplate
 
 from mapper import *
 from partitioner import *
 
 def main(argv):
   try:
-    tosca = ToscaTemplate(argv[0])
+    #tosca = ToscaTemplate(argv[0])
+    tpl = yaml.load(file(argv[0],'r'))
     # Extract Labels
-    node_labels = label.extract_labels( tosca )
+    node_labels = label.extract_labels( tpl )
     print node_labels
     site_id = 0
     subscribed_labels = {}
@@ -40,10 +41,11 @@ def main(argv):
     node_site = label.select_site( site_map )
     print node_site
 
-    file_paths = partitioner.partition_tosca("./tests/tmp/tosca",node_site,tosca.tpl)
+    file_paths = partitioner.partition_tosca("./tests/tmp/tosca",node_site,tpl)
     print file_paths
   except:
     print('Unexpected error: %s', sys.exc_info()[0])
 
 if __name__ == "__main__":
    main(sys.argv[1:])
+