1 # -*- coding: utf-8 -*-
6 from constants import TESTBED_ID, TESTBED_VERSION
7 from nepi.core import metadata
8 from nepi.core.attributes import Attribute
9 from nepi.util import tags, validation
10 from nepi.util.constants import ApplicationStatus as AS, \
11 FactoryCategories as FC, DeploymentConfiguration as DC
13 ##############################################################################
15 class OmfResource(object):
16 def __init__(self, guid, tc):
17 super(OmfResource, self).__init__()
18 self._tc = weakref.ref(tc)
23 return self._tc and self._tc()
40 ## NODE #######################################################################
42 class OmfNode(OmfResource):
43 def __init__(self, guid, tc):
44 super(OmfNode, self).__init__(guid, tc)
45 self.hostname = self.tc._get_parameters(guid)['hostname']
46 self.tc.api.enroll_host(self.hostname)
48 ## APPLICATION ################################################################
50 class OmfApplication(OmfResource):
51 def __init__(self, guid, tc):
52 super(OmfApplication, self).__init__(guid, tc)
53 node_guids = tc.get_connected(guid, "node", "apps")
54 if len(node_guids) == 0:
55 raise RuntimeError("Can't instantiate interface %d outside node" % guid)
57 self._node_guid = node_guids[0]
63 node = self.tc.elements.get(self._node_guid)
64 self.tc.api.execute(node.hostname,
70 if guid not in testbed_instance.elements.keys():
71 return AS.STATUS_NOT_STARTED
72 return AS.STATUS_RUNNING
74 #return AS.STATUS_FINISHED
77 ## WIFIIFACE ########################################################
79 class OmfWifiInterface(OmfResource):
80 def __init__(self, guid, tc):
81 super(OmfWifiInterface, self).__init__(guid, tc)
82 node_guids = tc.get_connected(guid, "node", "devs")
83 if len(node_guids) == 0:
84 raise RuntimeError("Can't instantiate interface %d outside node" % guid)
86 self._node_guid = node_guids[0]
93 def __setattr__(self, name, value):
94 if name in ["ip", "mode", "type", "essid", "channel"]:
95 node = self.tc.elements.get(self._node_guid)
96 attribute = "net/w0/%s" % name
97 self._tc().api.configure(node.hostname, attribute, value)
99 super(OmfWifiInterface, self).__setattr__(name, value)
103 WIFIIFACE = "WifiInterface"
105 OMFAPPLICATION = "OmfApplication"
107 def create(factory, testbed_instance, guid):
111 elif factory == OMFAPPLICATION:
112 clazz = OmfApplication
113 elif factory == WIFIIFACE:
114 clazz = OmfWifiInterface
116 element = clazz(guid, testbed_instance)
117 #import pdb; pdb.set_trace()
118 testbed_instance._elements[guid] = element
120 def start(testbed_instance, guid):
121 element = testbed_instance.elements.get(guid)
124 def stop(testbed_instance, guid):
125 element = testbed_instance.elements.get(guid)
128 def status(testbed_instance, guid):
129 element = testbed_instance.elements.get(guid)
130 return element.status()
132 def configure(testbed_instance, guid):
133 element = testbed_instance.elements.get(guid)
134 return element.status()
136 ### Factory information ###
138 connector_types = dict({
140 "help": "Connector from node to applications",
146 "help": "Connector to network interfaces",
152 "help": "Connector from a device to a channel",
158 "help": "Connector to a Node",
167 "from": (TESTBED_ID, NODE, "devs"),
168 "to": (TESTBED_ID, WIFIIFACE, "node"),
172 "from": (TESTBED_ID, WIFIIFACE, "chan"),
173 "to": (TESTBED_ID, CHANNEL, "devs"),
177 "from": (TESTBED_ID, NODE, "apps"),
178 "to": (TESTBED_ID, OMFAPPLICATION, "node"),
186 "help": "Application id",
187 "type": Attribute.STRING,
188 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
189 "validation_function": validation.is_string
193 "help": "Application arguments",
194 "type": Attribute.STRING,
195 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
196 "validation_function": validation.is_string
200 "help": "Path to binary (e.g '/opt/vlc-1.1.13/vlc')",
201 "type": Attribute.STRING,
202 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
203 "validation_function": validation.is_string
207 "help": "Hostname for the target OMF node",
208 "type": Attribute.STRING,
209 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
210 "validation_function": validation.is_string
214 "help": "Corresponds to the OMF attributes net/w0/mode",
215 "type": Attribute.STRING,
216 "flags": Attribute.NoDefaultValue,
217 "validation_function": validation.is_string
221 "help": "Corresponds to the OMF attributes net/w0/type",
222 "type": Attribute.STRING,
223 "flags": Attribute.NoDefaultValue,
224 "validation_function": validation.is_string
228 "help": "Corresponds to the OMF attributes net/w0/channel",
229 "type": Attribute.STRING,
230 "flags": Attribute.NoDefaultValue,
231 "validation_function": validation.is_string
235 "help": "Corresponds to the OMF attributes net/w0/essid",
236 "type": Attribute.STRING,
237 "flags": Attribute.NoDefaultValue,
238 "validation_function": validation.is_string
242 "help": "Corresponds to the OMF attributes net/w0/ip",
243 "type": Attribute.STRING,
244 "flags": Attribute.NoDefaultValue,
245 "validation_function": validation.is_ip4_address
254 create_order = [ NODE, WIFIIFACE, CHANNEL, OMFAPPLICATION ]
255 configure_order = [ WIFIIFACE, NODE, CHANNEL, OMFAPPLICATION ]
257 factories_info = dict({
260 "category": FC.CATEGORY_NODES,
261 "create_function": functools.partial(create, NODE),
262 "box_attributes": ["hostname"],
263 "connector_types": ["devs", "apps"],
264 "tags": [tags.NODE, tags.ALLOW_ROUTES],
267 "help": "Wireless network interface",
268 "category": FC.CATEGORY_DEVICES,
269 "create_function": functools.partial(create, WIFIIFACE),
270 "configure_function": configure,
271 "box_attributes": ["mode", "type", "channel", "essid", "ip"],
272 "connector_types": ["node", "chan"],
273 "tags": [tags.INTERFACE, tags.HAS_ADDRESSES],
276 "help": "Wireless channel",
277 "category": FC.CATEGORY_DEVICES,
278 "create_function": create,
279 "create_function": functools.partial(create, CHANNEL),
280 "box_attributes": ["mode", "type", "channel", "essid"],
281 "connector_types": ["devs"],
283 OMFAPPLICATION: dict({
284 "help": "Generic executable command line application",
285 "category": FC.CATEGORY_APPLICATIONS,
286 "create_function": functools.partial(create, OMFAPPLICATION),
287 "start_function": start,
288 "stop_function": stop,
289 "status_function": status,
290 "box_attributes": ["appId", "arguments", "path"],
291 "connector_types": ["node"],
292 "tags": [tags.APPLICATION],
296 testbed_attributes = dict({
297 "enable_debug": dict({
298 "name": "enableDebug",
299 "help": "Enable netns debug output",
300 "type": Attribute.BOOL,
302 "validation_function": validation.is_bool
307 "type": Attribute.STRING,
308 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
309 "validation_function": validation.is_string
313 "help": "OMF XMPP server host",
314 "type": Attribute.STRING,
315 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
316 "validation_function": validation.is_string
320 "help": "OMF XMPP service port",
321 "type": Attribute.INTEGER,
322 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
323 "validation_function": validation.is_integer
325 "xmppPassword": dict({
326 "name": "xmppPassword",
327 "help": "OMF XMPP slice password",
328 "type": Attribute.STRING,
329 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
330 "validation_function": validation.is_string
334 supported_recovery_policies = [
338 class MetadataInfo(metadata.MetadataInfo):
340 def connector_types(self):
341 return connector_types
344 def connections(self):
348 def attributes(self):
356 def create_order(self):
360 def configure_order(self):
361 return configure_order
364 def factories_info(self):
365 return factories_info
368 def testbed_attributes(self):
369 return testbed_attributes
372 def testbed_id(self):
376 def testbed_version(self):
377 return TESTBED_VERSION
380 def supported_recover_policies(self):
381 return supported_recovery_policies