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 OMFWifiInterface(ResourceManager):
12 _rtype = "OMFWifiInterface"
13 _authorized_connections = ["OMFNode" , "OMFChannel"]
15 #alias2name = dict({'w0':'wlan0', 'w1':'wlan1'})
18 def _register_attributes(cls):
19 alias = Attribute("alias","Alias of the interface", default_value = "w0")
20 mode = Attribute("mode","Mode of the interface")
21 type = Attribute("type","Type of the interface")
22 essid = Attribute("essid","Essid of the interface")
23 ip = Attribute("ip","IP of the interface")
24 xmppSlice = Attribute("xmppSlice","Name of the slice", flags = "0x02")
25 xmppHost = Attribute("xmppHost", "Xmpp Server",flags = "0x02")
26 xmppPort = Attribute("xmppPort", "Xmpp Port",flags = "0x02")
27 xmppPassword = Attribute("xmppPassword", "Xmpp Port",flags = "0x02")
28 cls._register_attribute(alias)
29 cls._register_attribute(xmppSlice)
30 cls._register_attribute(xmppHost)
31 cls._register_attribute(xmppPort)
32 cls._register_attribute(xmppPassword)
33 cls._register_attribute(mode)
34 cls._register_attribute(type)
35 cls._register_attribute(essid)
36 cls._register_attribute(ip)
38 def __init__(self, ec, guid, creds):
39 super(OMFWifiInterface, self).__init__(ec, guid)
40 self.set('xmppSlice', creds['xmppSlice'])
41 self.set('xmppHost', creds['xmppHost'])
42 self.set('xmppPort', creds['xmppPort'])
43 self.set('xmppPassword', creds['xmppPassword'])
45 self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
46 self._alias = self.get('alias')
48 self._logger = logging.getLogger("neco.omf.omfIface ")
49 self._logger.setLevel(neco.LOGLEVEL)
51 def _validate_connection(self, guid):
52 rm = self.ec.resource(guid)
53 if rm.rtype() in self._authorized_connections:
54 self._logger.debug("Connection between %s %s and %s %s accepted" % (self.rtype(), self._guid, rm.rtype(), guid))
56 self._logger.debug("Connection between %s %s and %s %s refused" % (self.rtype(), self._guid, rm.rtype(), guid))
59 def _get_nodes(self, conn_set):
61 rm = self.ec.resource(elt)
62 if rm.rtype() == "OMFNode":
68 self._logger.debug(self.rtype() + " ( Guid : " + str(self._guid) +") : " + self.get('mode') + " : " + self.get('type') + " : " + self.get('essid') + " : " + self.get('ip'))
70 if self.get('mode') and self.get('type') and self.get('essid') and self.get('ip'):
71 rm_node = self._get_nodes(self._connections)
72 for attrname in ["mode", "type", "essid", "ip"]:
73 attrval = self.get(attrname)
74 attrname = "net/%s/%s" % (self._alias, attrname)
75 #print "Send the configure message"
76 self._omf_api.configure(rm_node.get('hostname'), attrname, attrval)
79 self._omf_api.disconnect()