2 # -*- coding: utf-8 -*-
4 from constants import TESTBED_ID
5 from nepi.core import testbed_impl
6 from nepi.util.constants import TESTBED_STATUS_CREATED
9 class TestbedController(testbed_impl.TestbedController):
10 def __init__(self, testbed_version):
11 super(TestbedController, self).__init__(TESTBED_ID, testbed_version)
13 self._home_directory = None
17 def home_directory(self):
18 return self._home_directory
25 self._home_directory = self._attributes.\
26 get_attribute_value("homeDirectory")
27 self._netns = self._load_netns_module()
28 super(TestbedController, self).do_setup()
30 def set(self, time, guid, name, value):
31 super(TestbedController, self).set(time, guid, name, value)
32 # TODO: take on account schedule time for the task
33 element = self._elements.get(guid)
35 setattr(element, name, value)
37 def get(self, time, guid, name):
38 value = super(TestbedController, self).get(time, guid, name)
39 # TODO: take on account schedule time for the task
40 factory_id = self._create[guid]
41 factory = self._factories[factory_id]
42 if factory.box_attributes.is_attribute_design_only(name):
44 element = self._elements.get(guid)
46 return getattr(element, name)
47 except KeyError, AttributeError:
50 def get_route(self, guid, index, attribute):
51 # TODO: fetch real data from netns
53 return self.box_get_route(guid, int(index), attribute)
54 except KeyError, AttributeError:
57 def get_address(self, guid, index, attribute='Address'):
58 # TODO: fetch real data from netns
60 return self.box_get_address(guid, int(index), attribute)
61 except KeyError, AttributeError:
65 def action(self, time, guid, action):
66 raise NotImplementedError
69 for trace in self._traces.values():
71 for element in self._elements.values():
74 def trace_filename(self, guid, trace_id):
75 # TODO: Need to be defined inside a home!!!! with and experiment id_code
76 return os.path.join(self.home_directory, "%d_%s" % (guid, trace_id))
78 def follow_trace(self, trace_id, trace):
79 self._traces[trace_id] = trace
81 def _load_netns_module(self):
82 # TODO: Do something with the configuration!!!
85 netns_mod = sys.modules["netns"]
87 enable_debug = self._attributes.get_attribute_value("enableDebug")
89 netns_mod.environ.set_log_level(netns_mod.environ.LOG_DEBUG)