Added timeframe for PlanetLabe nodes statistics as a user configurable attribute.
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 29 May 2012 16:55:05 +0000 (18:55 +0200)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 29 May 2012 16:55:05 +0000 (18:55 +0200)
src/nepi/testbeds/planetlab/metadata.py
src/nepi/testbeds/planetlab/node.py

index e69f3e7..5e07320 100644 (file)
@@ -1042,7 +1042,19 @@ attributes = dict({
                 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
                 "validation_function": validation.is_number,
             }),
-            
+     "timeframe": dict({
+                "name": "timeframe",
+                "help": "Past time period in which to check information about the node. Values are year,month, week, latest", 
+                "type": Attribute.ENUM, 
+                "value": "week",
+                "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
+                "allowed": ["latest",
+                            "week",
+                            "month",
+                            "year"],
+                "validation_function": validation.is_enum,
+            }),
+           
     "up": dict({
                 "name": "up",
                 "help": "Link up",
@@ -1409,6 +1421,7 @@ factories_info = dict({
                 "max_load",
                 "min_cpu",
                 "max_cpu",
+                "timeframe",
                 
                 # NEPI-in-NEPI attributes
                 ATTR_NEPI_TESTBED_ENVIRONMENT_SETUP,
@@ -1768,7 +1781,7 @@ testbed_attributes = dict({
         "pl_log_level": dict({      
             "name": "plLogLevel",
             "help": "Verbosity of logging of planetlab events.",
-            "value": "ERROR",
+            "value": "INFO",
             "type": Attribute.ENUM, 
             "allowed": ["DEBUG",
                         "INFO",
index 41205e5..c4cb016 100644 (file)
@@ -113,7 +113,7 @@ class Node(object):
         self.maxLoad = None
         self.min_num_external_ifaces = None
         self.max_num_external_ifaces = None
-        self.timeframe = 'm'
+        self._timeframe = 'w'
         
         # Applications and routes add requirements to connected nodes
         self.required_packages = set()
@@ -140,6 +140,27 @@ class Node(object):
 
         # Logging
         self._logger = logging.getLogger('nepi.testbeds.planetlab')
+
+    def set_timeframe(self, timeframe):
+        if timeframe == "latest":
+            self._timeframe = ""
+        elif timeframe == "month":
+            self._timeframe = "m"
+        elif timeframe == "year":
+            self._timeframe = "y"
+        else:
+            self._timeframe = "w"
+
+    def get_timeframe(self):
+        if self._timeframe == "":
+            return "latest"
+        if self._timeframe == "m":
+            return "month"
+        if self._timeframe == "y":
+            return "year"
+        return "week"
+
+    timeframe = property(get_timeframe, set_timeframe)
     
     def _nepi_testbed_environment_setup_get(self):
         command = cStringIO.StringIO()
@@ -154,8 +175,10 @@ class Node(object):
                 for envval in envvals:
                     command.write(' ; export %s=%s' % (envkey, envval))
         return command.getvalue()
+
     def _nepi_testbed_environment_setup_set(self, value):
         pass
+
     _nepi_testbed_environment_setup = property(
         _nepi_testbed_environment_setup_get,
         _nepi_testbed_environment_setup_set)
@@ -179,7 +202,7 @@ class Node(object):
         self._logger.info("Finding candidates for %s", self.make_filter_description())
         
         fields = ('node_id',)
-        replacements = {'timeframe':self.timeframe}
+        replacements = {'timeframe':self._timeframe}
         
         # get initial candidates (no tag filters)
         basefilters = self.build_filters({}, self.BASEFILTERS)
@@ -210,9 +233,9 @@ class Node(object):
             if attr in applicable:
                 tagfilter = rootfilters.copy()
                 tagfilter['tagname'] = tagname % replacements
-                tagfilter[expr % replacements] = getattr(self,attr)
+                tagfilter[expr % replacements] = str(getattr(self,attr))
                 tagfilter['node_id'] = list(candidates)
-                
+              
                 candidates &= set(map(operator.itemgetter('node_id'),
                     self._sliceapi.GetNodeTags(filters=tagfilter, fields=fields)))
 
@@ -346,7 +369,7 @@ class Node(object):
     def rate_nodes(self, nodes):
         rates = collections.defaultdict(int)
         tags = collections.defaultdict(dict)
-        replacements = {'timeframe':self.timeframe}
+        replacements = {'timeframe':self._timeframe}
         tagnames = [ tagname % replacements 
                      for tagname, weight, default in self.RATE_FACTORS ]
        
@@ -381,9 +404,9 @@ class Node(object):
         orig_attrs['max_num_external_ifaces'] = self.max_num_external_ifaces
         self.min_num_external_ifaces = None
         self.max_num_external_ifaces = None
-        self.timeframe = 'm'
+        if not self._timeframe: self._timeframe = 'w'
         
-        replacements = {'timeframe':self.timeframe}
+        replacements = {'timeframe':self._timeframe}
 
         for attr, tag in self.BASEFILTERS.iteritems():
             if tag in info: