fixed shebangs in non executable .py files
[nepi.git] / test / lib / mock / 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 validation, tags
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 = True
17     testbed_instance.set(guid, "cross", True)
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":   ("mock2", IFACE, "cross"),
91         "init_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     "maxAddresses": dict({
117                 "name": "maxAddresses",
118                 "help": "Attribute that indicates the maximum number of addresses for an interface",
119                 "type": Attribute.INTEGER,
120                 "value": 3,
121                 "flags" : Attribute.DesignReadOnly |\
122                     Attribute.ExecInvisible |\
123                     Attribute.Metadata,
124                 "validation_function": validation.is_integer
125        })
126     })
127
128 traces = dict({
129     "fake": dict({
130                 "name": "fake",
131                 "help": "fake trace"
132               }),
133     })
134
135 factories_order = [ NODE, IFACE, APP ]
136
137 factories_info = dict({
138     NODE: dict({
139             "help": "Fake node",
140             "category": "topology",
141             "create_function": create_node,
142             "start_function": None,
143             "stop_function": None,
144             "status_function": None,
145             "box_attributes": ["fake","test"],
146             "connector_types": ["devs", "apps"],
147             "tags": [tags.MOBILE, tags.NODE, tags.ALLOW_ROUTES],
148        }),
149     IFACE: dict({
150             "help": "Fake iface",
151             "category": "devices",
152             "create_function": create_iface,
153             "start_function": None,
154             "stop_function": None,
155             "status_function": None,
156             "allow_addresses": True,
157             "factory_attributes": ["fake", "maxAddresses"],
158             "box_attributes": ["fake", "test", "cross"],
159             "connector_types": ["node", "iface", "cross"],
160             "tags": [tags.INTERFACE, tags.ALLOW_ADDRESSES],
161        }),
162     APP: dict({
163             "help": "Fake application",
164             "category": "applications",
165             "create_function": create_application,
166             "start_function": None,
167             "stop_function": None,
168             "status_function": status_application,
169             "box_attributes": ["fake", "test"],
170             "connector_types": ["node"],
171             "traces": ["fake"],
172             "tags": [tags.APPLICATION],
173         }),
174 })
175
176 testbed_attributes = dict({
177         "fake": dict({
178                 "name": "fake",
179                 "help": "fake attribute",
180                 "type": Attribute.BOOL,
181                 "value": False,
182                 "range": None,
183                 "allowed": None,
184                 "validation_function": validation.is_bool
185             }),
186         "test": dict({
187                 "name": "test",
188                 "help": "test attribute",
189                 "type": Attribute.STRING,
190                 "validation_function": validation.is_string
191             }),
192     })
193
194 class MetadataInfo(metadata.MetadataInfo):
195     @property
196     def connector_types(self):
197         return connector_types
198
199     @property
200     def connections(self):
201         return connections
202
203     @property
204     def attributes(self):
205         return attributes
206
207     @property
208     def traces(self):
209         return traces
210
211     @property
212     def create_order(self):
213         return factories_order
214
215     @property
216     def configure_order(self):
217         return factories_order
218
219     @property
220     def factories_info(self):
221         return factories_info
222
223     @property
224     def testbed_attributes(self):
225         return testbed_attributes
226
227     @property
228     def testbed_id(self):
229         return TESTBED_ID
230
231     @property
232     def testbed_version(self):
233         return TESTBED_VERSION
234