2 from neco.execution.resource import ResourceManager, clsinit
3 from neco.execution.attribute import Attribute, Flags
5 from neco.resources.omf.omf_api import OMFAPIFactory
12 class OMFNode(ResourceManager):
14 .. class:: Class Args :
16 :param ec: The Experiment controller
17 :type ec: ExperimentController
18 :param guid: guid of the RM
20 :param creds: Credentials to communicate with the rm (XmppClient for OMF)
25 This class is used only by the Experiment Controller through the Resource Factory
29 _authorized_connections = ["OMFApplication" , "OMFWifiInterface"]
33 def _register_attributes(cls):
34 """Register the attributes of an OMF Node
37 hostname = Attribute("hostname", "Hostname of the machine")
38 cpu = Attribute("cpu", "CPU of the node")
39 ram = Attribute("ram", "RAM of the node")
40 xmppSlice = Attribute("xmppSlice","Name of the slice", flags = Flags.Credential)
41 xmppHost = Attribute("xmppHost", "Xmpp Server",flags = Flags.Credential)
42 xmppPort = Attribute("xmppPort", "Xmpp Port",flags = Flags.Credential)
43 xmppPassword = Attribute("xmppPassword", "Xmpp Port",flags = Flags.Credential)
44 cls._register_attribute(hostname)
45 cls._register_attribute(ram)
46 cls._register_attribute(cpu)
47 cls._register_attribute(xmppSlice)
48 cls._register_attribute(xmppHost)
49 cls._register_attribute(xmppPort)
50 cls._register_attribute(xmppPassword)
53 def _register_filters(cls):
54 """Register the filters of an OMF Node
57 hostname = Attribute("hostname", "Hostname of the machine")
58 gateway = Attribute("gateway", "Gateway")
59 granularity = Attribute("granularity", "Granularity of the reservation time")
60 hardware_type = Attribute("hardware_type", "Hardware type of the machine")
61 cls._register_filter(hostname)
62 cls._register_filter(gateway)
63 cls._register_filter(granularity)
64 cls._register_filter(hardware_type)
66 # XXX: We don't necessary need to have the credentials at the
67 # moment we create the RM
68 def __init__(self, ec, guid):
70 :param ec: The Experiment controller
71 :type ec: ExperimentController
72 :param guid: guid of the RM
74 :param creds: Credentials to communicate with the rm (XmppClient for OMF)
78 super(OMFNode, self).__init__(ec, guid)
82 self._logger = logging.getLogger("neco.omf.omfNode ")
85 self._logger.setLevel(neco.LOGLEVEL)
87 def _validate_connection(self, guid):
88 """Check if the connection is available.
90 :param guid: Guid of the current RM
95 rm = self.ec.get_resource(guid)
96 if rm.rtype() in self._authorized_connections:
97 self._logger.debug("Connection between %s %s and %s %s accepted" %
98 (self.rtype(), self._guid, rm.rtype(), guid))
100 self._logger.debug("Connection between %s %s and %s %s refused" %
101 (self.rtype(), self._guid, rm.rtype(), guid))
104 def deploy_action(self):
108 self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'),
109 self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
110 self._omf_api.enroll_host(self.get('hostname'))
112 super(OMFNode, self).deploy_action()
115 """ Discover the availables nodes
121 """ Provision some availables nodes
127 """Send Xmpp Message Using OMF protocol to enroll the node into the experiment
130 super(OMFNode, self).start()
134 """Send Xmpp Message Using OMF protocol to disconnect the node
137 super(OMFNode, self).stop()
140 """Clean the RM at the end of the experiment
143 self._omf_api.release(self.get('hostname'))
144 OMFAPIFactory.release_api(self.get('xmppSlice'),
145 self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
149 #routes = self.tc._add_route.get(self.guid, [])
150 #iface_guids = self.tc.get_connected(self.guid, "devs", "node")
153 (destination, netprefix, nexthop, metric, device) = route
154 netmask = ipaddr2.ipv4_mask2dot(netprefix)
156 # Validate that the interface is associated to the node
157 for iface_guid in iface_guids:
158 iface = self.tc.elements.get(iface_guid)
159 if iface.devname == device:
160 self._omf_api.execute(self.get('hostname'),
161 "Id#%s" % str(random.getrandbits(128)),
162 "add -net %s netmask %s dev %s" % (destination, netmask, iface.devname),
163 "/sbin/route", # path