5 from requests.auth import HTTPBasicAuth
10 PREDEFINE_USERROLE="http://%s:8181/restconf/config/nemo-user:user-roles/"
11 PREDEFINE_NODETYPE="http://%s:8181/restconf/config/nemo-object:node-definitions/"
12 PREDEFINE_CONNECTIONTYPE="http://%s:8181/restconf/config/nemo-object:connection-definitions/"
13 PREDEFINE_FLOWMATCHTYPE="http://%s:8181/restconf/config/nemo-object:match-item-definitions/"
14 PREDEFINE_FLOWPROPERTY="http://%s:8181/restconf/config/nemo-object:flow-property-definitions/"
15 PREDEFINE_OPERATIONACTION="http://%s:8181/restconf/config/nemo-operation:action-definitions/"
16 PREDEFINE_OPERATIONCONDITION="http://%s:8181/restconf/config/nemo-operation:condition-parameter-definitions/"
17 PHYSICAL_PORT_ATTRIBUTE="http://%s:8181/restconf/config/generic-physical-network:physical-port-attribute-definitions/"
18 PHYSICAL_NODE_ATTRIBUTE="http://%s:8181/restconf/config/generic-physical-network:physical-node-attribute-definitions/"
22 def add_predefined_userrole(contHost):
27 "role-name": "tenant",
28 "role-description": "It's a non-administor user"
33 put(PREDEFINE_USERROLE % contHost, data)
35 def add_predefined_nodetypes(contHost):
41 "property-definition": [
43 "property-name": "name",
44 "property-value-type": "string"
47 "property-name": "location",
48 "property-value-type": "string"
51 #For example, one legal mac-address is 00:01:0a:90:78:02.
52 "property-name": "mac-address",
53 "property-value-type": "string"
56 #For example, one legal ip-address is 10.0.2.0/24.
57 "property-name": "ip-address",
58 "property-value-type": "string"
63 "node-type": "l2-group",
64 "property-definition": [
66 #For example, one legal ip-address is 10.0.2.0/24.
67 "property-name": "ip-prefix",
68 "property-value-type": "string"
71 #For example, one legal gateway-ip is 10.0.2.1.
72 "property-name": "gateway-ip",
73 "property-value-type": "string"
76 "property-name": "location",
77 "property-value-type": "string"
82 "node-type": "l3-group",
83 "property-definition": [
85 #For example, one legal ip-address is 10.0.2.0/24.
86 "property-name": "ip-prefix",
87 "property-value-type": "string"
92 "node-type": "ext-group",
93 "property-definition": [
95 "property-name": "location",
96 "property-value-type": "string",
97 "is-required": "required"
100 "property-name": "ac-info-network",
101 "property-value-type": "string",
102 "is-required": "required"
105 "property-name": "ac-info-protocol",
106 "property-value-type": "string",
107 "is-required": "required"
110 "property-name": "ip-prefix",
111 "property-value-type": "string"
116 "node-type": "chain-group"
120 "property-definition": [
122 "property-name": "location",
123 "property-value-type": "string",
124 "is-required": "required"
127 "property-name": "operating-mode",
128 "property-value-type": "string",
129 "is-required": "required"
135 "property-definition": [
137 "property-name": "location",
138 "property-value-type": "string",
139 "is-required": "required"
142 "property-name": "operating-mode",
143 "property-value-type": "string",
144 "is-required": "required"
149 "node-type": "cache",
150 "property-definition": [
152 "property-name": "location",
153 "property-value-type": "string",
154 "is-required": "required"
157 "property-name": "operating-mode",
158 "property-value-type": "string",
159 "is-required": "required"
166 put(PREDEFINE_NODETYPE % contHost, data)
168 def add_predefined_connectiontypes(contHost):
170 "connection-definitions": {
171 "connection-definition":[
173 "connection-type": "p2p",
174 "property-definition": [
176 #the unit of bandwidth is mbps.
177 "property-name": "bandwidth",
178 "property-value-type": "int"
183 "connection-type": "p2mp",
184 "property-definition": [
186 #the unit of bandwidth is mbps.
187 "property-name": "bandwidth",
188 "property-value-type": "int"
193 "connection-type": "mesh",
194 "property-definition": [
196 #the unit of bandwidth is mbps.
197 "property-name": "bandwidth",
198 "property-value-type": "int"
203 "connection-type": "chain",
204 "property-definition": [
206 #the unit of bandwidth is mbps.
207 "property-name": "bandwidth",
208 "property-value-type": "int"
215 put(PREDEFINE_CONNECTIONTYPE % contHost, data)
217 def add_flow_matchtypes(contHost):
219 "match-item-definitions": {
220 "match-item-definition": [
222 #For example, one legal eth-type is arp.
223 "match-item-name": "eth-type",
224 "match-item-value-type": "string"
227 #For example, one legal src-mac is 00:00:0a:b7:01:90;
228 "match-item-name": "src-mac",
229 "match-item-value-type": "string"
232 #For example, one legal src-mac is 00:00:0a:b7:01:90;
233 "match-item-name": "dst-mac",
234 "match-item-value-type": "string"
237 #For example, one legal proto is http;
238 "match-item-name": "proto",
239 "match-item-value-type": "string"
242 #For example, one legal src-ip is 10.0.2.1;
243 "match-item-name": "src-ip",
244 "match-item-value-type": "string"
247 #For example, one legal dst-ip is 10.0.1.2;
248 "match-item-name": "dst-ip",
249 "match-item-value-type": "string"
252 #For example, one legal src-port is 80;
253 "match-item-name": "src-port",
254 "match-item-value-type": "int"
257 #For example, one legal dst-port is 22;
258 "match-item-name": "dst-port",
259 "match-item-value-type": "int"
264 put(PREDEFINE_FLOWMATCHTYPE % contHost, data)
266 def add_flow_properties(contHost):
268 "flow-property-definitions": {
269 "property-definition": [
271 "property-name": "path",
272 "property-value-type": "string"
277 put(PREDEFINE_FLOWPROPERTY % contHost, data)
279 def add_operation_actions(contHost):
281 "action-definitions": {
282 "action-definition": [
284 "action-name": "deny"
287 "action-name": "allow"
290 "action-name": "go-through",
291 "parameter-value-type": "string"
294 "action-name": "qos-bandwidth",
295 "parameter-value-type": "int"
300 put(PREDEFINE_OPERATIONACTION % contHost, data)
302 def add_operation_conditions(contHost):
304 "condition-parameter-definitions": {
305 "condition-parameter-definition": [
307 "parameter-name": "time",
308 "parameter-value-type": "string",
309 "parameter-match-patterns": {
310 "parameter-match-pattern": ["less-than" ,"not-less-than","equal","not-equal",
311 "greater-than","not-greater-than","between","periodical"]
316 put(PREDEFINE_OPERATIONCONDITION % contHost, data)
318 def add_port_attributes(conHost):
320 "physical-port-attribute-definitions":{
321 "physical-port-attribute-definition":[
323 "attribute-name":"location",
324 "attribute-value-type":"string",
325 "attribute-match-patterns":{
326 "attribute-match-pattern":["equal"]
332 put(PHYSICAL_PORT_ATTRIBUTE % conHost, data)
334 def add_node_attributes(conHost):
336 "physical-node-attribute-definitions":{
337 "physical-node-attribute-definition":[
339 "attribute-name":"location",
340 "attribute-value-type":"string",
341 "attribute-match-patterns":{
342 "attribute-match-pattern":["equal"]
346 "attribute-name":"capacity",
347 "attribute-value-type":"int",
348 "attribute-match-patterns":{
349 "attribute-match-pattern":["equal"]
355 put(PHYSICAL_NODE_ATTRIBUTE % conHost, data)
360 headers = {'Content-type': 'application/yang.data+json',
361 'Accept': 'application/yang.data+json'}
363 print json.dumps(data, indent=4, sort_keys=True)
364 r = requests.put(url, data=json.dumps(data), headers=headers, auth=HTTPBasicAuth(USERNAME, PASSWORD))
368 if __name__ == '__main__':
370 parser = argparse.ArgumentParser()
371 parser.add_argument('--controller', default='127.0.0.1', help='controller IP')
372 args=parser.parse_args()
374 print args.controller
376 add_predefined_userrole(args.controller)
377 add_predefined_nodetypes(args.controller)
378 add_predefined_connectiontypes(args.controller)
379 add_flow_matchtypes(args.controller)
380 add_flow_properties(args.controller)
381 add_operation_actions(args.controller)
382 add_operation_conditions(args.controller)
383 add_port_attributes(args.controller)
384 add_node_attributes(args.controller)