+##############################################################################
+
+class OmfResource(object):
+ def __init__(self, guid, tc):
+ super(OmfResource, self).__init__()
+ self._tc = weakref.ref(tc)
+ self._guid = guid
+
+ @property
+ def tc(self):
+ return self._tc and self._tc()
+
+ def configure(self):
+ pass
+
+ def start(self):
+ pass
+
+ def stop(self):
+ pass
+
+ def status(self):
+ pass
+
+ def shutdown(self):
+ pass
+
+## NODE #######################################################################
+
+class OmfNode(OmfResource):
+ def __init__(self, guid, tc):
+ super(OmfNode, self).__init__(guid, tc)
+ self.hostname = self.tc._get_parameters(guid)['hostname']
+ self.tc.api.enroll_host(self.hostname)
+
+## APPLICATION ################################################################
+
+class OmfApplication(OmfResource):
+ def __init__(self, guid, tc):
+ super(OmfApplication, self).__init__(guid, tc)
+ node_guids = tc.get_connected(guid, "node", "apps")
+ if len(node_guids) == 0:
+ raise RuntimeError("Can't instantiate interface %d outside node" % guid)
+
+ self._node_guid = node_guids[0]
+ self.app_id = None
+ self.arguments = None
+ self.path = None
+
+ def start(self):
+ node = self.tc.elements.get(self._node_guid)
+ self.tc.api.execute(node.hostname,
+ self.appId,
+ self.arguments,
+ self.path)
+
+ def status(self):
+ if guid not in testbed_instance.elements.keys():
+ return AS.STATUS_NOT_STARTED
+ return AS.STATUS_RUNNING
+ # TODO!!!!
+ #return AS.STATUS_FINISHED
+
+
+## WIFIIFACE ########################################################
+
+class OmfWifiInterface(OmfResource):
+ def __init__(self, guid, tc):
+ super(OmfWifiInterface, self).__init__(guid, tc)
+ node_guids = tc.get_connected(guid, "node", "devs")
+ if len(node_guids) == 0:
+ raise RuntimeError("Can't instantiate interface %d outside node" % guid)
+
+ self._node_guid = node_guids[0]
+ self.mode = None
+ self.type = None
+ self.essid = None
+ self.channel = None
+ self.ip = None
+
+ def __setattr__(self, name, value):
+ if name in ["ip", "mode", "type", "essid", "channel"]:
+ node = self.tc.elements.get(self._node_guid)
+ attribute = "net/w0/%s" % name
+ self._tc().api.configure(node.hostname, attribute, value)
+ else:
+ super(OmfWifiInterface, self).__setattr__(name, value)
+