2 from neco.execution.resource import Resource, clsinit
3 from neco.execution.attribute import Attribute
4 from neco.resources.omf.omf_api import OMFAPIFactory
10 class OMFApplication(Resource):
11 _rtype = "OMFApplication"
12 _authorized_connections = ["OMFNode"]
15 def _register_attributes(cls):
16 appid = Attribute("appid", "Name of the application")
17 path = Attribute("path", "Path of the application")
18 args = Attribute("args", "Argument of the application")
19 env = Attribute("env", "Environnement variable of the application")
20 xmppSlice = Attribute("xmppSlice","Name of the slice", flags = "0x02")
21 xmppHost = Attribute("xmppHost", "Xmpp Server",flags = "0x02")
22 xmppPort = Attribute("xmppPort", "Xmpp Port",flags = "0x02")
23 xmppPassword = Attribute("xmppPassword", "Xmpp Port",flags = "0x02")
24 cls._register_attribute(appid)
25 cls._register_attribute(path)
26 cls._register_attribute(args)
27 cls._register_attribute(env)
28 cls._register_attribute(xmppSlice)
29 cls._register_attribute(xmppHost)
30 cls._register_attribute(xmppPort)
31 cls._register_attribute(xmppPassword)
34 def __init__(self, ec, guid, creds):
35 super(OMFApplication, self).__init__(ec, guid)
36 self.set('xmppSlice', creds['xmppSlice'])
37 self.set('xmppHost', creds['xmppHost'])
38 self.set('xmppPort', creds['xmppPort'])
39 self.set('xmppPassword', creds['xmppPassword'])
48 self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
50 self._logger = logging.getLogger("neco.omf.omfApp ")
51 self._logger.setLevel(neco.LOGLEVEL)
53 def _validate_connection(self, guid):
54 rm = self.ec.resource(guid)
55 if rm.rtype() not in self._authorized_connections:
56 self._logger.debug("Connection between %s %s and %s %s refused : An Application can be connected only to a Node" % (self.rtype(), self._guid, rm.rtype(), guid))
58 elif len(self.connections) != 0 :
59 self._logger.debug("Connection between %s %s and %s %s refused : Already Connected" % (self.rtype(), self._guid, rm.rtype(), guid))
62 self._logger.debug("Connection between %s %s and %s %s accepted" % (self.rtype(), self._guid, rm.rtype(), guid))
65 def _get_nodes(self, conn_set):
67 rm = self.ec.resource(elt)
68 if rm.rtype() == "OMFNode":
73 self._logger.debug(" " + self.rtype() + " ( Guid : " + str(self._guid) +") : " + self.get('appid') + " : " + self.get('path') + " : " + self.get('args') + " : " + self.get('env'))
75 if self.get('appid') and self.get('path') and self.get('args') and self.get('env'):
76 rm_node = self._get_nodes(self._connections)
77 self._omf_api.execute(rm_node.get('hostname'),self.get('appid'), self.get('args'), self.get('path'), self.get('env'))
80 rm_node = self._get_nodes(self._connections)
81 self._omf_api.exit(rm_node.get('hostname'),self.get('appid'))