From b542aacf53646d3162ff56677efb20d16f1ef8f1 Mon Sep 17 00:00:00 2001 From: Alina Quereilhac Date: Mon, 23 May 2011 19:22:07 +0200 Subject: [PATCH] added category to attributes --- examples/vlc_wireless_netns_ns3.py | 4 +-- src/nepi/core/attributes.py | 16 +++++++++-- src/nepi/core/design.py | 11 +++---- src/nepi/core/execute.py | 5 ++-- src/nepi/core/metadata.py | 46 +++++++++++++++++++++--------- 5 files changed, 56 insertions(+), 26 deletions(-) diff --git a/examples/vlc_wireless_netns_ns3.py b/examples/vlc_wireless_netns_ns3.py index eddefae5..45eb72d4 100644 --- a/examples/vlc_wireless_netns_ns3.py +++ b/examples/vlc_wireless_netns_ns3.py @@ -201,8 +201,8 @@ class VlcWirelessNetnsNs3Example(object): #xterm2.connector("node").connect(node4.connector("apps")) ## testbed_interconnection - fdnd1.connector("fd").connect(tap1.connector("fd")) - fdnd2.connector("fd").connect(tap2.connector("fd")) + fdnd1.connector("->fd").connect(tap1.connector("fd->")) + fdnd2.connector("->fd").connect(tap2.connector("fd->")) self.add_route(node4, "10.0.0.0", 24, "10.0.2.1") self.add_route(node4, "10.0.1.0", 24, "10.0.2.1") diff --git a/src/nepi/core/attributes.py b/src/nepi/core/attributes.py index 5072c1b1..321e5c9d 100644 --- a/src/nepi/core/attributes.py +++ b/src/nepi/core/attributes.py @@ -39,7 +39,8 @@ class Attribute(object): HasNoDefaultValue = 0x08 def __init__(self, name, help, type, value = None, range = None, - allowed = None, flags = NoFlags, validation_function = None): + allowed = None, flags = NoFlags, validation_function = None, + category = None): if not type in Attribute.types: raise AttributeError("invalid type %s " % type) self._name = name @@ -53,6 +54,7 @@ class Attribute(object): self._allowed = allowed self._validation_function = validation_function self._modified = False + self._category = category @property def name(self): @@ -91,6 +93,10 @@ class Attribute(object): def modified(self): return self._modified + @property + def category(self): + return self._category + @property def range(self): return self._range @@ -167,6 +173,9 @@ class AttributesMap(object): def get_attribute_allowed(self, name): return self._attributes[name].allowed + def get_attribute_category(self, name): + return self._attributes[name].category + def is_attribute_read_only(self, name): return self._attributes[name].read_only @@ -186,11 +195,12 @@ class AttributesMap(object): return self._attributes[name].is_valid_value(value) def add_attribute(self, name, help, type, value = None, range = None, - allowed = None, flags = Attribute.NoFlags, validation_function = None): + allowed = None, flags = Attribute.NoFlags, validation_function = None, + category = None): if name in self._attributes: raise AttributeError("Attribute %s already exists" % name) attribute = Attribute(name, help, type, value, range, allowed, flags, - validation_function) + validation_function, category) self._attributes[name] = attribute def del_attribute(self, name): diff --git a/src/nepi/core/design.py b/src/nepi/core/design.py index 50a8133f..50e00c16 100644 --- a/src/nepi/core/design.py +++ b/src/nepi/core/design.py @@ -200,7 +200,7 @@ class Box(AttributesMap): for attr in factory.box_attributes.attributes: self.add_attribute(attr.name, attr.help, attr.type, attr.value, attr.range, attr.allowed, attr.flags, - attr.validation_function) + attr.validation_function, attr.category) for attr in factory.attributes: if attr.modified: self._factory_attributes[attr.name] = attr.value @@ -326,7 +326,7 @@ class UserRoutableMixin(RoutableMixin): return route def delete_route(self, route): - self._route.remove(route) + self._routes.remove(route) del route def destroy(self): @@ -453,9 +453,10 @@ class Factory(AttributesMap): self._traces.append(trace) def add_box_attribute(self, name, help, type, value = None, range = None, - allowed = None, flags = Attribute.NoFlags, validation_function = None): + allowed = None, flags = Attribute.NoFlags, validation_function = None, + category = None): self._box_attributes.add_attribute(name, help, type, value, range, - allowed, flags, validation_function) + allowed, flags, validation_function, category) def create(self, guid, testbed_description): return self._factory(guid, self, testbed_description.guid) @@ -509,7 +510,7 @@ class TestbedDescription(AttributesMap): for attr in metadata.testbed_attributes().attributes: self.add_attribute(attr.name, attr.help, attr.type, attr.value, attr.range, attr.allowed, attr.flags, - attr.validation_function) + attr.validation_function, attr.category) @property def guid(self): diff --git a/src/nepi/core/execute.py b/src/nepi/core/execute.py index 1b52335f..67e5ebca 100644 --- a/src/nepi/core/execute.py +++ b/src/nepi/core/execute.py @@ -165,9 +165,10 @@ class Factory(AttributesMap): self._traces.append(trace_id) def add_box_attribute(self, name, help, type, value = None, range = None, - allowed = None, flags = Attribute.NoFlags, validation_function = None): + allowed = None, flags = Attribute.NoFlags, validation_function = None, + category = None): self._box_attributes.add_attribute(name, help, type, value, range, - allowed, flags, validation_function) + allowed, flags, validation_function, category) class TestbedController(object): def __init__(self, testbed_id, testbed_version): diff --git a/src/nepi/core/metadata.py b/src/nepi/core/metadata.py index 46ee1a2f..4ae57a18 100644 --- a/src/nepi/core/metadata.py +++ b/src/nepi/core/metadata.py @@ -7,6 +7,9 @@ import getpass from nepi.util import validation from nepi.util.constants import ATTR_NEPI_TESTBED_ENVIRONMENT_SETUP, DeploymentConfiguration +# Attribute categories +CATEGORY_DEPLOYMENT = "Deployment" + class VersionedMetadataInfo(object): @property def connector_types(self): @@ -47,6 +50,7 @@ class VersionedMetadataInfo(object): "allowed": array of posible values, "flags": attributes flags, "validation_function": validation function for the attribute + "category": category for the attribute }) """ raise NotImplementedError @@ -147,6 +151,7 @@ class VersionedMetadataInfo(object): "allowed": array of posible values, "flags": attributes flags, "validation_function": validation function for the attribute + "category": category for the attribute }) ] """ @@ -174,7 +179,7 @@ class Metadata(object): help = "Path to the directory where traces and other files will be stored", type = Attribute.STRING, value = "", - flags = Attribute.DesignOnly, + flags = Attribute.DesignOnly )), ) @@ -186,6 +191,7 @@ class Metadata(object): help = "Shell commands to run before spawning TestbedController processes", type = Attribute.STRING, flags = Attribute.DesignOnly, + category = CATEGORY_DEPLOYMENT, )), (DC.DEPLOYMENT_MODE, dict(name = DC.DEPLOYMENT_MODE, help = "Instance execution mode", @@ -196,7 +202,8 @@ class Metadata(object): DC.MODE_SINGLE_PROCESS ], flags = Attribute.DesignOnly, - validation_function = validation.is_enum + validation_function = validation.is_enum, + category = CATEGORY_DEPLOYMENT, )), (DC.DEPLOYMENT_COMMUNICATION, dict(name = DC.DEPLOYMENT_COMMUNICATION, help = "Instance communication mode", @@ -207,48 +214,55 @@ class Metadata(object): DC.ACCESS_SSH ], flags = Attribute.DesignOnly, - validation_function = validation.is_enum + validation_function = validation.is_enum, + category = CATEGORY_DEPLOYMENT, )), (DC.DEPLOYMENT_HOST, dict(name = DC.DEPLOYMENT_HOST, help = "Host where the testbed will be executed", type = Attribute.STRING, value = "localhost", flags = Attribute.DesignOnly, - validation_function = validation.is_string + validation_function = validation.is_string, + category = CATEGORY_DEPLOYMENT, )), (DC.DEPLOYMENT_USER, dict(name = DC.DEPLOYMENT_USER, help = "User on the Host to execute the testbed", type = Attribute.STRING, value = getpass.getuser(), flags = Attribute.DesignOnly, - validation_function = validation.is_string + validation_function = validation.is_string, + category = CATEGORY_DEPLOYMENT, )), (DC.DEPLOYMENT_KEY, dict(name = DC.DEPLOYMENT_KEY, help = "Path to SSH key to use for connecting", type = Attribute.STRING, flags = Attribute.DesignOnly, - validation_function = validation.is_string + validation_function = validation.is_string, + category = CATEGORY_DEPLOYMENT, )), (DC.DEPLOYMENT_PORT, dict(name = DC.DEPLOYMENT_PORT, help = "Port on the Host", type = Attribute.INTEGER, value = 22, flags = Attribute.DesignOnly, - validation_function = validation.is_integer + validation_function = validation.is_integer, + category = CATEGORY_DEPLOYMENT, )), (DC.ROOT_DIRECTORY, dict(name = DC.ROOT_DIRECTORY, help = "Root directory for storing process files", type = Attribute.STRING, value = ".", flags = Attribute.DesignOnly, - validation_function = validation.is_string # TODO: validation.is_path + validation_function = validation.is_string, # TODO: validation.is_path + category = CATEGORY_DEPLOYMENT, )), (DC.USE_AGENT, dict(name = DC.USE_AGENT, help = "Use -A option for forwarding of the authentication agent, if ssh access is used", type = Attribute.BOOL, value = False, flags = Attribute.DesignOnly, - validation_function = validation.is_bool + validation_function = validation.is_bool, + category = CATEGORY_DEPLOYMENT, )), (DC.LOG_LEVEL, dict(name = DC.LOG_LEVEL, help = "Log level for instance", @@ -259,14 +273,16 @@ class Metadata(object): DC.DEBUG_LEVEL ], flags = Attribute.DesignOnly, - validation_function = validation.is_enum + validation_function = validation.is_enum, + category = CATEGORY_DEPLOYMENT, )), (DC.RECOVER, dict(name = DC.RECOVER, help = "Do not intantiate testbeds, rather, reconnect to already-running instances. Used to recover from a dead controller.", type = Attribute.BOOL, value = False, flags = Attribute.DesignOnly, - validation_function = validation.is_bool + validation_function = validation.is_bool, + category = CATEGORY_DEPLOYMENT, )), ) @@ -360,8 +376,9 @@ class Metadata(object): flags = attr_info["flags"] if "flags" in attr_info \ else Attribute.NoFlags validation_function = attr_info["validation_function"] + category = attr_info["category"] if "category" in attr_info else None attributes.add_attribute(name, help, type, value, - range, allowed, flags, validation_function) + range, allowed, flags, validation_function, category) return attributes @@ -464,12 +481,13 @@ class Metadata(object): and attr_info["flags"] != None \ else Attribute.NoFlags validation_function = attr_info["validation_function"] + category = attr_info["category"] if "category" in attr_info else None if box_attributes: factory.add_box_attribute(name, help, type, value, range, - allowed, flags, validation_function) + allowed, flags, validation_function, category) else: factory.add_attribute(name, help, type, value, range, - allowed, flags, validation_function) + allowed, flags, validation_function, category) def _add_design_traces(self, factory, info): if "traces" in info: -- 2.45.2