2 from neco.execution.resource import ResourceManager, clsinit
3 from neco.execution.attribute import Attribute, Flags
5 from neco.resources.omf.omf_api import OMFAPIFactory
11 class OMFChannel(ResourceManager):
13 .. class:: Class Args :
15 :param ec: The Experiment controller
16 :type ec: ExperimentController
17 :param guid: guid of the RM
19 :param creds: Credentials to communicate with the rm (XmppClient for OMF)
24 This class is used only by the Experiment Controller through the Resource Factory
28 _authorized_connections = ["OMFWifiInterface", "OMFNode"]
29 _waiters = ["OMFNode", "OMFWifiInterface"]
33 def _register_attributes(cls):
34 """Register the attributes of an OMF channel
36 channel = Attribute("channel", "Name of the application")
37 xmppSlice = Attribute("xmppSlice","Name of the slice", flags = Flags.Credential)
38 xmppHost = Attribute("xmppHost", "Xmpp Server",flags = Flags.Credential)
39 xmppPort = Attribute("xmppPort", "Xmpp Port",flags = Flags.Credential)
40 xmppPassword = Attribute("xmppPassword", "Xmpp Port",flags = Flags.Credential)
41 cls._register_attribute(channel)
42 cls._register_attribute(xmppSlice)
43 cls._register_attribute(xmppHost)
44 cls._register_attribute(xmppPort)
45 cls._register_attribute(xmppPassword)
47 def __init__(self, ec, guid):
49 :param ec: The Experiment controller
50 :type ec: ExperimentController
51 :param guid: guid of the RM
53 :param creds: Credentials to communicate with the rm (XmppClient for OMF)
57 super(OMFChannel, self).__init__(ec, guid)
59 self._nodes_guid = list()
63 self._logger = logging.getLogger("neco.omf.omfChannel")
64 self._logger.setLevel(neco.LOGLEVEL)
66 def _validate_connection(self, guid):
67 """Check if the connection is available.
69 :param guid: Guid of the current RM
74 rm = self.ec.get_resource(guid)
75 if rm.rtype() in self._authorized_connections:
76 self._logger.debug("Connection between %s %s and %s %s accepted" %
77 (self.rtype(), self._guid, rm.rtype(), guid))
79 self._logger.debug("Connection between %s %s and %s %s refused" % (self.rtype(), self._guid, rm.rtype(), guid))
82 def _get_target(self, conn_set):
84 Get the couples (host, interface) that used this channel
86 :param conn_set: Connections of the current Guid
89 :return: self._nodes_guid
93 rm_iface = self.ec.get_resource(elt)
94 for conn in rm_iface.connections:
95 rm_node = self.ec.get_resource(conn)
96 if rm_node.rtype() == "OMFNode":
97 couple = [rm_node.get('hostname'), rm_iface.get('alias')]
99 self._nodes_guid.append(couple)
100 return self._nodes_guid
102 def deploy_action(self):
106 self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'),
107 self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
109 if self.get('channel'):
110 set_nodes = self._get_target(self._connections)
112 for couple in set_nodes:
113 #print "Couple node/alias : " + couple[0] + " , " + couple[1]
114 attrval = self.get('channel')
115 attrname = "net/%s/%s" % (couple[1], 'channel')
116 #print "Send the configure message"
117 self._omf_api.configure(couple[0], attrname, attrval)
119 super(OMFChannel, self).deploy_action()
122 """ Discover the availables channels
128 """ Provision some availables channels
134 """Send Xmpp Message Using OMF protocol to configure Channel
138 super(OMFChannel, self).start()
141 """Send Xmpp Message Using OMF protocol to put down the interface
144 super(OMFChannel, self).stop()
147 """Clean the RM at the end of the experiment
150 OMFAPIFactory.release_api(self.get('xmppSlice'),
151 self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))