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