Merging with HEAD
[nepi.git] / src / nepi / core / testbed_impl.py
index dbe944f..92cfb93 100644 (file)
@@ -12,9 +12,11 @@ from nepi.util.constants import STATUS_UNDETERMINED, TIME_NOW, \
     TESTBED_STATUS_CROSS_CONNECTED, \
     TESTBED_STATUS_CONFIGURED, \
     TESTBED_STATUS_STARTED, \
-    TESTBED_STATUS_STOPPED
+    TESTBED_STATUS_STOPPED,\
+    CONNECTION_DELAY
 
 import collections
+import copy
 
 class TestbedController(execute.TestbedController):
     def __init__(self, testbed_id, testbed_version):
@@ -204,27 +206,38 @@ class TestbedController(execute.TestbedController):
         self._status = TESTBED_STATUS_CREATED
 
     def _do_connect(self, init = True):
-        for guid1, connections in self._connect.iteritems():
-            factory1 = self._get_factory(guid1)
-            for connector_type_name1, connections2 in connections.iteritems():
-                connector_type1 = factory1.connector_type(connector_type_name1)
-                for guid2, connector_type_name2 in connections2.iteritems():
-                    factory_id2 = self._create[guid2]
-                    # Connections are executed in a "From -> To" direction only
-                    # This explicitly ignores the "To -> From" (mirror) 
-                    # connections of every connection pair.
-                    if init:
-                        connect_code = connector_type1.connect_to_init_code(
-                                self._testbed_id, factory_id2, 
-                                connector_type_name2,
-                                False)
-                    else:
-                        connect_code = connector_type1.connect_to_compl_code(
-                                self._testbed_id, factory_id2, 
-                                connector_type_name2,
-                                False)
-                    if connect_code:
-                        connect_code(self, guid1, guid2)
+        unconnected = copy.deepcopy(self._connect)
+        
+        while unconnected:
+            for guid1, connections in unconnected.items():
+                factory1 = self._get_factory(guid1)
+                for connector_type_name1, connections2 in connections.items():
+                    connector_type1 = factory1.connector_type(connector_type_name1)
+                    for guid2, connector_type_name2 in connections2.items():
+                        factory_id2 = self._create[guid2]
+                        # Connections are executed in a "From -> To" direction only
+                        # This explicitly ignores the "To -> From" (mirror) 
+                        # connections of every connection pair.
+                        if init:
+                            connect_code = connector_type1.connect_to_init_code(
+                                    self._testbed_id, factory_id2, 
+                                    connector_type_name2,
+                                    False)
+                        else:
+                            connect_code = connector_type1.connect_to_compl_code(
+                                    self._testbed_id, factory_id2, 
+                                    connector_type_name2,
+                                    False)
+                        delay = None
+                        if connect_code:
+                            delay = connect_code(self, guid1, guid2)
+
+                        if delay is not CONNECTION_DELAY:
+                            del unconnected[guid1][connector_type_name1][guid2]
+                    if not unconnected[guid1][connector_type_name1]:
+                        del unconnected[guid1][connector_type_name1]
+                if not unconnected[guid1]:
+                    del unconnected[guid1]
 
     def do_connect_init(self):
         self._do_connect()
@@ -445,22 +458,46 @@ class TestbedController(execute.TestbedController):
 
     def trace(self, guid, trace_id, attribute='value'):
         if attribute == 'value':
-            fd = open("%s" % self.trace_filename(guid, trace_id), "r")
+            fd = open("%s" % self.trace_filepath(guid, trace_id), "r")
             content = fd.read()
             fd.close()
         elif attribute == 'path':
-            content = self.trace_filename(guid, trace_id)
+            content = self.trace_filepath(guid, trace_id)
+        elif attribute == 'size':
+            content = str(self.traces_filesize(guid, trace_id))
         else:
             content = None
         return content
 
-    def trace_filename(self, guid, trace_id):
+    def traces_info(self):
+        traces_info = dict()
+        host = self._attributes.get_attribute_value("deployment_host")
+        for guid, trace_list in self._add_trace.iteritems(): 
+            traces_info[guid] = dict()
+            for trace_id in trace_list:
+                traces_info[guid][trace_id] = dict()
+                filepath = self.trace(guid, trace_id, attribute = "path")
+                # TODO: Filesize!
+                # filesize = self.trace(guid, trace_id)
+                filesize = -1
+                traces_info[guid][trace_id]["host"] = host
+                traces_info[guid][trace_id]["filepath"] = filepath
+                traces_info[guid][trace_id]["filesize"] = str(filesize)
+        return traces_info
+
+    def trace_filepath(self, guid, trace_id):
         """
         Return a trace's file path, for TestbedController's default 
         implementation of trace()
         """
         raise NotImplementedError
 
+    def trace_filesize(self, guid, trace_id):
+        """
+        Return a trace's filesize in bytes
+        """
+        raise NotImplementedError
+
     #shutdown: NotImplementedError
 
     def get_connected(self, guid, connector_type_name,