1 # -*- coding: utf-8 -*-
3 from constants import TESTBED_ID, TESTBED_VERSION
4 from nepi.core import testbed_impl
5 from nepi.util.constants import TIME_NOW
7 from nepi.testbeds.omf.omf_api import OmfAPI
13 class TestbedController(testbed_impl.TestbedController):
15 super(TestbedController, self).__init__(TESTBED_ID, TESTBED_VERSION)
18 self._logger = logging.getLogger('nepi.testbeds.omf')
21 debug = self._attributes.get_attribute_value("enableDebug")
23 self._logger.setLevel(logging.DEBUG)
26 self._home = self._attributes.get_attribute_value("homeDirectory")
27 home = os.path.normpath(self._home)
28 if not os.path.exists(home):
29 os.makedirs(home, 0755)
31 # initialize OMF xmpp client
32 slice = self._attributes.get_attribute_value("xmppSlice")
33 host = self._attributes.get_attribute_value("xmppHost")
34 port = self._attributes.get_attribute_value("xmppPort")
35 password = self._attributes.get_attribute_value("xmppPassword")
37 xmpp_root = self._attributes.get_attribute_value("xmppRoot")
38 self._api = OmfAPI(slice, host, port, password, xmpp_root)
40 super(TestbedController, self).do_setup()
46 def set(self, guid, name, value, time = TIME_NOW):
47 super(TestbedController, self).set(guid, name, value, time)
48 element = self._elements[guid]
51 setattr(element, name, value)
53 # We ignore these errors while recovering.
54 # Some attributes are immutable, and setting
55 # them is necessary (to recover the state), but
56 # some are not (they throw an exception).
57 if not self.recovering:
60 def get(self, guid, name, time = TIME_NOW):
61 value = super(TestbedController, self).get(guid, name, time)
62 element = self._elements.get(guid)
64 return getattr(element, name)
65 except (KeyError, AttributeError):