2 from neco.execution.resource import Resource, clsinit
3 from neco.execution.attribute import Attribute
5 from neco.resources.omf.omf_api import OMFAPIFactory
11 class OMFChannel(Resource):
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"]
31 def _register_attributes(cls):
32 """Register the attributes of an OMF channel
34 channel = Attribute("channel", "Name of the application")
35 xmppSlice = Attribute("xmppSlice","Name of the slice", flags = "0x02")
36 xmppHost = Attribute("xmppHost", "Xmpp Server",flags = "0x02")
37 xmppPort = Attribute("xmppPort", "Xmpp Port",flags = "0x02")
38 xmppPassword = Attribute("xmppPassword", "Xmpp Port",flags = "0x02")
39 cls._register_attribute(channel)
40 cls._register_attribute(xmppSlice)
41 cls._register_attribute(xmppHost)
42 cls._register_attribute(xmppPort)
43 cls._register_attribute(xmppPassword)
45 def __init__(self, ec, guid, creds):
47 :param ec: The Experiment controller
48 :type ec: ExperimentController
49 :param guid: guid of the RM
51 :param creds: Credentials to communicate with the rm (XmppClient for OMF)
55 super(OMFChannel, self).__init__(ec, guid)
56 self.set('xmppSlice', creds['xmppSlice'])
57 self.set('xmppHost', creds['xmppHost'])
58 self.set('xmppPort', creds['xmppPort'])
59 self.set('xmppPassword', creds['xmppPassword'])
61 self._nodes_guid = list()
63 self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
65 self._logger = logging.getLogger("neco.omf.omfChannel")
66 self._logger.setLevel(neco.LOGLEVEL)
68 def _validate_connection(self, guid):
69 """Check if the connection is available.
71 :param guid: Guid of the current RM
76 rm = self.ec.resource(guid)
77 if rm.rtype() in self._authorized_connections:
78 self._logger.debug("Connection between %s %s and %s %s accepted" % (self.rtype(), self._guid, rm.rtype(), guid))
80 self._logger.debug("Connection between %s %s and %s %s refused" % (self.rtype(), self._guid, rm.rtype(), guid))
83 def _get_target(self, conn_set):
85 Get the couples (host, interface) that used this channel
87 :param conn_set: Connections of the current Guid
90 :return: self._nodes_guid
93 rm_iface = self.ec.resource(elt)
94 for conn in rm_iface._connections:
95 rm_node = self.ec.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
103 """ Discover the availables channels
108 def provision(self, credential):
109 """ Provision some availables channels
115 """Send Xmpp Message Using OMF protocol to configure Channel
118 if self.get('channel'):
119 set_nodes = self._get_target(self._connections)
121 for couple in set_nodes:
122 #print "Couple node/alias : " + couple[0] + " , " + couple[1]
123 attrval = self.get('channel')
124 attrname = "net/%s/%s" % (couple[1], 'channel')
125 #print "Send the configure message"
126 self._omf_api.configure(couple[0], attrname, attrval)
130 if self.get('channel'):
131 node = self.tc.elements.get(self._node_guid)
132 attrval = self.get('channel')
133 attrname = "net/%s/%s" % (self._alias, 'channel')
134 self._omf_api.configure('omf.plexus.wlab17', attrname, attrval)
135 except AttributeError:
136 # If the attribute is not yet defined, ignore the error