Add test script for NIC NEMO renderer
[nemo.git] / nemo-impl / src / test / resources / nic-bod.py
1 #!/usr/bin/python
2 #Filename:servicechain.py
3 import requests,json
4 import argparse, sys
5 from requests.auth import HTTPBasicAuth
6
7 USERNAME='admin'
8 PASSWORD='admin'
9
10 TRANSACTION_BEGIN="http://%s:8181/restconf/operations/nemo-intent:begin-transaction"
11 TRANSACTION_END="http://%s:8181/restconf/operations/nemo-intent:end-transaction"
12 REGISTER_USER="http://%s:8181/restconf/operations/nemo-intent:register-user"
13 STRUCTURE_UPDATE_USERS="http://%s:8181/restconf/operations/nemo-intent:structure-style-nemo-update"
14 PHYSICAL_NETWORK="http://%s:8181/restconf/config/generic-physical-network:physical-network"
15 NIC_INTENTS="http://%s:8181/restconf/config/intent:intents"
16 NIC_INTENT="http://%s:8181/restconf/config/intent:intents/intent/14ce424a-3e50-4a2a-ad5c-b29845158c8b"
17
18 def create_physical_network(contHost):
19         data={
20  "physical-network": {
21          "physical-hosts": {
22                  "physical-host": [
23                          {
24          "host-id": "22282cca-9a13-4d0c-a67e-a933ebb0b0ae",
25                                  "node-id": "openflow:2",
26                                  "host-name": "video-server2",
27                                  "mac-address": "00:00:00:00:00:04",
28                                  "port-id": "openflow:2:2",
29                                  "ip-addresses": {
30                                          "ip-address": [
31                                                  "192.168.12.4"
32                                          ]
33          }
34        },
35        {
36          "host-id": "7b796915-adf4-4356-b5ca-de005ac410c1",
37                "node-id": "openflow:1",
38                "host-name": "video-server1",
39                "mac-address": "00:00:00:00:00:01",
40                "port-id": "openflow:1:1",
41                "ip-addresses": {
42                        "ip-address": [
43                                "192.168.11.2"
44                        ]
45          }
46        },
47        {
48          "host-id": "6c787caa-156a-49ed-8546-547bdccf283c",
49                "node-id": "openflow:2",
50                "host-name": "vm2",
51                "mac-address": "00:00:00:00:00:03",
52                "port-id": "openflow:2:1",
53                "ip-addresses": {
54                        "ip-address": [
55                                "192.168.12.3"
56                        ]
57          }
58        },
59        {
60          "host-id": "1eaf9a67-a171-42a8-9282-71cf702f61dd",
61                "node-id": "openflow:1",
62                "host-name": "vm1",
63                "mac-address": "00:00:00:00:00:02",
64                "port-id": "openflow:1:2",
65                "ip-addresses": {
66                        "ip-address": [
67                                "192.168.12.2"
68                        ]
69          }
70        }
71      ]
72    },
73    "physical-nodes": {
74            "physical-node": [
75                    {
76          "node-id": "openflow:3",
77                            "attribute": [
78                                    {
79              "attribute-name": "location",
80                                            "attribute-value": {
81                                                    "string-value": "openflow:3"
82                                            }
83            }
84          ],
85          "node-type": "router",
86                            "physical-port": [
87                                    {
88              "port-id": "openflow:3:1",
89                                            "attribute": [
90                                                    {
91                  "attribute-name": "location",
92                                                            "attribute-value": {
93                                                                    "string-value": "openflow:3:1"
94                                                            }
95                }
96              ],
97              "port-type": "internal",
98                                            "mac-address": "BE:DB:79:24:0A:B1",
99                                            "bandwidth": 10240
100                                    },
101            {
102              "port-id": "openflow:3:2",
103                    "attribute": [
104                            {
105                  "attribute-name": "location",
106                                    "attribute-value": {
107                                            "string-value": "openflow:3:2"
108                                    }
109                }
110              ],
111              "port-type": "internal",
112                    "mac-address": "06:E7:27:6D:C2:A5",
113                    "bandwidth": 10240
114            },
115            {
116              "port-id": "openflow:3:3",
117                    "attribute": [
118                            {
119                  "attribute-name": "location",
120                                    "attribute-value": {
121                                            "string-value": "openflow:3:3"
122                                    }
123                }
124              ],
125              "port-type": "internal",
126                    "mac-address": "9E:00:76:D7:0C:1D",
127                    "bandwidth": 10240
128            },
129            {
130              "port-id": "openflow:3:4",
131                    "attribute": [
132                            {
133                  "attribute-name": "location",
134                                    "attribute-value": {
135                                            "string-value": "openflow:3:4"
136                                    }
137                }
138              ],
139              "port-type": "external",
140                    "mac-address": "00:00:00:00:03:04",
141                    "bandwidth": 10240
142            }
143          ]
144        },
145        {
146          "node-id": "openflow:4",
147                "attribute": [
148                        {
149              "attribute-name": "location",
150                                "attribute-value": {
151                                        "string-value": "openflow:4"
152                                }
153            }
154          ],
155          "node-type": "router",
156                "physical-port": [
157                        {
158              "port-id": "openflow:4:2",
159                                "attribute": [
160                                        {
161                  "attribute-name": "location",
162                                                "attribute-value": {
163                                                        "string-value": "openflow:4:2"
164                                                }
165                }
166              ],
167              "port-type": "external",
168                                "mac-address": "00:00:00:00:04:02",
169                                "bandwidth": 10240
170                        },
171            {
172              "port-id": "openflow:4:1",
173                    "attribute": [
174                            {
175                  "attribute-name": "location",
176                                    "attribute-value": {
177                                            "string-value": "openflow:4:1"
178                                    }
179                }
180              ],
181              "port-type": "internal",
182                    "mac-address": "4E:93:BE:EF:99:35",
183                    "bandwidth": 10240
184            }
185          ]
186        },
187        {
188          "node-id": "openflow:1",
189                "attribute": [
190                        {
191              "attribute-name": "location",
192                                "attribute-value": {
193                                        "string-value": "openflow:1"
194                                }
195            }
196          ],
197          "node-type": "switch",
198                "physical-port": [
199                        {
200              "port-id": "openflow:1:1",
201                                "attribute": [
202                                        {
203                  "attribute-name": "location",
204                                                "attribute-value": {
205                                                        "string-value": "openflow:1:1"
206                                                }
207                }
208              ],
209              "port-type": "external",
210                                "mac-address": "BA:8C:1F:60:2C:FC",
211                                "bandwidth": 10240
212                        },
213            {
214              "port-id": "openflow:1:2",
215                    "attribute": [
216                            {
217                  "attribute-name": "location",
218                                    "attribute-value": {
219                                            "string-value": "openflow:1:2"
220                                    }
221                }
222              ],
223              "port-type": "external",
224                    "mac-address": "82:ED:57:DE:28:F0",
225                    "bandwidth": 10240
226            },
227            {
228              "port-id": "openflow:1:3",
229                    "attribute": [
230                            {
231                  "attribute-name": "location",
232                                    "attribute-value": {
233                                            "string-value": "openflow:1:3"
234                                    }
235                }
236              ],
237              "port-type": "internal",
238                    "mac-address": "62:D3:F1:80:06:F0",
239                    "bandwidth": 10240
240            }
241          ]
242        },
243        {
244          "node-id": "openflow:2",
245                "attribute": [
246                        {
247              "attribute-name": "location",
248                                "attribute-value": {
249                                        "string-value": "openflow:2"
250                                }
251            }
252          ],
253          "node-type": "switch",
254                "physical-port": [
255                        {
256              "port-id": "openflow:2:3",
257                                "attribute": [
258                                        {
259                  "attribute-name": "location",
260                                                "attribute-value": {
261                                                        "string-value": "openflow:2:3"
262                                                }
263                }
264              ],
265              "port-type": "internal",
266                                "mac-address": "42:33:22:43:EF:02",
267                                "bandwidth": 10240
268                        },
269            {
270              "port-id": "openflow:2:2",
271                    "attribute": [
272                            {
273                  "attribute-name": "location",
274                                    "attribute-value": {
275                                            "string-value": "openflow:2:2"
276                                    }
277                }
278              ],
279              "port-type": "external",
280                    "mac-address": "32:7C:45:B9:ED:18",
281                    "bandwidth": 10240
282            },
283            {
284              "port-id": "openflow:2:1",
285                    "attribute": [
286                            {
287                  "attribute-name": "location",
288                                    "attribute-value": {
289                                            "string-value": "openflow:2:1"
290                                    }
291                }
292              ],
293              "port-type": "external",
294                    "mac-address": "D6:86:A8:54:2B:32",
295                    "bandwidth": 10240
296            }
297          ]
298        }
299      ]
300    },
301    "physical-links": {
302            "physical-link": [
303                    {
304          "link-id": "openflow:4:1",
305                            "loss-rate": 1,
306                            "delay": 1,
307                            "src-port-id": "openflow:4:1",
308                            "dest-node-id": "openflow:3",
309                            "metric": 1,
310                            "dest-port-id": "openflow:3:3",
311                            "bandwidth": 10240,
312                            "src-node-id": "openflow:4"
313                    },
314        {
315          "link-id": "openflow:2:3",
316                "loss-rate": 1,
317                "delay": 1,
318                "src-port-id": "openflow:2:3",
319                "dest-node-id": "openflow:3",
320                "metric": 1,
321                "dest-port-id": "openflow:3:2",
322                "bandwidth": 10240,
323                "src-node-id": "openflow:2"
324        },
325        {
326          "link-id": "openflow:3:1",
327                "loss-rate": 1,
328                "delay": 1,
329                "src-port-id": "openflow:3:1",
330                "dest-node-id": "openflow:1",
331                "metric": 1,
332                "dest-port-id": "openflow:1:3",
333                "bandwidth": 10240,
334                "src-node-id": "openflow:3"
335        },
336        {
337          "link-id": "openflow:1:3",
338                "loss-rate": 1,
339                "delay": 1,
340                "src-port-id": "openflow:1:3",
341                "dest-node-id": "openflow:3",
342                "metric": 1,
343                "dest-port-id": "openflow:3:1",
344                "bandwidth": 10240,
345                "src-node-id": "openflow:1"
346        },
347        {
348          "link-id": "openflow:3:3",
349                "loss-rate": 1,
350                "delay": 1,
351                "src-port-id": "openflow:3:3",
352                "dest-node-id": "openflow:4",
353                "metric": 1,
354                "dest-port-id": "openflow:4:1",
355                "bandwidth": 10240,
356                "src-node-id": "openflow:3"
357        },
358        {
359          "link-id": "openflow:3:2",
360                "loss-rate": 1,
361                "delay": 1,
362                "src-port-id": "openflow:3:2",
363                "dest-node-id": "openflow:2",
364                "metric": 1,
365                "dest-port-id": "openflow:2:3",
366                "bandwidth": 10240,
367                "src-node-id": "openflow:3"
368        }
369      ]
370    }
371  }
372                 }
373         put(PHYSICAL_NETWORK % contHost, data)
374
375
376 def register_user(contHost):
377         data={
378                         "input":{
379                                         "user-id":"14ce424a-3e50-4a2a-ad5c-b29845158c8b",
380                                         "user-name":"user2",
381                                         "user-password":"abc",
382                                         "user-role":"tenant"
383                                         }
384                 }
385         post(REGISTER_USER % contHost, data)
386
387 def transaction_begin(contHost):
388         data={
389                         "input":{
390                                         "user-id":"14ce424a-3e50-4a2a-ad5c-b29845158c8b"                                        
391                                         }
392                 }
393         post(TRANSACTION_BEGIN % contHost, data)
394
395 def transaction_end(contHost):
396         data={
397                         "input":{
398                                         "user-id":"14ce424a-3e50-4a2a-ad5c-b29845158c8b"                                
399                                         }
400                 }
401         post(TRANSACTION_END % contHost, data)
402
403 def add_server1_host(contHost):
404         data={
405                         "input":{                               
406                                   "user-id": "14ce424a-3e50-4a2a-ad5c-b29845158c8b",
407                                   "objects":{
408                                                 "node":[
409                                                                 {
410                                                                         "node-name": "server1",
411                                                                         "node-type": "host",
412                                                                         "node-id":"7b796915-adf4-4356-b5ca-de005ac410c1"
413                                                                 }
414                                                         ]
415                                                 }
416                                         }
417                 }
418         post(STRUCTURE_UPDATE_USERS % contHost, data)
419
420 def add_server2_host(contHost):
421         data={
422                         "input":{
423                                   "user-id": "14ce424a-3e50-4a2a-ad5c-b29845158c8b",
424                                   "objects":{
425                                                 "node":[
426                                                                 {
427                                                                         "node-name": "server2",
428                                                                         "node-type": "host",
429                                                                         "node-id":"22282cca-9a13-4d0c-a67e-a933ebb0b0ae"
430                                                                 }
431                                                         ]
432                                                 }
433                                         }
434                 }
435         post(STRUCTURE_UPDATE_USERS % contHost, data)
436
437 def add_vm1_host(contHost):
438         data={
439                         "input":{
440                                   "user-id": "14ce424a-3e50-4a2a-ad5c-b29845158c8b",
441                                   "objects":{
442                                                 "node":[
443                                                                 {
444                                                                         "node-name": "vm1",
445                                                                         "node-type": "host",
446                                                                         "node-id":"1eaf9a67-a171-42a8-9282-71cf702f61dd"
447                                                                 }
448                                                         ]
449                                                 }
450                                         }
451                 }
452         post(STRUCTURE_UPDATE_USERS % contHost, data)
453
454 def add_vm2_host(contHost):
455         data={
456                         "input":{
457                                   "user-id": "14ce424a-3e50-4a2a-ad5c-b29845158c8b",
458                                   "objects":{
459                                                 "node":[
460                                                                 {
461                                                                         "node-name": "vm2",
462                                                                         "node-type": "host",
463                                                                         "node-id":"6c787caa-156a-49ed-8546-547bdccf283c"
464                                                                 }
465                                                         ]
466                                                 }
467                                         }
468                 }
469         post(STRUCTURE_UPDATE_USERS % contHost, data)
470
471 def add_enterpise_node(contHost):
472         data={
473                   "input":{
474                           "user-id": "14ce424a-3e50-4a2a-ad5c-b29845158c8b",
475                           "objects":{
476                           "node":[
477                                           {
478                                                         "node-name": "enterprise",
479                                                         "node-type": "ext-group",
480                                                         "property": [
481                                                                                   {
482                                                                                         "property-name": "location",
483                                                                                         "property-values": {
484                                                                                                           "string-value": [
485                                                                                                                         {
486                                                                                                                           "order": "0",
487                                                                                                                           "value": "openflow:4:2"
488                                                                                                                         }
489                                                                                                                 ]
490                                                                                                         }
491                                                                                   },
492                                                                                   {
493                                                                                         "property-name": "ac-info-network",
494                                                                                         "property-values": {
495                                                                                                           "string-value": [
496                                                                                                                         {
497                                                                                                                           "order": "0",
498                                                                                                                           "value": "layer3"
499                                                                                                                         }
500                                                                                                                 ]
501                                                                                                         }
502                                                                                   },
503                                                                                   {
504                                                                                         "property-name": "ac-info-protocol",
505                                                                                         "property-values": {
506                                                                                                           "string-value": [
507                                                                                                                         {
508                                                                                                                           "order": "0",
509                                                                                                                           "value": "static"
510                                                                                                                         }
511                                                                                                                 ]
512                                                                                                         }
513                                                                                   },
514                                                                                   {
515                                                                                         "property-name": "ip-prefix",
516                                                                                         "property-values": {
517                                                                                                           "string-value": [
518                                                                                                                         {
519                                                                                                                           "order": "0",
520                                                                                                                           "value": "192.168.13.0/24"
521                                                                                                                         }
522                                                                                                                 ]
523                                                                                                         }
524                                                                                   }
525                                                                                 ],
526                                                         "node-id": "94a6fb90-b425-4ffd-9515-c0684aa4c37f"
527                                                   }
528                                         ]
529                           }
530                   }
531                 }
532         post(STRUCTURE_UPDATE_USERS % contHost, data)
533
534 def add_internet_node(contHost):
535         data={
536                   "input":{
537                           "user-id": "14ce424a-3e50-4a2a-ad5c-b29845158c8b",
538                           "objects":{
539                           "node":[
540                                           {
541                                                         "node-name": "internet",
542                                                         "node-type": "ext-group",
543                                                         "property": [
544                                                                                   {
545                                                                                         "property-name": "location",
546                                                                                         "property-values": {
547                                                                                                           "string-value": [
548                                                                                                                         {
549                                                                                                                           "order": "0",
550                                                                                                                           "value": "openflow:3:4"
551                                                                                                                         }
552                                                                                                                 ]
553                                                                                                         }
554                                                                                   },
555                                                                                   {
556                                                                                         "property-name": "ac-info-network",
557                                                                                         "property-values": {
558                                                                                                           "string-value": [
559                                                                                                                         {
560                                                                                                                           "order": "0",
561                                                                                                                           "value": "layer3"
562                                                                                                                         }
563                                                                                                                 ]
564                                                                                                         }
565                                                                                   },
566                                                                                   {
567                                                                                         "property-name": "ac-info-protocol",
568                                                                                         "property-values": {
569                                                                                                                 "string-value": [
570                                                                                                                         {
571                                                                                                                                 "order": "0",
572                                                                                                                                 "value": "static"
573                                                                                                                         }
574                                                                                                                 ]
575                                                                                                         }
576                                                                                   },
577                                                                                   {
578                                                                                         "property-name": "ip-prefix",
579                                                                                         "property-values": {
580                                                                                                           "string-value": [
581                                                                                                                         {
582                                                                                                                           "order": "0",
583                                                                                                                           #wait for external network ip
584                                                                                                                           "value": "172.168.1.0/24"
585                                                                                                                         }
586                                                                                                                 ]
587                                                                                                         }
588                                                                                   }
589                                                                                 ],
590                                                         "node-id": "d463232f-363f-491c-a6f5-097ed0a794d3"
591                                                   }
592                                         ]
593                           }
594                   }
595                 }
596         post(STRUCTURE_UPDATE_USERS % contHost, data)
597
598 def add_dmz_node(contHost):
599         data={
600                   "input":{
601                           "user-id": "14ce424a-3e50-4a2a-ad5c-b29845158c8b",
602                           "objects":{
603                           "node":[
604                                           {
605                                                         "node-name": "dmz",
606                                                         "node-type": "l2-group",
607                                                         "sub-node": [
608                                                                                   {
609                                                                                         "node-id":"7b796915-adf4-4356-b5ca-de005ac410c1",
610                                                                                         "order":"0"
611                                                                                   }
612                                                                 ],
613                                                         "property": [
614                                                                                   {
615                                                                                         "property-name": "location",
616                                                                                         "property-values": {
617                                                                                                           "string-value": [
618                                                                                                                         {
619                                                                                                                           "order": "0",
620                                                                                                                           "value": "openflow:3"
621                                                                                                                         }
622                                                                                                                 ]
623                                                                                                         }
624                                                                                   },
625                                                                                   {
626                                                                                         "property-name": "ip-prefix",
627                                                                                         "property-values": {
628                                                                                                           "string-value": [
629                                                                                                                         {
630                                                                                                                           "order": "0",
631                                                                                                                           "value": "192.168.11.0/24"
632                                                                                                                         }
633                                                                                                                 ]
634                                                                                                         }
635                                                                                   },
636                                                                                   {
637                                                                                         "property-name": "gateway-ip",
638                                                                                         "property-values": {
639                                                                                                           "string-value": [
640                                                                                                                         {
641                                                                                                                           "order": "0",
642                                                                                                                           "value": "192.168.11.1"
643                                                                                                                         }
644                                                                                                                 ]
645                                                                                                         }
646                                                                                   }
647                                                                                 ],
648                                                         "node-id": "b46cfa7f-93a3-43f4-ac20-09307c75feca"
649                                                   }
650                                         ]
651                           }
652                   }
653                 }
654         post(STRUCTURE_UPDATE_USERS % contHost, data)
655
656 def add_interior_node(contHost):
657         data={
658                   "input":{
659                           "user-id": "14ce424a-3e50-4a2a-ad5c-b29845158c8b",
660                           "objects":{
661                           "node":[
662                                           {
663                                                         "node-name": "interior",
664                                                         "node-type": "l2-group",
665                                                         "sub-node": [
666                                                                                   {
667                                                                                         "node-id":"22282cca-9a13-4d0c-a67e-a933ebb0b0ae",
668                                                                                         "order":"0"
669                                                                                   },
670                                                                                   {
671                                                                                         "node-id":"1eaf9a67-a171-42a8-9282-71cf702f61dd",
672                                                                                         "order":"0"
673                                                                                   },
674                                                                                   {
675                                                                                         "node-id":"6c787caa-156a-49ed-8546-547bdccf283c",
676                                                                                         "order":"0"
677                                                                                   }
678                                                                 ],
679                                                         "property": [
680                                                                                   {
681                                                                                         "property-name": "location",
682                                                                                         "property-values": {
683                                                                                                           "string-value": [
684                                                                                                                         {
685                                                                                                                           "order": "0",
686                                                                                                                           "value": "openflow:3"
687                                                                                                                         }
688                                                                                                                 ]
689                                                                                                         }
690                                                                                   },
691                                                                                   {
692                                                                                         "property-name": "ip-prefix",
693                                                                                         "property-values": {
694                                                                                                           "string-value": [
695                                                                                                                         {
696                                                                                                                           "order": "0",
697                                                                                                                           "value": "192.168.12.0/24"
698                                                                                                                         }
699                                                                                                                 ]
700                                                                                                         }
701                                                                                   },
702                                                                                   {
703                                                                                         "property-name": "gateway-ip",
704                                                                                         "property-values": {
705                                                                                                           "string-value": [
706                                                                                                                         {
707                                                                                                                           "order": "0",
708                                                                                                                           "value": "192.168.12.1"
709                                                                                                                         }
710                                                                                                                 ]
711                                                                                                         }
712                                                                                   }
713                                                                                 ],
714                                                         "node-id": "175425f7-c9c9-474a-962c-70cb6c180d4d"
715                                                   }
716                                         ]
717                           }
718                   }
719                 }
720         post(STRUCTURE_UPDATE_USERS % contHost, data)
721
722 def add_enterprise_interior_connection(contHost):
723         data={
724                  "input": {
725                           "user-id": "14ce424a-3e50-4a2a-ad5c-b29845158c8b",
726                           "objects":{
727                                   "connection": [
728                                                   {
729                                                         "connection-name": "c1",
730                                                         "connection-id": "30da6667-608e-4d2f-bb50-79e5cabcc523",
731                                                         "end-node": [
732                                                           {
733                                                                 "order": "0",
734                                                                 "node-id": "94a6fb90-b425-4ffd-9515-c0684aa4c37f"
735                                                           },
736                                                           {
737                                                                 "order": "0",
738                                                                 "node-id": "175425f7-c9c9-474a-962c-70cb6c180d4d"
739                                                           }
740                                                         ],
741                                                         "connection-type": "p2p",
742                                                         "property": [
743                                                                 {
744                                                                         "property-name": "bandwidth",
745                                                                         "property-values": {
746                                                                                                           "int-value": [
747                                                                                                                         {
748                                                                                                                           "order": "0",
749                                                                                                                           "value": "128"
750                                                                                                                         }
751                                                                                                                 ]
752                                                                                                         }
753                                                                 }
754                                                         ]
755                                                 }
756                                         ]
757                                 }
758                   }
759         }
760         post(STRUCTURE_UPDATE_USERS % contHost, data)
761
762 def add_interior_dmz_connection(contHost):
763         data={
764                  "input": {
765                           "user-id": "14ce424a-3e50-4a2a-ad5c-b29845158c8b",
766                           "objects":{
767                                   "connection": [
768                                                   {
769                                                         "connection-name": "c2",
770                                                         "connection-id": "b49e3960-c08d-4fff-b9fc-08b65ebcde2c",
771                                                         "end-node": [
772                                                           {
773                                                                 "order": "0",
774                                                                 "node-id": "175425f7-c9c9-474a-962c-70cb6c180d4d"
775                                                           },
776                                                           {
777                                                                 "order": "0",
778                                                                 "node-id": "b46cfa7f-93a3-43f4-ac20-09307c75feca"
779                                                           }
780                                                         ],
781                                                         "connection-type": "p2p"
782                                                 }
783                                         ]
784                                 }
785                   }
786         }
787         post(STRUCTURE_UPDATE_USERS % contHost, data)
788
789 def add_dmz_internet_connection(contHost):
790         data={
791                  "input": {
792                           "user-id": "14ce424a-3e50-4a2a-ad5c-b29845158c8b",
793                           "objects":{
794                                   "connection": [
795                                                   {
796                                                         "connection-name": "c3",
797                                                         "connection-id": "e0d56fee-7235-4748-a2a1-eb5e3733d866",
798                                                         "end-node": [
799                                                           {
800                                                                 "order": "0",
801                                                                 "node-id": "b46cfa7f-93a3-43f4-ac20-09307c75feca"
802                                                           },
803                                                           {
804                                                                 "order": "0",
805                                                                 "node-id": "d463232f-363f-491c-a6f5-097ed0a794d3"
806                                                           }
807                                                         ],
808                                                         "connection-type": "p2p"
809                                                 }
810                                         ]
811                                 }
812                   }
813         }
814         post(STRUCTURE_UPDATE_USERS % contHost, data)
815
816 def update_enterprise_interior_connection(contHost):
817         data={
818                  "input": {
819                           "user-id": "14ce424a-3e50-4a2a-ad5c-b29845158c8b",
820                           "objects":{
821                                   "connection": [
822                                                   {
823                                                         "connection-name": "c1",
824                                                         "connection-id": "30da6667-608e-4d2f-bb50-79e5cabcc523",
825                                                         "end-node": [
826                                                           {
827                                                                 "order": "0",
828                                                                 "node-id": "94a6fb90-b425-4ffd-9515-c0684aa4c37f"
829                                                           },
830                                                           {
831                                                                 "order": "0",
832                                                                 "node-id": "175425f7-c9c9-474a-962c-70cb6c180d4d"
833                                                           }
834                                                         ],
835                                                         "connection-type": "p2p",
836                                                         "property": [
837                                                                 {
838                                                                         "property-name": "bandwidth",
839                                                                         "property-values": {
840                                                                                                           "int-value": [
841                                                                                                                         {
842                                                                                                                           "order": "0",
843                                                                                                                           "value": "512"
844                                                                                                                         }
845                                                                                                                 ]
846                                                                                                         }
847                                                                 }
848                                                         ]
849                                                 }
850                                         ]
851                                 }
852                   }
853         }
854         post(STRUCTURE_UPDATE_USERS % contHost, data)
855
856 def delete_nic_intents(contHost):
857         delete(NIC_INTENTS % contHost)
858
859 def create_nic_intent(contHost):
860         data = {
861                 "intent": { 
862                         "id": "14ce424a-3e50-4a2a-ad5c-b29845158c8b", 
863                         "actions": [ 
864                                 { 
865          "order": 1, 
866                                         "allow": {} 
867                                 } 
868      ], 
869      "subjects": [ 
870              { 
871          "order": 1 , 
872                      "end-point-group": { "name": "dmz" } 
873              }, { 
874           "order": 2 , 
875                      "end-point-group": { "name": "interior" }
876              } 
877      ],
878      "constraints": [
879              {
880           "order": 1,
881                      "bandwidth-constraint": { "bandwidth": "10G" }
882              }
883      ],
884      "conditions": [
885              {
886           "order": 1,
887                      "daily": { "start-time": "08:00:00Z", "duration": "10h" }
888              }
889      ]
890 }
891                 }
892         put(NIC_INTENT % contHost, data)
893
894
895 def post(url, data):
896     headers = {'Content-type': 'application/yang.data+json',
897                'Accept': 'application/yang.data+json'}
898     print "POST %s" % url
899     print json.dumps(data, indent=4, sort_keys=True)
900     r = requests.post(url, data=json.dumps(data), headers=headers, auth=HTTPBasicAuth(USERNAME, PASSWORD))
901     print r.text
902     r.raise_for_status()
903
904 def put(url, data):
905     headers = {'Content-type': 'application/yang.data+json',
906                'Accept': 'application/yang.data+json'}
907     print "PUT %s" % url
908     print json.dumps(data, indent=4, sort_keys=True)
909     r = requests.put(url, data=json.dumps(data), headers=headers, auth=HTTPBasicAuth(USERNAME, PASSWORD))
910     print r.text
911     r.raise_for_status()
912
913 def delete(url):
914     headers = {'Content-type': 'application/yang.data+json',
915                'Accept': 'application/yang.data+json'}
916     print "DELETE %s" % url
917     r = requests.delete(url, headers=headers, auth=HTTPBasicAuth(USERNAME, PASSWORD))
918     print r.text
919     r.raise_for_status()
920
921
922 if __name__ == '__main__':
923
924         parser = argparse.ArgumentParser()
925         parser.add_argument('--controller', default='127.0.0.1', help='controller IP')
926         args=parser.parse_args()
927
928
929         create_physical_network(args.controller)
930
931         # CREATE User;
932         register_user(args.controller)
933
934         # IMPORT Node server1 Type host;
935         transaction_begin(args.controller)
936         add_server1_host(args.controller)
937         #transaction_end(args.controller)
938
939         # IMPORT Node server2 Type host;
940         #transaction_begin(args.controller)
941         add_server2_host(args.controller)
942         #transaction_end(args.controller)
943
944         # IMPORT Node vm1 Type host;
945         #transaction_begin(args.controller)
946         add_vm1_host(args.controller)
947         #transaction_end(args.controller)
948
949         # IMPORT Node vm2 Type host;
950         #transaction_begin(args.controller)
951         add_vm2_host(args.controller)
952         #transaction_end(args.controller)
953
954         # IMPORT Node enterprise Type ext-group Property location:openflow:4:2, ip-prefix:192.18.13.0/24;
955         #transaction_begin(args.controller)
956         add_enterpise_node(args.controller)
957         #transaction_end(args.controller)
958
959         # CREATE Node interior Type l2-group Contain server1,vm1,vm2;
960         #transaction_begin(args.controller)
961         add_interior_node(args.controller)
962         #transaction_end(args.controller)
963
964         # CREATE Node dmz Type l2-group Contain server2;
965         #transaction_begin(args.controller)
966         add_dmz_node(args.controller)
967         #transaction_end(args.controller)
968
969         # IMPORT Node internet Type ext-group Property location:openflow:3:4, ip-prefix:172.168.1.0/24;
970         #transaction_begin(args.controller)
971         add_internet_node(args.controller)
972         #transaction_end(args.controller)
973
974         # CREATE Connection c1 Endnodes enterprise,interior Property bandwidth:128(kbps);
975         #transaction_begin(args.controller)
976         #add_enterprise_interior_connection(args.controller)
977         #transaction_end(args.controller)
978
979         # CREATE Connection c2 Endnodes interior,dmz;
980         #transaction_begin(args.controller)
981         #add_interior_dmz_connection(args.controller)
982         #transaction_end(args.controller)
983
984         # CREATE Connection c3 Endnodes dmz,internet;
985         #transaction_begin(args.controller)
986         #add_dmz_internet_connection(args.controller)
987         #transaction_end(args.controller)
988
989         # UPDATE Connection c1 Endnodes enterprise,interior Property bandwidth:512(kbps);
990         #transaction_begin(args.controller)
991         #update_enterprise_interior_connection(args.controller)
992         #transaction_end(args.controller)
993
994         transaction_end(args.controller)
995
996         delete_nic_intents(args.controller)
997         create_nic_intent(args.controller)