2 from neco.execution.resource import ResourceManager, clsinit
3 from neco.execution.attribute import Attribute
5 from neco.resources.omf.omf_api import OMFAPIFactory
11 class OMFChannel(ResourceManager):
13 _authorized_connections = ["OMFWifiInterface"]
16 def _register_attributes(cls):
17 channel = Attribute("channel", "Name of the application")
18 xmppSlice = Attribute("xmppSlice","Name of the slice", flags = "0x02")
19 xmppHost = Attribute("xmppHost", "Xmpp Server",flags = "0x02")
20 xmppPort = Attribute("xmppPort", "Xmpp Port",flags = "0x02")
21 xmppPassword = Attribute("xmppPassword", "Xmpp Port",flags = "0x02")
22 cls._register_attribute(channel)
23 cls._register_attribute(xmppSlice)
24 cls._register_attribute(xmppHost)
25 cls._register_attribute(xmppPort)
26 cls._register_attribute(xmppPassword)
28 def __init__(self, ec, guid, creds):
29 super(OMFChannel, self).__init__(ec, guid)
30 self.set('xmppSlice', creds['xmppSlice'])
31 self.set('xmppHost', creds['xmppHost'])
32 self.set('xmppPort', creds['xmppPort'])
33 self.set('xmppPassword', creds['xmppPassword'])
35 self._nodes_guid = list()
37 self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
39 self._logger = logging.getLogger("neco.omf.omfChannel")
40 self._logger.setLevel(neco.LOGLEVEL)
42 def _validate_connection(self, guid):
43 rm = self.ec.resource(guid)
44 if rm.rtype() in self._authorized_connections:
45 self._logger.debug("Connection between %s %s and %s %s accepted" % (self.rtype(), self._guid, rm.rtype(), guid))
47 self._logger.debug("Connection between %s %s and %s %s refused" % (self.rtype(), self._guid, rm.rtype(), guid))
50 def _get_nodes(self, conn_set):
52 rm_iface = self.ec.resource(elt)
53 for conn in rm_iface._connections:
54 rm_node = self.ec.resource(conn)
55 if rm_node.rtype() == "OMFNode":
56 couple = [rm_node.get('hostname'), rm_iface.get('alias')]
58 self._nodes_guid.append(couple)
59 return self._nodes_guid
64 def provision(self, credential):
68 if self.get('channel'):
69 set_nodes = self._get_nodes(self._connections)
71 for couple in set_nodes:
72 #print "Couple node/alias : " + couple[0] + " , " + couple[1]
73 attrval = self.get('channel')
74 attrname = "net/%s/%s" % (couple[1], 'channel')
75 #print "Send the configure message"
76 self._omf_api.configure(couple[0], attrname, attrval)
80 if self.get('channel'):
81 node = self.tc.elements.get(self._node_guid)
82 attrval = self.get('channel')
83 attrname = "net/%s/%s" % (self._alias, 'channel')
84 self._omf_api.configure('omf.plexus.wlab17', attrname, attrval)
85 except AttributeError:
86 # If the attribute is not yet defined, ignore the error