2 # -*- coding: utf-8 -*-
4 from constants import TESTBED_ID
5 from nepi.core import testbed_impl
6 from nepi.util.constants import TIME_NOW
9 class TestbedController(testbed_impl.TestbedController):
10 from nepi.util.tunchannel_impl import TunChannel
12 def __init__(self, testbed_version):
13 super(TestbedController, self).__init__(TESTBED_ID, testbed_version)
15 self._home_directory = None
19 def home_directory(self):
20 return self._home_directory
27 self._home_directory = self._attributes.\
28 get_attribute_value("homeDirectory")
29 self._netns = self._load_netns_module()
30 super(TestbedController, self).do_setup()
32 def set(self, guid, name, value, time = TIME_NOW):
33 super(TestbedController, self).set(guid, name, value, time)
34 # TODO: take on account schedule time for the task
35 factory_id = self._create[guid]
36 factory = self._factories[factory_id]
37 if factory.box_attributes.is_attribute_design_only(name):
39 element = self._elements.get(guid)
41 setattr(element, name, value)
43 def get(self, guid, name, time = TIME_NOW):
44 value = super(TestbedController, self).get(guid, name, time)
45 # TODO: take on account schedule time for the task
46 factory_id = self._create[guid]
47 factory = self._factories[factory_id]
48 if factory.box_attributes.is_attribute_design_only(name):
50 element = self._elements.get(guid)
52 return getattr(element, name)
53 except KeyError, AttributeError:
56 def action(self, time, guid, action):
57 raise NotImplementedError
60 for guid, traces in self._traces.iteritems():
61 for trace_id, (trace, filename) in traces.iteritems():
62 if hasattr(trace, "close"):
64 for guid, element in self._elements.iteritems():
65 if isinstance(element, self.TunChannel):
68 factory_id = self._create[guid]
69 if factory_id == "Node":
71 self._elements.clear()
73 def trace_filename(self, guid, trace_id, filename = None):
75 (trace, filename) = self._traces[guid][trace_id]
76 return os.path.join(self.home_directory, filename)
78 def follow_trace(self, guid, trace_id, trace, filename):
79 if not guid in self._traces:
80 self._traces[guid] = dict()
81 self._traces[guid][trace_id] = (trace, filename)
83 def _load_netns_module(self):
84 # TODO: Do something with the configuration!!!
87 netns_mod = sys.modules["netns"]
89 enable_debug = self._attributes.get_attribute_value("enableDebug")
91 netns_mod.environ.set_log_level(netns_mod.environ.LOG_DEBUG)