Ticket #8: box labels, reference expression substitution supporting framework
[nepi.git] / test / lib / mock / 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 validation
8 from nepi.util.constants import STATUS_FINISHED
9
10 NODE = "Node"
11 IFACE = "Interface"
12 APP = "Application"
13
14 ### Connection functions ####
15
16 ### Creation functions ###
17
18 def create_node(testbed_instance, guid):
19     element = NODE 
20     testbed_instance.elements[guid] = element
21
22 def create_iface(testbed_instance, guid):
23      element = IFACE
24      testbed_instance.elements[guid] = element
25
26 def create_application(testbed_instance, guid):
27      element = APP
28      testbed_instance.elements[guid] = element
29
30 ### Start/Stop functions ###
31
32 ### Status functions ###
33
34 def status_application(testbed_instance, guid):
35     return 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    })
65
66 connections = [
67     dict({
68         "from": (TESTBED_ID, NODE, "devs"),
69         "to":   (TESTBED_ID, IFACE, "node"),
70         "code": None,
71         "can_cross": False
72     }),
73     dict({
74         "from": (TESTBED_ID, IFACE, "iface"),
75         "to":   (TESTBED_ID, IFACE, "iface"),
76         "code": None,
77         "can_cross": False
78     }),
79     dict({
80         "from": (TESTBED_ID, NODE, "apps"),
81         "to":   (TESTBED_ID, APP, "node"),
82         "code": None,
83         "can_cross": False
84     })
85 ]
86
87 attributes = dict({
88     "fake": dict({
89                 "name": "fake",
90                 "help": "fake attribute",
91                 "type": Attribute.BOOL,
92                 "value": False,
93                 "range": None,
94                 "allowed": None,
95                 "validation_function": validation.is_bool
96             }),
97     "test": dict({
98                 "name": "test",
99                 "help": "test attribute",
100                 "type": Attribute.STRING,
101                 "validation_function": validation.is_string
102             }),
103     })
104
105 traces = dict({
106     "fake": dict({
107                 "name": "fake",
108                 "help": "fake trace"
109               }),
110     })
111
112 factories_order = [ NODE, IFACE, APP ]
113
114 factories_info = dict({
115     NODE: dict({
116             "help": "Fake node",
117             "category": "topology",
118             "create_function": create_node,
119             "start_function": None,
120             "stop_function": None,
121             "status_function": None,
122             "box_attributes": ["fake","test"],
123             "connector_types": ["devs", "apps"]
124        }),
125     IFACE: dict({
126             "help": "Fake iface",
127             "category": "devices",
128             "create_function": create_iface,
129             "start_function": None,
130             "stop_function": None,
131             "status_function": None,
132             "allow_addresses": True,
133             "factory_attributes": ["fake"],
134             "box_attributes": ["fake","test"],
135             "connector_types": ["node", "iface"]
136        }),
137     APP: dict({
138             "help": "Fake application",
139             "category": "applications",
140             "create_function": create_application,
141             "start_function": None,
142             "stop_function": None,
143             "status_function": status_application,
144             "box_attributes": ["fake","test"],
145             "connector_types": ["node"],
146             "traces": ["fake"]
147         }),
148 })
149
150 testbed_attributes = dict({
151         "fake": dict({
152                 "name": "fake",
153                 "help": "fake attribute",
154                 "type": Attribute.BOOL,
155                 "value": False,
156                 "range": None,
157                 "allowed": None,
158                 "validation_function": validation.is_bool
159             }),
160     })
161
162 class VersionedMetadataInfo(metadata.VersionedMetadataInfo):
163     @property
164     def connector_types(self):
165         return connector_types
166
167     @property
168     def connections(self):
169         return connections
170
171     @property
172     def attributes(self):
173         return attributes
174
175     @property
176     def traces(self):
177         return traces
178
179     @property
180     def create_order(self):
181         return factories_order
182
183     @property
184     def configure_order(self):
185         return factories_order
186
187     @property
188     def factories_info(self):
189         return factories_info
190
191     @property
192     def testbed_attributes(self):
193         return testbed_attributes
194