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 OMFNode(ResourceManager):
13 _authorized_connections = ["OMFApplication" , "OMFWifiInterface"]
16 def _register_attributes(cls):
17 hostname = Attribute("hostname", "Hostname of the machine")
18 cpu = Attribute("cpu", "CPU of the node")
19 ram = Attribute("ram", "RAM of the node")
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(hostname)
25 cls._register_attribute(ram)
26 cls._register_attribute(cpu)
27 cls._register_attribute(xmppSlice)
28 cls._register_attribute(xmppHost)
29 cls._register_attribute(xmppPort)
30 cls._register_attribute(xmppPassword)
33 def _register_filters(cls):
34 hostname = Attribute("hostname", "Hostname of the machine")
35 gateway = Attribute("gateway", "Gateway")
36 granularity = Attribute("granularity", "Granularity of the reservation time")
37 hardware_type = Attribute("hardware_type", "Hardware type of the machine")
38 cls._register_filter(hostname)
39 cls._register_filter(gateway)
40 cls._register_filter(granularity)
41 cls._register_filter(hardware_type)
43 def __init__(self, ec, guid, creds):
44 super(OMFNode, self).__init__(ec, guid)
45 self.set('xmppSlice', creds['xmppSlice'])
46 self.set('xmppHost', creds['xmppHost'])
47 self.set('xmppPort', creds['xmppPort'])
48 self.set('xmppPassword', creds['xmppPassword'])
50 self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
52 self._logger = logging.getLogger("neco.omf.omfNode ")
53 self._logger.setLevel(neco.LOGLEVEL)
55 def _validate_connection(self, guid):
56 rm = self.ec.resource(guid)
57 if rm.rtype() in self._authorized_connections:
58 self._logger.debug("Connection between %s %s and %s %s accepted" % (self.rtype(), self._guid, rm.rtype(), guid))
60 self._logger.debug("Connection between %s %s and %s %s refused" % (self.rtype(), self._guid, rm.rtype(), guid))
66 def provision(self, credential):
70 self._omf_api.enroll_host(self.get('hostname'))
73 self._omf_api.disconnect()
76 #routes = self.tc._add_route.get(self.guid, [])
77 #iface_guids = self.tc.get_connected(self.guid, "devs", "node")
80 (destination, netprefix, nexthop, metric, device) = route
81 netmask = ipaddr2.ipv4_mask2dot(netprefix)
83 # Validate that the interface is associated to the node
84 for iface_guid in iface_guids:
85 iface = self.tc.elements.get(iface_guid)
86 if iface.devname == device:
87 self._omf_api.execute(self.get('hostname'),
88 "Id#%s" % str(random.getrandbits(128)),
89 "add -net %s netmask %s dev %s" % (destination, netmask, iface.devname),