-
Notifications
You must be signed in to change notification settings - Fork 0
/
aci_api_functions.py
1606 lines (1360 loc) · 86.3 KB
/
aci_api_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import absolute_import
from mysite.globals import *
import json
import re
import os
import requests
import urllib3
import collections
urllib3.disable_warnings()
def ping(ip_add):
response = os.system('ping -c 1 ' + ip_add)
if response == 0:
return True
else:
return False
class ACIconfig_by_API:
def __init__(self, ip_address, user, pwd):
self.user_name = user
self.password = pwd
self.ip_addr = ip_address
if self.test_connection():
self.get_token()
def test_connection(self):
if ping(self.ip_addr):
return True
else:
return False
def get_token(self):
r = requests.post('https://' + self.ip_addr + '/api/aaaLogin.json',
json={'aaaUser': {"attributes": {
'name': self.user_name, 'pwd': self.password}}},
verify=False)
r_json = r.json()
self.token = r_json["imdata"][0]["aaaLogin"]["attributes"]["token"]
# return self.token
# print self.token
# Get Details
def get_model_no(self,leaf):
path1 = 'https://198.18.133.200/api/node/mo/topology/pod-1/node-'+leaf+'.json'
token = self.token
cookie = {'APIC-cookie': token}
r = requests.get(path1, cookies=cookie, verify=False)
opt = r.json()
for data in opt['imdata']:
# leaf_data = {}
for k,v in data["fabricNode"]["attributes"].iteritems():
if 'model' in k:
return v
def get_leaf_list(self):
leaf_data_list = []
path1 = 'http://198.18.133.200/api/node/class/topology/pod-1/topSystem.json?query-target-filter=eq(topSystem.role,"leaf")&rsp-subtree-include=health,required'
# path = 'http://198.18.133.200/api/node/class/topology/pod-1/topSystem.json?query-target-filter=eq(topSystem.role,"spine")&rsp-subtree-include=health,required'
token = self.token
cookie = {'APIC-cookie': token}
# r1 = requests.get(path, cookies=cookie, verify=False)
r = requests.get(path1, cookies=cookie, verify=False)
opt = r.json()
# opt1=r1.json()
for data in opt['imdata']:
leaf_data = {}
for k,v in data["topSystem"]["attributes"].iteritems():
# print k,'>>>>',v
if "id" in k:
leaf_data["name"]= v
if "serial" in k:
leaf_data["serial"]= v
leaf_data_list.append(leaf_data)
return leaf_data_list
# print ele
def get_all_tenant(self):
# getting of all tenant
# token=""
tenant_lst = []
token = self.token
# print token, ">>>token"
cookie = {'APIC-cookie': token}
url = "https://" + self.ip_addr + "/api/class/fvTenant.json"
# print ("\nExecuting GET '%s'\n" % url)
# The request and response of "GET" request
resp = requests.get(url, cookies=cookie, verify=False)
data = resp.json()
for i in data["imdata"]:
tenant_lst.append(i["fvTenant"]["attributes"]["name"])
return tenant_lst
def get_epg_bd(self,tenant, app):
path1 = 'https://198.18.133.200/api/node/mo/uni/tn-'+tenant+'/ap-'+app+'.json?query-target=subtree&target-subtree-class=fvAEPg&query-target-filter=and(not(wcard(fvAEPg.dn,"__ui_")),eq(fvAEPg.isAttrBasedEPg,"false"))&rsp-subtree=children&rsp-subtree-class=fvRsBd'
token = self.token
cookie = {'APIC-cookie': token}
r = requests.get(path1, cookies=cookie, verify=False)
opt = r.json()
data = opt['imdata']
epg_list = []
bd_list = []
for i in data:
EPG = i['fvAEPg']['attributes']['name']
BD = i['fvAEPg']['children'][0]['fvRsBd']['attributes']['tnFvBDName']
epg_list.append(EPG)
bd_list.append(BD)
return {'epg':epg_list, 'bd':bd_list}
def get_port_details(self,leaf):
port_details_dict = {}
token = self.token
cookie = {'APIC-cookie': token}
url = "http://"+self.ip_addr+"/api/node/class/topology/pod-1/node-"+str(leaf)+"/l1PhysIf.json"
print ("\nExecuting GET '%s'\n" % url)
count = 0
resp = requests.get(url, cookies=cookie, verify=False)
data = resp.json()
for ele in data['imdata']:
details_dict = {}
count += 1
for k, v in ele["l1PhysIf"]["attributes"].iteritems():
if "id" in k:
details_dict['port'] = v
oper_state = self.oper_status(leaf,v)
policy = self.get_policy_get(leaf,v)
details_dict['policy'] = oper_state
details_dict['oper_state'] = oper_state
port_details_dict[details_dict['port']] = {}
if "adminSt" in k:
details_dict['admin_state'] = v
if "descr" in k:
details_dict['description'] = v
if 'port' in details_dict and details_dict['port'] in port_details_dict:
port_details_dict[details_dict['port']] = details_dict
# port_details_list.append(details_dict)
# print count
return port_details_dict
def get_policy_get(self,leaf,port):
path='http://'+self.ip_addr+'/api/node/class/infraHPathS.json?&rsp-subtree=full&query-target=subtree&query-target-filter=and(eq(infraRsHPathAtt.tDn,%22topology/pod-1/paths-'+leaf+'/pathep-['+port+']%22))'
token = self.token
cookie = {'APIC-cookie': token}
r = requests.get(path, cookies=cookie, verify=False)
opt = r.json()
policy = ""
for data in opt['imdata']:
port_details = data['infraRsHPathAtt']
for k, v in port_details['attributes'].iteritems():
if 'dn' in k:
m1 = re.search(r'hpaths\S(\S.+)/rsHPathAtt', v)
if m1:
unitno = m1.group(1)
path1='http://'+self.ip_addr+'/api/node/mo/uni/infra/hpaths-'+unitno+'/rspathToAccBaseGrp.json'
r1= requests.get(path1, cookies=cookie, verify=False)
opt1 = r1.json()
for data in opt1['imdata']:
port_details = data['infraRsPathToAccBaseGrp']
for k, v in port_details['attributes'].iteritems():
if 'tDn' in k:
m1 = re.search(r'accportgrp\S(\S.+)', v)
if m1:
policy = m1.group(1)
return policy
return policy
def get_port_stat(self, name, leaf, port):
state_dict = {}
overide_name = name + "_" + leaf + "_" + port.replace("/", "_")
path = 'http://' + self.ip_addr + \
'/api/node/mo/uni/infra/hpaths-' + overide_name + '.json'
token = self.token
cookie = {'APIC-cookie': token}
r = requests.get(path, cookies=cookie, verify=False)
# print r.json()
for elem in r.json()['imdata']:
overide_name = elem['infraHPathS']['attributes']['name']
descr = elem['infraHPathS']['attributes']['descr']
state_dict[overide_name] = {
'desc': descr, 'leaf_node': leaf, 'port': port}
break
path = 'http://' + self.ip_addr + '/api/node/mo/uni/infra/hpaths-' + \
overide_name + '/rspathToAccBaseGrp.json'
r = requests.get(path, cookies=cookie, verify=False)
for elem in r.json()['imdata']:
policy_grp = elem['infraRsPathToAccBaseGrp']['attributes']['tDn']
m2 = re.search(r'uni/infra/funcprof/accportgrp-(\S.+)', policy_grp)
if m2:
policy = m2.group(1)
state_dict[overide_name]['policy'] = policy
# c.update(s)
# js =
try:
with open('mysite/ACI_Rolback_Dir/' + name + ".json", 'r+') as json_file:
data1 = json.load(json_file)
print data1, ">>>>>>"
data1.update(state_dict)
with open('mysite/ACI_Rolback_Dir/' + name + ".json", 'w+') as data:
json.dump(data1, data)
except:
with open('mysite/ACI_Rolback_Dir/' + name + ".json", 'w+') as data:
json.dump(state_dict, data)
if len(state_dict.keys()) == 0:
return False
else:
return True
def apps_profile(self, tenant_name):
app_list = []
# path = 'http://'+self.ip_addr+'/api/node/api/node/class/pod-1/l1PhysIf.json'
path = 'http://' + self.ip_addr + '/api/node/mo/uni/tn-' + tenant_name + \
'.json?order-by=fvAp.name|asc&query-target=subtree&target-subtree-class=fvAp'
token = self.token
cookie = {'APIC-cookie': token}
r = requests.get(path, cookies=cookie, verify=False)
# print r
data = r.json()
for i in data["imdata"]:
app_list.append(i["fvAp"]["attributes"]["name"])
return app_list
def leaf_status_details(self, leaf_node, phy_port):
# leaf_node = response_dict['leaf_node']
# phy_port = response_dict['phy_port']
# print "Physial Port==============================>", phy_port
path = 'http://' + self.ip_addr + '/api/node/mo/topology/pod-1/node-' + leaf_node + '/sys/phys-[' + phy_port + '].json?rsp-subtree-include=full-deployment&target-node=all&target-path=l1EthIfToEPg'
token = self.token
cookie = {'APIC-cookie': token}
rsp = requests.get(path, cookies=cookie, verify=False)
op = rsp.json()
for each in op['imdata']:
# print "--------))))))", each
if "l1PhysIf" in each:
get_data = each['l1PhysIf']['attributes']
# print get_data
return get_data
else:
return {}
def get_override_name(self, leaf_node, phy_port):
overide_name = ''
path = 'https://'+self.ip_addr+'/api/node/class/infraHPathS.json?&rsp-subtree=full&query-target=subtree&query-target-filter=and(eq(infraRsHPathAtt.tDn,%22topology/pod-1/paths-'+leaf_node+'/pathep-['+phy_port+']%22))'
token = self.token
cookie = {'APIC-cookie': token}
rsp = requests.get(path, cookies=cookie, verify=False)
op = rsp.json()
for each in op['imdata']:
# print "--------))))))", each
if "infraRsHPathAtt" in each:
get_data = each['infraRsHPathAtt']['attributes']['dn']
match_data = re.search(r'hpaths-(\S+)/rs',get_data )
if match_data:
overide_name = match_data.group(1)
return overide_name
# Create On APIC
def Create_tenant(self, tenant_name):
# function to create tenant using json
token = self.token
r_json = {
"fvTenant": {
"attributes": {
"name": tenant_name}}}
cookie = {'APIC-cookie': token}
post_url = "https://" + self.ip_addr + "/api/mo/uni.json"
headers = {'content-type': 'application/json'}
r = requests.post(post_url, data=json.dumps(
r_json), cookies=cookie, verify=False)
r1 = r.json()
return r1
def Create_VrfBD(self, data_dict):
if data_dict['select_tenant'] == 'New':
tenant_name = data_dict['tenant_new']
get_vrf = data_dict['vrf_new']
get_bd = data_dict['bd_new']
else:
tenant_name = data_dict['tenant_name']
get_vrf = data_dict['vrf_name']
get_bd = data_dict['bd_name']
r_json = '<fvTenant name="' + tenant_name + '"><fvCtx name="' + get_vrf + '"/> <fvBD name="' + get_bd + '"> <fvRsCtx tnFvCtxName="' + get_vrf + '"/> ' \
'<fvSubnet ip="10.10.100.1/24"/> </fvBD></fvTenant>'
token = self.token
cookie = {'APIC-cookie': token}
# The url for the post ticket API reques
post_url = "https://" + self.ip_addr + \
"/api/node/mo/uni/tn-" + tenant_name + ".xml"
headers = {'content-type': 'application/xml'}
r = requests.post(post_url, data=r_json, cookies=cookie, verify=False)
# print ">>>>>>>", r.text
return r
def create_app_profile(self, data_dict):
if data_dict['select_tenant'] == 'New':
tenant_name = data_dict['tenant_new']
app_name = data_dict['app_name_new']
else:
tenant_name = data_dict['tenant_name']
app_name = data_dict['app_name']
path = 'http://' + self.ip_addr + '/api/node/mo/uni/tn-' + \
tenant_name + '/ap-' + app_name + '.json'
payload = '{"fvAp":{"attributes":{"dn":"uni/tn-' + tenant_name + '/ap-' + app_name + \
'","name":"' + app_name + '","rn":"ap-' + \
app_name + '","status":"created"},"children":[]}}'
token = self.token
cookie = {'APIC-cookie': token}
r = requests.post(path, cookies=cookie, data=payload, verify=False)
# print r
return r.json()
def create_epg(self, data_dict):
if data_dict['select_tenant'] == 'New':
tenant_name = data_dict['tenant_new']
app_name = data_dict['app_name_new']
epg_name = data_dict['epg_name_new']
bd_name = data_dict['bd_new']
else:
tenant_name = data_dict['tenant_name']
app_name = data_dict['app_name']
epg_name = data_dict['epg_name']
bd_name = data_dict['bd_name']
# path = 'http://'+self.ip_addr+'/api/node/api/node/class/pod-1/l1PhysIf.json'
path = 'http://' + self.ip_addr + '/api/node/mo/uni/tn-' + \
tenant_name + '/ap-' + app_name + '/epg-' + epg_name + '.json'
payload = '{"fvAEPg": {"attributes": {"dn": "uni/tn-' + tenant_name + '/ap-' + app_name + '/epg-' + epg_name + '", "name": "' + epg_name + '", "rn": "epg-' + epg_name + '","status": "created"}, ' \
'"children": [{"fvRsBd": {"attributes": {"tnFvBDName": "' + \
bd_name + '", "status": "created,modified"}, "children": []}}]}}'
token = self.token
cookie = {'APIC-cookie': token}
r = requests.post(path, cookies=cookie, data=payload, verify=False)
# print r
print r.json()
def create_policy_group(self, response_dict):
grp_name = response_dict['policy_name']
description = response_dict['description']
path = 'http://' + self.ip_addr + \
'/api/node/mo/uni/infra/funcprof/accportgrp-' + grp_name + '.json'
data = '{"infraAccPortGrp":{"attributes":{"dn":"uni/infra/funcprof/accportgrp-' + grp_name + '","name":"' + \
grp_name + '","descr":' + description + ',"rn":"accportgrp-' + \
grp_name + '","status":"created"},"children":[]}}'
token = self.token
cookie = {'APIC-cookie': token}
r = requests.post(path, data=data, cookies=cookie, verify=False)
return r.json()
def policy_group_create(self, name,speed):
llp2 = name + "_llp1280"
interface_prority_folw = name + "_interface_pfy20"
interface_fc_policy = "_interface_fc_policy2"
slow_drain = "_slow_drain"
cdp1 = name + "_cdp1"
mcp1 = name + "_mcp1"
lldp1 = name + "_lldp1"
stp_policy = name + "_stp_policy"
storm_control_policy = name + "_storm_control_policy"
L2_inter = name + "_L2_inter"
port_securit = name + "_port_securit"
Access_entity_profile = name + "_attached-entity"
path = 'http://' + self.ip_addr + \
'/api/node/mo/uni/infra/funcprof/accportgrp-' + name + '.json'
r_json = '{"infraAccPortGrp":{"attributes":{"dn":"uni/infra/funcprof/accportgrp-' + name + '","name":"' + name + '","rn":"accportgrp-' + name + '","status":"created"},' \
'"children":[{"infraRsHIfPol":{"attributes":{"tnFabricHIfPolName":"' + llp2 + '","status":"created,modified"},"children":[]}},' \
'{"infraRsQosPfcIfPol":{"attributes":{"tnQosPfcIfPolName":"' + interface_prority_folw + '","status":"created,modified"},"children":[]}},' \
'{"infraRsFcIfPol":{"attributes":{"tnFcIfPolName":"' + interface_fc_policy + '","status":"created,modified"},"children":[]}},' \
'{"infraRsQosSdIfPol":{"attributes":{"tnQosSdIfPolName":"' + slow_drain + '","status":"created,modified"},"children":[]}},' \
'{"infraRsCdpIfPol":{"attributes":{"tnCdpIfPolName":"' + cdp1 + '","status":"created,modified"},"children":[]}},' \
'{"infraRsMcpIfPol":{"attributes":{"tnMcpIfPolName":"' + mcp1 + '","status":"created,modified"},"children":[]}},' \
'{"infraRsLldpIfPol":{"attributes":{"tnLldpIfPolName":"' + lldp1 + '","status":"created,modified"},"children":[]}},' \
'{"infraRsAttEntP":{"attributes":{"tDn":"uni/infra/attentp-' + Access_entity_profile + '","status":"created,modified"},"children":[]}},' \
'{"infraRsStpIfPol":{"attributes":{"tnStpIfPolName":"' + stp_policy + '","status":"created,modified"},"children":[]}},' \
'{"infraRsStormctrlIfPol":{"attributes":{"tnStormctrlIfPolName":"' + storm_control_policy + '","status":"created,modified"},"children":[]}},' \
'{"infraRsL2IfPol":{"attributes":{"tnL2IfPolName":"' + L2_inter + '","status":"created,modified"},"children":[]}},' \
'{"infraRsL2PortSecurityPol":{"attributes":{"tnL2PortSecurityPolName":"' + \
port_securit + '","status":"created,modified"},"children":[]}}]}}'
token = self.token
cookie = {'APIC-cookie': token}
r_policy = requests.post(
path, data=r_json, cookies=cookie, verify=False)
# print '>>>>>>>>---------', r.json()
# return r.json()
path = 'http://' + self.ip_addr + \
'/api/node/mo/uni/infra/hintfpol-' + llp2 + '.json'
data = '{"fabricHIfPol":{"attributes":{"dn":"uni/infra/hintfpol-' + \
llp2 + '","descr":"any","autoNeg":"on","speed":"'+speed+'"},"children":[]}}'
r = requests.post(path, data=data, cookies=cookie, verify=False)
print r.json()
path = 'http://' + self.ip_addr + '/api/node/mo/uni/infra/pfc-' + \
interface_prority_folw + '.json'
data = '{"qosPfcIfPol":{"attributes":{"dn":"uni/infra/pfc-' + interface_prority_folw + '","name":"' + \
interface_prority_folw + '","rn":"pfc-' + \
interface_prority_folw + '","status":"created"},"children":[]}}'
r = requests.post(path, data=data, cookies=cookie, verify=False)
print r.json()
path = 'http://' + self.ip_addr + \
'/api/node/mo/uni/infra/fcIfPol-' + interface_fc_policy + '.json'
data = '{"fcIfPol":{"attributes":{"dn":"uni/infra/fcIfPol-' + interface_fc_policy + \
'","portMode":"f","trunkMode":"trunk-off","automaxspeed":"32G"},"children":[]}}'
r = requests.post(path, data=data, cookies=cookie, verify=False)
print r.json()
path = 'http://' + self.ip_addr + \
'/api/node/mo/uni/infra/qossdpol-' + slow_drain + '.json'
data = '{"qosSdIfPol":{"attributes":{"dn":"uni/infra/qossdpol-' + slow_drain + '","flushAdminSt":"disabled","name":"' + \
slow_drain + '","rn":"qossdpol-' + slow_drain + \
'","status":"created,modified"},"children":[]}}'
r = requests.post(path, data=data, cookies=cookie, verify=False)
print r.json()
path = 'http://' + self.ip_addr + '/api/node/mo/uni/infra/cdpIfP-' + cdp1 + '.json'
data = '{"cdpIfPol":{"attributes":{"dn":"uni/infra/cdpIfP-' + \
cdp1 + '"},"children":[]}}'
r = requests.post(path, data=data, cookies=cookie, verify=False)
print r.json()
path = 'http://' + self.ip_addr + '/api/node/mo/uni/infra/mcpIfP-' + mcp1 + '.json'
data = '{"mcpIfPol":{"attributes":{"dn":"uni/infra/mcpIfP-' + \
mcp1 + '","adminSt":"disabled"},"children":[]}}'
r = requests.post(path, data=data, cookies=cookie, verify=False)
print r.json()
path = 'http://' + self.ip_addr + \
'/api/node/mo/uni/infra/lldpIfP-' + lldp1 + '.json'
data = '{"lldpIfPol":{"attributes":{"dn":"uni/infra/lldpIfP-' + lldp1 + \
'","descr":"test","adminRxSt":"enabled","adminTxSt":"enabled"},"children":[]}}'
r = requests.post(path, data=data, cookies=cookie, verify=False)
print r.json()
path = 'http://' + self.ip_addr + \
'/api/node/mo/uni/infra/ifPol-' + stp_policy + '.json'
data = '{"stpIfPol":{"attributes":{"dn":"uni/infra/ifPol-' + \
stp_policy + '","descr":"test"},"children":[]}}'
r = requests.post(path, data=data, cookies=cookie, verify=False)
print r.json()
path = 'http://' + self.ip_addr + \
'/api/node/mo/uni/infra/stormctrlifp-' + storm_control_policy + '.json'
data = '{"stormctrlIfPol":{"attributes":{"dn":"uni/infra/stormctrlifp-' + storm_control_policy + \
'","rate":"100.000000","burstRate":"100.000000","isUcMcBcStormPktCfgValid":"Invalid"},"children":[]}}'
r = requests.post(path, data=data, cookies=cookie, verify=False)
print r.json()
path = 'http://' + self.ip_addr + \
'/api/node/mo/uni/infra/l2IfP-' + L2_inter + '.json'
data = '{"l2IfPol":{"attributes":{"dn":"uni/infra/l2IfP-' + L2_inter + \
'","vlanScope":"portlocal","vepa":"disabled"},"children":[]}}'
r = requests.post(path, data=data, cookies=cookie, verify=False)
print r.json()
# path = 'http://'+self.ip_addr+'/api/node/mo/uni/infra/portsecurityP-' + port_securit + '.json'
#
# data = '{"l2PortSecurityPol":{"attributes":{"timeout":"60","descr":"sssdddd","name":' + port_securit + '},"children":[]}}'
path = 'http://' + self.ip_addr + '/api/node/mo/uni/infra/funcprof/accportgrp-' + \
name + '/rsl2PortSecurityPol.json'
data = '{"infraRsL2PortSecurityPol":{"attributes":{"tnL2PortSecurityPolName":"port_security_policy"},"children":[]}}'
r = requests.post(path, data=data, cookies=cookie, verify=False)
print r.json()
path = 'http://198.18.133.200/api/node/mo/uni/infra/attentp-' + \
Access_entity_profile + '.json'
data = '{"infraAttEntityP":{"attributes":{"dn":"uni/infra/attentp-' + Access_entity_profile + '","name":"' + Access_entity_profile + '",' \
'"rn":"attentp-' + Access_entity_profile + '","status":"created"},' \
'"children":[{"infraProvAcc":{"attributes":{"dn":"uni/infra/attentp-' + Access_entity_profile + '/provacc","status":"created"},' \
'"children":[]}},{"infraRsDomP":{"attributes":{"tDn":"uni/phys-vlan_domain_1","status":"created"},"children":[]}}]}}'
r = requests.post(path, data=data, cookies=cookie, verify=False)
print r.json()
return r_policy.json()
# Physical Provision
def Deploy_EPG(self, data_dict):
token = self.token
tenant_name = data_dict['tenant']
vrf_name = data_dict['vrf']
bd_name = data_dict['bd']
app_name = data_dict['app']
epg_name = data_dict['epg']
leaf_id = data_dict['leaf_id']
phy_port = data_dict['port']
mode = data_dict['mode']
vlan = data_dict['vlan']
# regular ---> Trunk
# untagged ---> Access
req_xml = '<fvTenant name="' + tenant_name + '" dn="uni/tn-' + tenant_name + '" > <fvCtx name="' + vrf_name + '" pcEnfPref="enforced" knwMcastAct="permit"/><fvBD name="' + bd_name + '" unkMcastAct="flood" ><fvRsCtx tnFvCtxName="' + vrf_name + '"/></fvBD><fvAp name="' + app_name + '" > <fvAEPg name="' + epg_name + '" ><fvRsPathAtt tDn="topology/pod-1/paths-' + leaf_id + '/pathep-[' + phy_port + ']" mode="' + mode + '" instrImedcy="immediate" encap="vlan-' + vlan + '"/></fvAEPg></fvAp></fvTenant>'
cookie = {'APIC-cookie': token}
# The url for the post ticket API reques
post_url = 'https://' + self.ip_addr + \
'/api/node/mo/uni/tn-' + tenant_name + '.xml'
headers = {'content-type': 'application/xml'}
r = requests.post(post_url, data=req_xml, cookies=cookie, verify=False)
return r
def oper_status(self,leaf,port):
path = 'https://198.18.133.200/api/node/mo/topology/pod-1/node-'+leaf+'/sys/phys-['+port+'].json?query-target=children&target-subtree-class=ethpmPhysIf'
token = self.token
cookie = {'APIC-cookie': token}
r = requests.get(path, cookies=cookie, verify=False)
opt = r.json()
port_data = []
for data in opt['imdata']:
# print ">>>>>>", data
if 'ethpmPhysIf' in data:
port_details = data['ethpmPhysIf']['attributes']
return port_details['operSt']
else:
return {}
def enable_disable_switch_port(self, port, leaf_id, action):
print "am here"
path = 'https://' + self.ip_addr + '/api/node/mo/uni/fabric/outofsvc.json'
if action == 'disable':
data = '{"fabricRsOosPath":{"attributes":{"dn":"uni/fabric/outofsvc/rsoosPath-[topology/pod-1/paths-' + \
leaf_id + '/pathep-[' + port + \
']]","lc":"blacklist"},"children":[]}}'
elif action == 'enable':
data = '{"fabricRsOosPath":{"attributes":{"dn":"uni/fabric/outofsvc/rsoosPath-[topology/pod-1/paths-%s/pathep-[%s]]","status":"deleted"},"children":[]}}' % (
leaf_id, port)
# print data
token = self.token
cookie = {'APIC-cookie': token}
r = requests.post(path, data=data, cookies=cookie, verify=False)
# req = self.post(path,data)
return r
def port_provision(self, leaf, interface, response_data):
# print " In Port Provision "
print leaf, interface, response_data
name = response_data['work_order_no']
# dsc = response_data['action'] + \
# " for Work Order No. " + name.split('_')[0]
# dsc = name.split('_')[0] +'_'+ response_data['Desc_int_{}'.format(interface.title())]
if 'description' in response_data and len(response_data['description'])!=0:
dsc = name.split('_')[0]+"_"+response_data['action']+"_"+response_data['description']
else:
dsc = name.split('_')[0]+"_"+response_data['action']
policy_grp = response_data['policy_grp']
leaf_node = leaf
port = interface
state = response_data['admin_state']
port_status = self.leaf_status_details(leaf, interface)
oper_status = self.oper_status(leaf, interface)
policy_status = self.get_policy_get(leaf, interface)
path = 'http://' + self.ip_addr + '/api/node/mo/uni/infra/hpaths-' + name + '.json'
token = self.token
# Enable / Disable
cookie = {'APIC-cookie': token}
# rsp = requests.post(path, cookies=cookie, data=data, verify=False)
# Enable / Disable
port_state = self.enable_disable_switch_port(port, leaf_node, state)
print oper_status !="up"
if oper_status !="up" :
if response_data['action'] == "Reservation" and not policy_status:
data = '{"infraHPathS":{"attributes":{"dn":"uni/infra/hpaths-' + name + '","name":"' + name + '","status":"created,modified","descr":"' + dsc + '","rn":"hpaths-' + name + \
'"},"children":[{"infraRsHPathAtt":{"attributes":{"tDn":"topology/pod-1/paths-' + leaf_node + '/pathep-[' + port + \
']"},"children":[]}}],"children":[{"infraRsPathToAccBaseGrp":{"attributes":{"tDn":"uni/infra/funcprof/accportgrp-' + \
policy_grp + '","status":"created,modified"}}}]}}'
rsp = requests.post(path, cookies=cookie, data=data, verify=False)
print rsp
return rsp.json()
elif response_data['action'] == "Provision" and not policy_status:
desc_port = 'Eth1/'+interface.split('/')[1]
print desc_port
if name.split('_')[0] not in response_data['Desc_int_{}'.format(desc_port.title())].split("_")[0]:
dsc = name.split('_')[0] +'_'+ response_data['Desc_int_{}'.format(desc_port.title())]
else:
dsc = response_data['Desc_int_{}'.format(desc_port.title())]
# policy_gen = self.policy_group_create(response_data['policy_grp'], response_data['speed'])
data = '{"infraHPathS":{"attributes":{"dn":"uni/infra/hpaths-' + name + '","name":"' + name + '","status":"created,modified","descr":"' + dsc + '","rn":"hpaths-' + name + \
'"},"children":[{"infraRsHPathAtt":{"attributes":{"tDn":"topology/pod-1/paths-' + leaf_node + '/pathep-[' + port + \
']"},"children":[]}}],"children":[{"infraRsPathToAccBaseGrp":{"attributes":{"tDn":"uni/infra/funcprof/accportgrp-' + \
policy_grp + '","status":"created,modified"}}}]}}'
rsp = requests.post(path, cookies=cookie, data=data, verify=False)
print '>>>>>>>',rsp
if type(response_data['vlan_id']) == list:
for ele in response_data['vlan_id']:
vlan_detail = ele.split('-')
vlan = vlan_detail[0]
epg = vlan_detail[1]
bd = vlan_detail[2]
app = response_data['application']
# Deploy EPG API call
data_dict = {'tenant': response_data['tenant_name'], 'app': app, 'bd': bd,
'mode': response_data['port_mode'], 'vlan': vlan,
'vrf': 'Prod-VRF-1',
'port': interface, 'leaf_id': leaf, 'epg': epg}
deploy_epg = self.Deploy_EPG(data_dict)
print '>>>>>>>----------', deploy_epg
else:
vlan_detail = response_data['vlan_id'].split('-')
vlan = vlan_detail[0]
epg = vlan_detail[1]
bd = vlan_detail[2]
# app = response_data['application']
app = 'new_app'
# Deploy EPG API call
data_dict = {'tenant': response_data['tenant_name'], 'app': app, 'bd': bd,
'mode': response_data['port_mode'], 'vlan': vlan,
'vrf': 'Prod-VRF-1',
'port': interface, 'leaf_id': leaf, 'epg': epg}
deploy_epg = self.Deploy_EPG(data_dict)
print '>>>>>>>----------', deploy_epg
return rsp.json()
else:
return {'imdata':[{'error':{"attributes":{'text':"Validation failed : Alredy Have Policy "}}}]}
else:
return {'imdata':[{'error':{"attributes":{'text':"Validation failed : Port is UP and Having description "}}}]}
def port_provision_bulk(self, leaf, interface, response_data):
# print " In Port Provision "
print leaf, interface, response_data
name = response_data['work_order_no']
# dsc = response_data['action'] + \
# " for Work Order No. " + name.split('_')[0]
# dsc = name.split('_')[0] +'_'+ response_data['Desc_int_{}'.format(interface.title())]
if 'description' in response_data and len(response_data['description'])!=0:
dsc = name.split('_')[0]+"_"+response_data['action']+"_"+response_data['description']
else:
dsc = name.split('_')[0]+"_"+response_data['action']
policy_grp = response_data['policy_grp']
leaf_node = leaf
port = interface
state = response_data['admin_state']
port_status = self.leaf_status_details(leaf, interface)
oper_status = self.oper_status(leaf, interface)
policy_status = self.get_policy_get(leaf, interface)
path = 'http://' + self.ip_addr + '/api/node/mo/uni/infra/hpaths-' + name + '.json'
token = self.token
# Enable / Disable
cookie = {'APIC-cookie': token}
# rsp = requests.post(path, cookies=cookie, data=data, verify=False)
# Enable / Disable
port_state = self.enable_disable_switch_port(port, leaf_node, state)
print oper_status !="up"
if oper_status !="up" :
if response_data['action'] == "Reservation" and not policy_status:
data = '{"infraHPathS":{"attributes":{"dn":"uni/infra/hpaths-' + name + '","name":"' + name + '","status":"created,modified","descr":"' + dsc + '","rn":"hpaths-' + name + \
'"},"children":[{"infraRsHPathAtt":{"attributes":{"tDn":"topology/pod-1/paths-' + leaf_node + '/pathep-[' + port + \
']"},"children":[]}}],"children":[{"infraRsPathToAccBaseGrp":{"attributes":{"tDn":"uni/infra/funcprof/accportgrp-' + \
policy_grp + '","status":"created,modified"}}}]}}'
rsp = requests.post(path, cookies=cookie, data=data, verify=False)
print rsp
return rsp.json()
elif response_data['action'] == "Provision" and not policy_status:
desc_port = 'Eth1/'+interface.split('/')[1]
print desc_port
if name.split('_')[0] not in response_data['Desc_int_{}'.format(desc_port.title())].split("_")[0]:
dsc = name.split('_')[0] +'_'+ response_data['Desc_int_{}'.format(desc_port.title())]
else:
dsc = response_data['Desc_int_{}'.format(desc_port.title())]
# policy_gen = self.policy_group_create(response_data['policy_grp'], response_data['speed'])
data = '{"infraHPathS":{"attributes":{"dn":"uni/infra/hpaths-' + name + '","name":"' + name + '","status":"created,modified","descr":"' + dsc + '","rn":"hpaths-' + name + \
'"},"children":[{"infraRsHPathAtt":{"attributes":{"tDn":"topology/pod-1/paths-' + leaf_node + '/pathep-[' + port + \
']"},"children":[]}}],"children":[{"infraRsPathToAccBaseGrp":{"attributes":{"tDn":"uni/infra/funcprof/accportgrp-' + \
policy_grp + '","status":"created,modified"}}}]}}'
rsp = requests.post(path, cookies=cookie, data=data, verify=False)
print '>>>>>>>',rsp
if type(response_data['vlan_id']) == list:
for ele in response_data['vlan_id']:
vlan_detail = ele.split('-')
vlan = vlan_detail[0]
epg = vlan_detail[1]
bd = vlan_detail[2]
app = response_data['application']
# Deploy EPG API call
data_dict = {'tenant': response_data['tenant_name'], 'app': app, 'bd': bd,
'mode': response_data['port_mode'], 'vlan': vlan,
'vrf': 'Prod-VRF-1',
'port': interface, 'leaf_id': leaf, 'epg': epg}
deploy_epg = self.Deploy_EPG(data_dict)
print '>>>>>>>----------', deploy_epg
else:
vlan_detail = response_data['vlan_id'].split('-')
vlan = vlan_detail[0]
epg = vlan_detail[1]
bd = vlan_detail[2]
app = response_data['application']
# app = 'new_app'
# Deploy EPG API call
data_dict = {'tenant': response_data['tenant_name'], 'app': app, 'bd': bd,
'mode': response_data['port_mode'], 'vlan': vlan,
'vrf': 'Prod-VRF-1',
'port': interface, 'leaf_id': leaf, 'epg': epg}
deploy_epg = self.Deploy_EPG(data_dict)
print '>>>>>>>----------', deploy_epg
return rsp.json()
else:
return {'imdata':[{'error':{"attributes":{'text':"Validation failed : Alredy Have Policy "}}}]}
else:
return {'imdata':[{'error':{"attributes":{'text':"Validation failed : Port is UP and Having description "}}}]}
def list_policygroups(self):
policy_grps = []
path = 'http://' + self.ip_addr + '/api/node/class/infraAccPortGrp.json'
token = self.token
cookie = {'APIC-cookie': token}
r = requests.get(path, cookies=cookie, verify=False)
# req = self.post(path,data)
print r
for elem in r.json()['imdata']:
# print ">>>>>", elem
for k, v in elem.iteritems():
policy_grps.append(v['attributes']['name'])
return policy_grps
def list_PortChannel_policygroups(self):
policy_grps = []
path = 'http://' + self.ip_addr + '/api/node/class/infraAccBndlGrp.json'
token = self.token
cookie = {'APIC-cookie': token}
r = requests.get(path, cookies=cookie, verify=False)
# req = self.post(path,data)
print r
for elem in r.json()['imdata']:
for k, v in elem.iteritems():
policy_grps.append(v['attributes']['name'])
return policy_grps
def deprovision_port_bulk(self, response_dict):
print '>>>>>>', response_dict
name = response_dict['config_name']
# port = response_dict['physical_ports']
# leaf_node = response_dict['leaf_id_deprovision']
# # action = response_dict['admin_state']
# action = "disable"
path = 'http://' + self.ip_addr + '/api/node/mo/uni/infra/hpaths-' + name + '.json'
data = '{"infraHPathS":{"attributes":{"dn":"uni/infra/hpaths-' + \
name + '","status":"deleted"},"children":[]}}'
print data, "???>>>>>>>>"
token = self.token
cookie = {'APIC-cookie': token}
r = requests.post(path, data=data, cookies=cookie, verify=False)
# port_state = self.enable_disable_switch_port(action)
# print r
return r.json()
# Rollback Functions
def rollback_state(self, name):
token = self.token
cookie = {'APIC-cookie': token}
# name = "REQ0000020"
op_list = []
with open('mysite/ACI_Rolback_Dir/' + name + ".json", "r+") as json_file:
data1 = json.load(json_file)
for k, v in data1.iteritems():
overridename = k
leaf = v['leaf_node']
port = v['port']
policy = v['policy']
desc = v['desc']
path = 'http://' + self.ip_addr + \
'/api/node/mo/uni/infra/hpaths-' + overridename + '.json'
data = '{"infraHPathS":{"attributes":{"dn":"uni/infra/hpaths-' + overridename + '","name":"' + overridename + '","status":"created,modified","descr":"' + desc + '","rn":"hpaths-' + overridename + \
'"},"children":[{"infraRsHPathAtt":{"attributes":{"tDn":"topology/pod-1/paths-' + leaf + '/pathep-[' + port + \
']"},"children":[]}}],"children":[{"infraRsPathToAccBaseGrp":{"attributes":{"tDn":"uni/infra/funcprof/accportgrp-' + \
policy + '","status":"created,modified"}}}]}}'
r = requests.post(path, cookies=cookie,
data=data, verify=False)
# req = self.post(path,data)
print r.json()
if len(r.json()['imdata']) == 0:
op_list.append((True, leaf, port))
else:
op_list.append((False, leaf, port))
return op_list
# Port-Channel Functions
def PC_VPC_port_provision(self,leaf, port, response_data):
profile_name = response_data['profile_grp']
vpc = response_data['pc_policy_grp']
phy_port = port.replace(' ', '')
port1 = port.split('/')[1]
name = profile_name + '_' + phy_port.replace('/', '_')
description = profile_name + '_' + phy_port.replace('/', '_')
print profile_name,vpc,name,description
path = ' http://'+self.ip_addr+'/api/node/mo/uni/infra/accportprof-'+profile_name+'.json'
data = '{"infraAccPortP":{"attributes":{"dn":"uni/infra/accportprof-'+profile_name+'","name":' \
'"'+profile_name+'","descr":"ss","rn":"accportprof-'+profile_name+'","status":"created,modified"}' \
',"children":[{"infraHPortS":{"attributes":{"dn":"uni/infra/accportprof-'+profile_name+'' \
'/hports-'+name+'-typ-range","name":"'+name+'","descr":"ttt","rn":"hports-'+name+'-typ-range",' \
'"status":"created,modified"},"children":[{"infraPortBlk":{"attributes":{"dn":"uni/infra/' \
'accportprof-'+profile_name+'/hports-'+name+'-typ-range/portblk-block3","fromPort":"'+port1+'","toPort":"'+port1+'",' \
'"name":"block3","rn":"portblk-block3","status":"created,modified"},"children":[]}},' \
'{"infraRsAccBaseGrp":{"attributes":{"tDn":"uni/infra/funcprof/accbundle-'+vpc+'","status":' \
'"created,modified"},"children":[]}}]}}]}}'
token = self.token
cookie = {'APIC-cookie': token}
r = requests.post(path, data=data, cookies=cookie, verify=False)
print r.json(),"group"
# path = ' http://198.18.133.200/api/node/mo/uni/infra/accportprof-'+policy_name+'.json'
# data = '{"infraAccPortP":{"attributes":{"dn":"uni/infra/accportprof-'+policy_name+'","name":' \
# '"'+policy_name+'","descr":"ss","rn":"accportprof-'+policy_name+'","status":"created,modified"}' \
# ',"children":[{"infraHPortS":{"attributes":{"dn":"uni/infra/accportprof-'+policy_name+'' \
# '/hports-'+name+'-typ-range","name":"'+name+'","descr":"ttt","rn":"hports-'+name+'-typ-range",' \
# '"status":"created,modified"},"children":[{"infraPortBlk":{"attributes":{"dn":"uni/infra/' \
# 'accportprof-'+policy_name+'/hports-'+name+'-typ-range/portblk-block2","fromPort":"'+fromPort+'","toPort":"'+toPort+'",' \
# '"name":"block2","rn":"portblk-block2","status":"created,modified"},"children":[]}},' \
# '{"infraRsAccBaseGrp":{"attributes":{"tDn":"uni/infra/funcprof/accbundle-'+vpc+'","status":' \
# '"created,modified"},"children":[]}}]}}]}}'
# token = get_auth_token()
# cookie = {'APIC-cookie': token}
# r = requests.post(path, data=data, cookies=cookie, verify=False)
# print r.json(),"group"
# path = ' http://198.18.133.200/api/node/mo/uni/infra/funcprof/accbundle-'+vpc+'.json'
# data='{"infraAccBndlGrp":{"attributes":{"dn":"uni/infra/funcprof/accbundle-'+vpc+'","lagT":"node","name":"'+vpc+'","descr":"vpc",' \
# '"rn":"accbundle-'+vpc+'","status":"created,modifed"},"children":[]}}]}}'
# token = get_auth_token()
# cookie = {'APIC-cookie': token}
# r = requests.post(path, data=data, cookies=cookie, verify=False)
# print r.json(),"policy"
# path = ' http://198.18.133.200/api/node/mo/uni/infra/funcprof/accbundle-'+vpc+'.json'
# data='{"infraAccBndlGrp":{"attributes":{"dn":"uni/infra/funcprof/accbundle-'+vpc+'","lagT":"node","name":"'+vpc+'","descr":"vpc",' \
# '"rn":"accbundle-'+vpc+'","status":"created,modifed"},"children":[]}}]}}'
# token = self.token
# cookie = {'APIC-cookie': token}
# r = requests.post(path, data=data, cookies=cookie, verify=False)
return r.json()
def portchannel_group_create2(self, pc_group_name, PC_policy_name):
path = ' http://' + self.ip_addr + '/api/node/mo/uni/infra.json'
data = '{"infraAccBndlGrp":{"attributes":{"dn":"uni/infra/funcprof/accbundle-' + pc_group_name + '",' '"name":"' + pc_group_name + '","descr":"testing port channel","rn":"accbundle-' + pc_group_name + '",' '"status":"created"},"children":[{"infraRsLacpPol":{"attributes":{"tnLacpLagPolName":"' + PC_policy_name + '",''"status":"created,modified"},"children":[]}}]}}'
token = self.token
cookie = {'APIC-cookie': token}
r = requests.post(path, data=data, cookies=cookie, verify=False)
return r.json()
def portchannel_policy_create(self, policy_name, PC_mode, desc):
path = 'http://' + self.ip_addr + \
'/api/node/mo/uni/infra/lacplagp-' + policy_name + '.json'
data = '{"lacpLagPol":{"attributes":{"dn":"uni/infra/lacplagp-' + policy_name + '","name":"' + policy_name + '",' \
'"descr":"' + desc + ' ","mode":"' + PC_mode + '","rn":"lacplagp-' + \
policy_name + '","status":"created"},"children":[]}}'
token = self.token
cookie = {'APIC-cookie': token}
r = requests.post(path, data=data, cookies=cookie, verify=False)
return r.json()
def portchannel_group_assign(self, leaf, pc_policy_grp, port,profile_name, response_data):
op_dict = {'provision_status':'', 'Error': ''}
Provision_flag = False
port_status = self.leaf_status_details(leaf, port)
oper_status = self.oper_status(leaf, port)
policy_status = self.get_policy_get(leaf, port)
# phy_port = port.replace(' ', '')
# port1 = port.split('/')[1]
# name = profile_name + '_' + phy_port.replace('/', '_')
description = profile_name + '_' + port.replace('/', '_')
if oper_status !="up" :
if response_data['action'] == "Provision":
port1 = port.split('/')
path = 'http://' + self.ip_addr + '/api/node/mo/uni/infra.json'
data = '{"infraInfra":{"attributes":{"dn":"uni/infra","status":"modified"},"children":[{"infraAccPortP":{"attributes":' \
'{"dn":"uni/infra/accportprof-'+profile_name+'","name":"'+profile_name+'",' \
'"descr":"'+description+'","status":"created,modified"},"children":[' \
'{"infraHPortS":{"attributes":{"dn":"uni/infra/accportprof-'+profile_name+'/hports-leaf-' + leaf + '_1-ports-' + \
port1[1] + '-typ-range","name":"leaf-' + leaf + '_1-ports-' + port1[1] + '","type":"range",' \
'"status":"created,modified"},"children":[{"infraPortBlk":{"attributes":' \
'{"dn":"uni/infra/accportprof-'+profile_name+'/hports-leaf-' + leaf + '_1-ports-' + \
port1[1] + '-typ-range/portblk-block1","fromPort":"' + port1[1] + '","toPort":"' + port1[
1] + '","name":"block1",' \
'"status":"created,modified","rn":"portblk-block1"},"children":[]}},' \
'{"infraRsAccBaseGrp":{"attributes":{"tDn":"uni/infra/funcprof/accbundle-' + pc_policy_grp + '","status":"created,modified"},' \
'"children":[]}}]}}]}},{"infraNodeP":{"attributes":{"dn":"uni/infra/nprof-leaf-' + leaf + '_Profile1","name":"leaf-' + leaf + '_Profile1",' \
'"descr":"'+description+'","status":"created,modified"},"children":[{"infraLeafS":' \
'{"attributes":{"dn":"uni/infra/nprof-leaf-' + leaf + '_Profile1/leaves-leaf-' + leaf + '_Profile1_selector_' + leaf + '-typ-range",' \
'"name":"leaf-' + leaf + '_Profile1_selector_' + leaf + '","type":"range","status":"created,modified"},"children":[{"infraNodeBlk":' \
'{"attributes":{"dn":"uni/infra/nprof-leaf-' + leaf + '_Profile1/leaves-leaf-' + leaf + '_Profile1_selector_' + leaf + '-typ-range/nodeblk-single0",' \
'"status":"created,modified","from_":"' + leaf + '","to_":"' + leaf + '","name":"single0","rn":"nodeblk-single0"},"children":[]}}]}},' \
'{"infraRsAccPortP":{"attributes":{"tDn":"uni/infra/accportprof-'+profile_name+'","status":"created,modified"},' \
'"children":[]}}]}}]}}'
token = self.token
cookie = {'APIC-cookie': token}
post_data = requests.post(path, data=data, cookies=cookie, verify=False)
pc_op = post_data.json()
# print pc_op
if len(pc_op['imdata']) == 0: