Adding PlanetLab resources
[nepi.git] / src / nepi / execution / attribute.py
index 1282dfe..8203306 100644 (file)
@@ -1,9 +1,27 @@
+"""
+    NEPI, a framework to manage network experiments
+    Copyright (C) 2013 INRIA
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+"""
 
 ### Attribute Types
 class Types:
     String  = "STRING"
     Bool    = "BOOL"
-    Enum    = "ENUM"
+    Enumerate    = "ENUM"
     Double  = "DOUBLE"
     Integer = "INTEGER"
 
@@ -17,16 +35,19 @@ class Flags:
     ExecReadOnly        = 0x02
     # Attribute is an access credential
     Credential      = 0x04
+    # Attribute is a filter used to discover resources
+    Filter      = 0x08
 
 class Attribute(object):
     def __init__(self, name, help, type = Types.String,
             flags = Flags.NoFlags, default = None, allowed = None,
-            set_hook = None):
+            range = None, set_hook = None):
         self._name = name
         self._help = help
         self._type = type
         self._flags = flags
         self._allowed = allowed
+        self._range = range
         self._default = self._value = default
         # callback to be invoked upon changing the 
         # attribute value
@@ -56,6 +77,10 @@ class Attribute(object):
     def allowed(self):
         return self._allowed
 
+    @property
+    def range(self):
+        return self._range
+
     def has_flag(self, flag):
         return (self._flags & flag) == flag
 
@@ -65,8 +90,12 @@ class Attribute(object):
     def set_value(self, value):
         valid = True
 
-        if self.type == Types.Enum:
+        if self.type == Types.Enumerate:
             valid = value in self._allowed
+
+        if self.type in [Types.Double, Types.Integer] and self.range:
+            (min, max) = self.range
+            valid = (value >= min and value <= max) 
         
         valid = valid and self.is_valid_value(value)