2 # -*- coding: utf-8 -*-
4 from constants import TESTBED_ID
5 from nepi.core import metadata
6 from nepi.core.attributes import Attribute
7 from nepi.util import validation, tags
8 from nepi.util.constants import STATUS_FINISHED
14 ### Connection functions ####
16 def connect_cross(testbed_instance, guid, cross_data):
18 testbed_instance.set(guid, "cross", True)
20 ### Creation functions ###
22 def create_node(testbed_instance, guid):
23 testbed_instance.elements[guid] = NODE
25 def create_iface(testbed_instance, guid):
26 testbed_instance.elements[guid] = IFACE
28 def create_application(testbed_instance, guid):
29 testbed_instance.elements[guid] = APP
31 ### Start/Stop functions ###
33 ### Status functions ###
35 def status_application(testbed_instance, guid):
36 return STATUS_FINISHED
38 ### Factory information ###
40 connector_types = dict({
42 "help": "Connector from node to applications",
48 "help": "Connector from node to network interfaces",
54 "help": "Connector to a Node",
60 "help": "Connector to a Interface",
66 "help": "Connector to an Interface in other testbed",
75 "from": (TESTBED_ID, NODE, "devs"),
76 "to": (TESTBED_ID, IFACE, "node"),
80 "from": (TESTBED_ID, IFACE, "iface"),
81 "to": (TESTBED_ID, IFACE, "iface"),
85 "from": (TESTBED_ID, NODE, "apps"),
86 "to": (TESTBED_ID, APP, "node"),
90 "from": (TESTBED_ID, IFACE, "cross"),
91 "to": ("mock2", IFACE, "cross"),
92 "init_code": connect_cross,
99 "help": "fake attribute",
100 "type": Attribute.BOOL,
102 "validation_function": validation.is_bool
106 "help": "test attribute",
107 "type": Attribute.STRING,
108 "validation_function": validation.is_string
112 "help": "Attribute that indicates if cross connection was performed",
113 "type": Attribute.BOOL,
115 "validation_function": validation.is_bool
126 factories_order = [ NODE, IFACE, APP ]
128 factories_info = dict({
131 "category": "topology",
132 "create_function": create_node,
133 "start_function": None,
134 "stop_function": None,
135 "status_function": None,
136 "box_attributes": ["fake","test"],
137 "connector_types": ["devs", "apps"],
138 "tags": [tags.MOBILE]
141 "help": "Fake iface",
142 "category": "devices",
143 "create_function": create_iface,
144 "start_function": None,
145 "stop_function": None,
146 "status_function": None,
147 "allow_addresses": True,
148 "factory_attributes": ["fake"],
149 "box_attributes": ["fake", "test", "cross"],
150 "connector_types": ["node", "iface", "cross"]
153 "help": "Fake application",
154 "category": "applications",
155 "create_function": create_application,
156 "start_function": None,
157 "stop_function": None,
158 "status_function": status_application,
159 "box_attributes": ["fake", "test"],
160 "connector_types": ["node"],
165 testbed_attributes = dict({
168 "help": "fake attribute",
169 "type": Attribute.BOOL,
173 "validation_function": validation.is_bool
177 "help": "test attribute",
178 "type": Attribute.STRING,
179 "validation_function": validation.is_string
183 class VersionedMetadataInfo(metadata.VersionedMetadataInfo):
185 def connector_types(self):
186 return connector_types
189 def connections(self):
193 def attributes(self):
201 def create_order(self):
202 return factories_order
205 def configure_order(self):
206 return factories_order
209 def factories_info(self):
210 return factories_info
213 def testbed_attributes(self):
214 return testbed_attributes