fixed shebangs in non executable .py files
[nepi.git] / test / lib / mock2 / metadata.py
1 # -*- coding: utf-8 -*-
2
3 from constants import TESTBED_ID, TESTBED_VERSION
4 from nepi.core import metadata
5 from nepi.core.attributes import Attribute
6 from nepi.util import tags, validation
7 from nepi.util.constants import ApplicationStatus as AS
8
9 NODE = "Node"
10 IFACE = "Interface"
11 APP = "Application"
12
13 ### Connection functions ####
14
15 def connect_cross(testbed_instance, guid, cross_data):
16     connected = cross_data["cross"]
17     testbed_instance.set(guid, "cross", connected)
18
19 ### Creation functions ###
20
21 def create_node(testbed_instance, guid):
22     testbed_instance.elements[guid] = NODE
23
24 def create_iface(testbed_instance, guid):
25      testbed_instance.elements[guid] = IFACE
26
27 def create_application(testbed_instance, guid):
28      testbed_instance.elements[guid] = APP
29
30 ### Start/Stop functions ###
31
32 ### Status functions ###
33
34 def status_application(testbed_instance, guid):
35     return AS.STATUS_FINISHED
36
37 ### Factory information ###
38
39 connector_types = dict({
40     "apps": dict({
41                 "help": "Connector from node to applications", 
42                 "name": "apps",
43                 "max": -1, 
44                 "min": 0
45             }),
46     "devs": dict({
47                 "help": "Connector from node to network interfaces", 
48                 "name": "devs",
49                 "max": -1, 
50                 "min": 0
51             }),
52     "node": dict({
53                 "help": "Connector to a Node", 
54                 "name": "node",
55                 "max": 1, 
56                 "min": 1
57             }),
58     "iface": dict({
59                 "help": "Connector to a Interface", 
60                 "name": "iface",
61                 "max": 1, 
62                 "min": 0
63             }),
64     "cross": dict({
65                 "help": "Connector to an Interface in other testbed", 
66                 "name": "cross",
67                 "max": 1, 
68                 "min": 0
69             }),
70    })
71
72 connections = [
73     dict({
74         "from": (TESTBED_ID, NODE, "devs"),
75         "to":   (TESTBED_ID, IFACE, "node"),
76         "can_cross": False
77     }),
78     dict({
79         "from": (TESTBED_ID, IFACE, "iface"),
80         "to":   (TESTBED_ID, IFACE, "iface"),
81         "can_cross": False
82     }),
83     dict({
84         "from": (TESTBED_ID, NODE, "apps"),
85         "to":   (TESTBED_ID, APP, "node"),
86         "can_cross": False
87     }),
88     dict({
89         "from": (TESTBED_ID, IFACE, "cross"),
90         "to":   ("mock", IFACE, "cross"),
91         "compl_code": connect_cross,
92         "can_cross": True,
93     })]
94
95 attributes = dict({
96     "fake": dict({
97                 "name": "fake",
98                 "help": "fake attribute",
99                 "type": Attribute.BOOL,
100                 "value": False,
101                 "validation_function": validation.is_bool
102             }),
103     "test": dict({
104                 "name": "test",
105                 "help": "test attribute",
106                 "type": Attribute.STRING,
107                 "validation_function": validation.is_string
108             }),
109     "cross": dict({
110                 "name": "cross",
111                 "help": "Attribute that indicates if cross connection was performed",
112                 "type": Attribute.BOOL,
113                 "value": False,
114                 "validation_function": validation.is_bool
115             })
116     })
117
118 traces = dict({
119     "fake": dict({
120                 "name": "fake",
121                 "help": "fake trace"
122               }),
123     })
124
125 factories_order = [ NODE, IFACE, APP ]
126
127 factories_info = dict({
128     NODE: dict({
129             "help": "Fake node",
130             "category": "topology",
131             "create_function": create_node,
132             "start_function": None,
133             "stop_function": None,
134             "status_function": None,
135             "box_attributes": ["fake","test"],
136             "connector_types": ["devs", "apps"],
137             "tags": [tags.NODE, tags.ALLOW_ROUTES],
138        }),
139     IFACE: dict({
140             "help": "Fake iface",
141             "category": "devices",
142             "create_function": create_iface,
143             "start_function": None,
144             "stop_function": None,
145             "status_function": None,
146             "allow_addresses": True,
147             "factory_attributes": ["fake"],
148             "box_attributes": ["fake", "test", "cross"],
149             "connector_types": ["node", "iface", "cross"],
150             "tags": [tags.INTERFACE, tags.ALLOW_ADDRESSES],
151        }),
152     APP: dict({
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"],
161             "traces": ["fake"],
162             "tags": [tags.APPLICATION],
163         }),
164 })
165
166 testbed_attributes = dict({
167         "fake": dict({
168                 "name": "fake",
169                 "help": "fake attribute",
170                 "type": Attribute.BOOL,
171                 "value": False,
172                 "range": None,
173                 "allowed": None,
174                 "validation_function": validation.is_bool
175             }),
176         "test": dict({
177                 "name": "test",
178                 "help": "test attribute",
179                 "type": Attribute.STRING,
180                 "validation_function": validation.is_string
181             }),
182     })
183
184 class MetadataInfo(metadata.MetadataInfo):
185     @property
186     def connector_types(self):
187         return connector_types
188
189     @property
190     def connections(self):
191         return connections
192
193     @property
194     def attributes(self):
195         return attributes
196
197     @property
198     def traces(self):
199         return traces
200
201     @property
202     def create_order(self):
203         return factories_order
204
205     @property
206     def configure_order(self):
207         return factories_order
208
209     @property
210     def factories_info(self):
211         return factories_info
212
213     @property
214     def testbed_attributes(self):
215         return testbed_attributes
216
217     @property
218     def testbed_id(self):
219         return TESTBED_ID
220
221     @property
222     def testbed_version(self):
223         return TESTBED_VERSION
224