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"
32 "role-description": "It's a administor user"
37 put(PREDEFINE_USERROLE % contHost, data)
39 def add_predefined_nodetypes(contHost):
45 "property-definition": [
47 "property-name": "name",
48 "property-value-type": "string"
51 "property-name": "location",
52 "property-value-type": "string"
55 #For example, one legal mac-address is 00:01:0a:90:78:02.
56 "property-name": "mac-address",
57 "property-value-type": "string"
60 #For example, one legal ip-address is 10.0.2.0/24.
61 "property-name": "ip-address",
62 "property-value-type": "string"
67 "node-type": "l2-group",
68 "property-definition": [
70 #For example, one legal ip-address is 10.0.2.0/24.
71 "property-name": "ip-prefix",
72 "property-value-type": "string"
75 #For example, one legal gateway-ip is 10.0.2.1.
76 "property-name": "gateway-ip",
77 "property-value-type": "string"
80 "property-name": "location",
81 "property-value-type": "string"
84 "property-name": "sub-nodes",
85 "property-value-type": "string"
90 "node-type": "l3-group",
91 "property-definition": [
93 #For example, one legal ip-address is 10.0.2.0/24.
94 "property-name": "ip-prefix",
95 "property-value-type": "string"
100 "node-type": "ext-group",
101 "property-definition": [
103 "property-name": "location",
104 "property-value-type": "string",
105 "is-required": "required"
108 "property-name": "ac-info-network",
109 "property-value-type": "string",
110 "is-required": "required"
113 "property-name": "ac-info-protocol",
114 "property-value-type": "string",
115 "is-required": "required"
118 "property-name": "ip-prefix",
119 "property-value-type": "string"
124 "node-type": "chain-group"
128 "property-definition": [
130 "property-name": "location",
131 "property-value-type": "string",
132 "is-required": "required"
135 "property-name": "operating-mode",
136 "property-value-type": "string",
137 "is-required": "required"
143 "property-definition": [
145 "property-name": "location",
146 "property-value-type": "string",
147 "is-required": "required"
150 "property-name": "operating-mode",
151 "property-value-type": "string",
152 "is-required": "required"
157 "node-type": "cache",
158 "property-definition": [
160 "property-name": "location",
161 "property-value-type": "string",
162 "is-required": "required"
165 "property-name": "operating-mode",
166 "property-value-type": "string",
167 "is-required": "required"
174 put(PREDEFINE_NODETYPE % contHost, data)
176 def add_predefined_connectiontypes(contHost):
178 "connection-definitions": {
179 "connection-definition":[
181 "connection-type": "p2p",
182 "property-definition": [
184 #the unit of bandwidth is mbps.
185 "property-name": "bandwidth",
186 "property-value-type": "int"
191 "connection-type": "p2mp",
192 "property-definition": [
194 #the unit of bandwidth is mbps.
195 "property-name": "bandwidth",
196 "property-value-type": "int"
201 "connection-type": "mesh",
202 "property-definition": [
204 #the unit of bandwidth is mbps.
205 "property-name": "bandwidth",
206 "property-value-type": "int"
211 "connection-type": "chain",
212 "property-definition": [
214 #the unit of bandwidth is mbps.
215 "property-name": "bandwidth",
216 "property-value-type": "int"
223 put(PREDEFINE_CONNECTIONTYPE % contHost, data)
225 def add_flow_matchtypes(contHost):
227 "match-item-definitions": {
228 "match-item-definition": [
230 #For example, one legal eth-type is arp.
231 "match-item-name": "eth-type",
232 "match-item-value-type": "string"
235 #For example, one legal src-mac is 00:00:0a:b7:01:90;
236 "match-item-name": "src-mac",
237 "match-item-value-type": "string"
240 #For example, one legal src-mac is 00:00:0a:b7:01:90;
241 "match-item-name": "dst-mac",
242 "match-item-value-type": "string"
245 #For example, one legal proto is http;
246 "match-item-name": "proto",
247 "match-item-value-type": "string"
250 #For example, one legal src-ip is 10.0.2.1;
251 "match-item-name": "src-ip",
252 "match-item-value-type": "string"
255 #For example, one legal dst-ip is 10.0.1.2;
256 "match-item-name": "dst-ip",
257 "match-item-value-type": "string"
260 #For example, one legal src-port is 80;
261 "match-item-name": "src-port",
262 "match-item-value-type": "int"
265 #For example, one legal dst-port is 22;
266 "match-item-name": "dst-port",
267 "match-item-value-type": "int"
272 put(PREDEFINE_FLOWMATCHTYPE % contHost, data)
274 def add_flow_properties(contHost):
276 "flow-property-definitions": {
277 "property-definition": [
279 "property-name": "path",
280 "property-value-type": "string"
285 put(PREDEFINE_FLOWPROPERTY % contHost, data)
287 def add_operation_actions(contHost):
289 "action-definitions": {
290 "action-definition": [
292 "action-name": "deny"
295 "action-name": "allow"
298 "action-name": "go-through",
299 "parameter-value-type": "string"
302 "action-name": "qos-bandwidth",
303 "parameter-value-type": "int"
308 put(PREDEFINE_OPERATIONACTION % contHost, data)
310 def add_operation_conditions(contHost):
312 "condition-parameter-definitions": {
313 "condition-parameter-definition": [
315 "parameter-name": "time",
316 "parameter-value-type": "string",
317 "parameter-match-patterns": {
318 "parameter-match-pattern": ["less-than" ,"not-less-than","equal","not-equal",
319 "greater-than","not-greater-than","between","periodical"]
324 put(PREDEFINE_OPERATIONCONDITION % contHost, data)
326 def add_port_attributes(conHost):
328 "physical-port-attribute-definitions":{
329 "physical-port-attribute-definition":[
331 "attribute-name":"location",
332 "attribute-value-type":"string",
333 "attribute-match-patterns":{
334 "attribute-match-pattern":["equal"]
340 put(PHYSICAL_PORT_ATTRIBUTE % conHost, data)
342 def add_node_attributes(conHost):
344 "physical-node-attribute-definitions":{
345 "physical-node-attribute-definition":[
347 "attribute-name":"location",
348 "attribute-value-type":"string",
349 "attribute-match-patterns":{
350 "attribute-match-pattern":["equal"]
354 "attribute-name":"capacity",
355 "attribute-value-type":"int",
356 "attribute-match-patterns":{
357 "attribute-match-pattern":["equal"]
363 put(PHYSICAL_NODE_ATTRIBUTE % conHost, data)
368 headers = {'Content-type': 'application/yang.data+json',
369 'Accept': 'application/yang.data+json'}
371 print json.dumps(data, indent=4, sort_keys=True)
372 r = requests.put(url, data=json.dumps(data), headers=headers, auth=HTTPBasicAuth(USERNAME, PASSWORD))
376 if __name__ == '__main__':
378 parser = argparse.ArgumentParser()
379 parser.add_argument('--controller', default='127.0.0.1', help='controller IP')
380 args=parser.parse_args()
382 print args.controller
384 add_predefined_userrole(args.controller)
385 add_predefined_nodetypes(args.controller)
386 add_predefined_connectiontypes(args.controller)
387 add_flow_matchtypes(args.controller)
388 add_flow_properties(args.controller)
389 add_operation_actions(args.controller)
390 add_operation_conditions(args.controller)
391 add_port_attributes(args.controller)
392 add_node_attributes(args.controller)