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 # XXX: flags = "0x02" is not human readable.
22 # from neco.execution.attribute import Attribute, Flags
23 # xmppSlice = Attribute("xmppSlice","Name of the slice", flags = Flags.Credential)
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(hostname)
29 cls._register_attribute(ram)
30 cls._register_attribute(cpu)
31 cls._register_attribute(xmppSlice)
32 cls._register_attribute(xmppHost)
33 cls._register_attribute(xmppPort)
34 ls._register_attribute(xmppPassword)
37 def _register_filters(cls):
38 hostname = Attribute("hostname", "Hostname of the machine")
39 gateway = Attribute("gateway", "Gateway")
40 granularity = Attribute("granularity", "Granularity of the reservation time")
41 hardware_type = Attribute("hardware_type", "Hardware type of the machine")
42 cls._register_filter(hostname)
43 cls._register_filter(gateway)
44 cls._register_filter(granularity)
45 cls._register_filter(hardware_type)
47 # XXX: We don't necessary need to have the credentials at the
48 # moment we create the RM
49 # THE OMF API SHOULD BE CREATED ON THE DEPLOY METHOD, NOT NOW
50 # THIS FORCES MORE CONSTRAINES ON THE WAY WE WILL AUTHOMATE DEPLOYMENT!
51 def __init__(self, ec, guid, creds):
52 super(OMFNode, self).__init__(ec, guid)
53 self.set('xmppSlice', creds['xmppSlice'])
54 self.set('xmppHost', creds['xmppHost'])
55 self.set('xmppPort', creds['xmppPort'])
56 self.set('xmppPassword', creds['xmppPassword'])
58 # XXX: Lines should not be more than 80 characters!
59 self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
61 self._logger = logging.getLogger("neco.omf.omfNode ")
64 self._logger.setLevel(neco.LOGLEVEL)
66 def _validate_connection(self, guid):
67 rm = self.ec.resource(guid)
68 if rm.rtype() in self._authorized_connections:
69 self._logger.debug("Connection between %s %s and %s %s accepted" % (self.rtype(), self._guid, rm.rtype(), guid))
71 self._logger.debug("Connection between %s %s and %s %s refused" % (self.rtype(), self._guid, rm.rtype(), guid))
77 def provision(self, credential):
81 self._omf_api.enroll_host(self.get('hostname'))
84 self._omf_api.disconnect()
87 #routes = self.tc._add_route.get(self.guid, [])
88 #iface_guids = self.tc.get_connected(self.guid, "devs", "node")
91 (destination, netprefix, nexthop, metric, device) = route
92 netmask = ipaddr2.ipv4_mask2dot(netprefix)
94 # Validate that the interface is associated to the node
95 for iface_guid in iface_guids:
96 iface = self.tc.elements.get(iface_guid)
97 if iface.devname == device:
98 self._omf_api.execute(self.get('hostname'),
99 "Id#%s" % str(random.getrandbits(128)),
100 "add -net %s netmask %s dev %s" % (destination, netmask, iface.devname),
101 "/sbin/route", # path