This repository has been archived by the owner on Nov 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert.py
2489 lines (2232 loc) · 118 KB
/
convert.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
#Created by Felix Sterzelmaier, Concat AG
#2019-11
#tested on Python 3.7.4 and 3.7.5rc1
#run with "run.bat" or "python3 ./convert.py" or "python ./convert.py"
#imports
import xlrd
import os
import sys
from datetime import datetime
from datetime import time
from pytz import timezone
from datetime import timezone, datetime, timedelta
import tzlocal
import string
import re
############################################################################
############ Only Change Variables below this line #########################
############################################################################
filename_prefix = ""
filename_sufix = ".yml"
columnNames = "A" # in exceltabgeneral
config_prefx = ""
config_sufix = "_oneview_config.json"
inputfilename = "wip_checkliste_gesamt.xlsx"
exceltabgeneral = "Synergy-MGMT"
exceltabsubnets = "Synergy-Subnets"
exceltabnets = "Synergy-Networks"
exceltabstorage = "Nimble"
exceltabhypervisor = "Synergy-VMware"
exceltabnimble = "Synergy-Nimble"
outputfolder = "output"
restApiVersion = "1000"
restDomain = "LOCAL"
############################################################################
############## Only change Variables above this line #######################
############################################################################
variablesAll = []
variablesNimbleAll = {}
variablesSynergyNimbleAll = {}
variablesHypervisorAll = {}
variablesClustersAll = []
variableHVCPserverpassword = ""
variableHVCPmgmtNet = ""
#change working directory to script path/xlsx path
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
############################################################################
############## Small helper functions ######################################
############################################################################
def columnCharToInt(c):
c = c.lower()
return string.ascii_lowercase.index(c)
def convertToAnsibleVariableName(n):
n = str(n)
n = n.lower().replace(" ","_").replace("-","_")
n = re.sub(r'\W+', '', n)
return n
############################################################################
############## Parse Excel functions #######################################
############################################################################
def findFrames():
global variablesAll
#open workbook and worksheet
workbook = xlrd.open_workbook(inputfilename)
worksheet = workbook.sheet_by_name(exceltabgeneral)
columnNamesInt = columnCharToInt(columnNames)
for row in range(worksheet.nrows):
name = str(worksheet.cell_value(row,columnNamesInt))
if(name==""):
continue
if(name=="OneView Hostname"):
for col in range(columnCharToInt(columnNames)+1,worksheet.ncols):
data = str(worksheet.cell_value(row,col))
if(data=="" or data=="#TODO" or data=="n/a" or data.startswith("#TODO")):
continue
tmp = {"name":data,"column":col,"letter":data[0]}
variablesAll.append(tmp)
break
#ehemals fillvariables
for frame in variablesAll:
variables = {}
infocount = 0
foundGateway = False
for row in range(worksheet.nrows):
name = str(worksheet.cell_value(row,columnNamesInt))
if(name==""):
continue
if(name=="Infos"):
infocount = infocount + 1
continue
if(infocount!=1):
continue
#found valid line
columnDataInt = frame["column"]
data = str(worksheet.cell_value(row,columnDataInt))
if(data=="" or data=="#TODO" or data=="n/a" or data.startswith("#TODO")):
continue
if(data.find("#TODO") != -1):
pos = data.find("#TODO")
data = data[:pos-1]
name = convertToAnsibleVariableName(name)
if(name=="gateway"):
if(foundGateway):
continue
foundGateway = True
variables[name] = data
frame["variables"] = variables
def findNimbles():
global variablesNimbleAll
#open workbook and worksheet
workbook = xlrd.open_workbook(inputfilename)
worksheet = workbook.sheet_by_name(exceltabstorage)
columnNamesInt = columnCharToInt(columnNames)
for row in range(worksheet.nrows):
name = str(worksheet.cell_value(row,columnNamesInt))
if(name==""):
continue
if(name=="Storage System Name"):
for col in range(columnCharToInt(columnNames)+1,worksheet.ncols):
data = str(worksheet.cell_value(row,col))
if(data=="" or data=="#TODO" or data=="n/a" or data.startswith("#TODO") or str(worksheet.cell_value(row-1,col))=="Bemerkungen"):
continue
tmp = {"name":data,"column":col,"letter":data[0]}
variablesNimbleAll[data[0]] = tmp
break
#ehemals fillvariablesnimble
for l in variablesNimbleAll:
nimble = variablesNimbleAll[l]
variables = {}
start = False
end = False
for row in range(worksheet.nrows):
name = str(worksheet.cell_value(row,columnNamesInt))
if(name==""):
continue
if(name=="Group name"):
start = True
if(not start):
continue
if(end):
continue
if(name=="NTP (time) server IP address"):
end = True
#found valid line
columnDataInt = nimble["column"]
data = str(worksheet.cell_value(row,columnDataInt))
if(data=="" or data=="#TODO" or data=="n/a" or data.startswith("#TODO")):
continue
if(data.find("#TODO") != -1):
pos = data.find("#TODO")
data = data[:pos-1]
name = convertToAnsibleVariableName(name)
variables[name] = data
nimble["variables"] = variables
def findSynergyNimbles():
global variablesSynergyNimbleAll
#open workbook and worksheet
workbook = xlrd.open_workbook(inputfilename)
worksheet = workbook.sheet_by_name(exceltabnimble)
columnNamesInt = columnCharToInt(columnNames)
for row in range(worksheet.nrows):
name = str(worksheet.cell_value(row,columnNamesInt))
if(name==""):
continue
if(name=="Zone"):
for col in range(columnCharToInt(columnNames)+1,worksheet.ncols):
data = str(worksheet.cell_value(row,col))
if(data=="" or data=="#TODO" or data=="n/a" or data.startswith("#TODO") or str(worksheet.cell_value(row-1,col))=="Bemerkungen"):
continue
tmp = {"column":col,"letter":data[0]}
variablesSynergyNimbleAll[data[0]] = tmp
break
#ehemals fillvariablesnimble
for l in variablesSynergyNimbleAll:
nimble = variablesSynergyNimbleAll[l]
variables = {}
start = False
for row in range(worksheet.nrows):
name = str(worksheet.cell_value(row,columnNamesInt))
if(name==""):
continue
if(name=="Storage system type"):
start = True
if(not start):
continue
#found valid line
columnDataInt = nimble["column"]
data = str(worksheet.cell_value(row,columnDataInt))
if(data=="" or data=="#TODO" or data=="n/a" or data.startswith("#TODO")):
continue
if(data.find("#TODO") != -1):
pos = data.find("#TODO")
data = data[:pos-1]
name = convertToAnsibleVariableName(name)
variables[name] = data
nimble["variables"] = variables
def findHypervisor():
global variablesHypervisorAll,variablesClustersAll,variableHVCPserverpassword,variableHVCPmgmtNet
#open workbook and worksheet
workbook = xlrd.open_workbook(inputfilename)
worksheet = workbook.sheet_by_name(exceltabhypervisor)
start = False
end = False
for row in range(worksheet.nrows):
name = str(worksheet.cell_value(row,0))
if(name==""):
continue
if(name=="Type"):
start = True
if(not start):
continue
if(end):
continue
if(name=="High availability"):
end = True
#found valid line
data = worksheet.cell_value(row,1)
if(isinstance(data,float)):
data = str(int(data))
if(data=="" or data=="#TODO" or data=="n/a" or data.startswith("#TODO")):
continue
if(data.find("#TODO") != -1):
pos = data.find("#TODO")
data = data[:pos-1]
name = convertToAnsibleVariableName(name)
variablesHypervisorAll[name] = data
#clusters
start = False
for row in range(worksheet.nrows):
name = str(worksheet.cell_value(row,3))
if(name==""):
continue
if(name=="Cluster"):
start = True
continue
if(not start):
continue
#found valid line
if(not name in variablesClustersAll):
variablesClustersAll.append(name)
#serverpassword
start = False
for row in range(worksheet.nrows):
name = str(worksheet.cell_value(row,5))
if(name==""):
continue
if(name=="serverPassword"):
start = True
continue
if(not start):
continue
variableHVCPserverpassword = name
break
#variableHVCPmgmtNet
start = False
for row in range(worksheet.nrows):
name = str(worksheet.cell_value(row,4))
if(name==""):
continue
if(name=="Management Network"):
start = True
continue
if(not start):
continue
variableHVCPmgmtNet = name
break
############################################################################
############## Write Config and Fileheaders functions ######################
############################################################################
def writeConfigs():
for frame in variablesAll:
configFile = outputfolder+"/"+config_prefx+frame["letter"]+config_sufix
outfile = open(configFile,'w')
outfile.write("{"+"\n")
outfile.write(" \"ip\": \""+frame["variables"]["oneview_hostname"].lower()+"."+frame["variables"]["domain_name"]+"\","+"\n")
outfile.write(" \"credentials\": {"+"\n")
outfile.write(" \"userName\": \"Administrator\","+"\n")
outfile.write(" \"password\": \""+frame["variables"]["administrator_passwort"]+"\""+"\n")
outfile.write(" },"+"\n")
outfile.write(" \"image_streamer_ip\": \"\","+"\n") #todo, bleibt erstmal leer
outfile.write(' "api_version": "'+restApiVersion+'"\n')
outfile.write("}"+"\n")
outfile.close()
def writeFileheader(outfile,configFileName):
filename = os.path.basename(outfile.name)
print("now: "+filename)
outfile.write("###\n")
outfile.write("# created by python script convert.py\n")
outfile.write("# Felix Sterzelmaier, Concat AG\n")
outfile.write("# Created: "+datetime.now(tzlocal.get_localzone()).strftime("%Y-%m-%d %H:%M:%S %Z(%z)")+"\n")
outfile.write("# Dependencies: pip install --upgrade pip\n")
outfile.write("# Dependencies: pip install pyvmomi\n")
outfile.write("# Run with: ansible-playbook -c local -i localhost, "+filename+"\n")
outfile.write("# Run on: 10.10.5.239/olant-ansible as user olant in path /home/olant/synergy-ansible/feste-script/output\n")
outfile.write("# Before reading this playbook please read the README.txt and the sourcecode of convert.py first!\n")
outfile.write("###\n")
outfile.write("---\n")
outfile.write("- hosts: localhost\n")
outfile.write(" vars:\n")
outfile.write(' config: "{{ playbook_dir }}/'+configFileName+'"\n')
outfile.write(" tasks:\n")
outfile.write("\n")
def writeFilepartRESTAPILogin(outfile,host,username,password):
outfile.write(' - name: Login to API and retrieve AUTH-Token\n')
outfile.write(' uri:\n')
outfile.write(' validate_certs: yes\n')
outfile.write(' headers:\n')
outfile.write(' X-Api-Version: "'+restApiVersion+'"\n')
outfile.write(' Content-Type: application/json\n')
outfile.write(' url: https://'+host+'/rest/login-sessions\n')
outfile.write(' method: POST\n')
outfile.write(' body_format: json\n')
outfile.write(' body:\n')
outfile.write(' authLoginDomain: "'+restDomain+'"\n')
outfile.write(' password: "'+password+'"\n')
outfile.write(' userName: "'+username+'"\n')
outfile.write(' loginMsgAck: "true"\n')
outfile.write(' register: var_this\n')
outfile.write('\n')
outfile.write(' - set_fact: var_token=\'{{ var_this["json"]["sessionID"] }}\'\n')
outfile.write('\n')
############################################################################
############## Create Playbooks functions ##################################
############################################################################
#01
def writeTimelocale(nr,name):
for frame in variablesAll:
filePath = outputfolder+"/"+filename_prefix+frame["letter"]+"_"+nr+"_"+name+filename_sufix
outfile = open(filePath,'w')
writeFileheader(outfile,config_prefx+frame["letter"]+config_sufix)
outfile.write(" - name: Configure time locale in en_US.UTF-8\n")
outfile.write(" oneview_appliance_time_and_locale_configuration:\n")
outfile.write(" config: \"{{ config }}\"\n")
outfile.write(" state: present\n")
outfile.write(" data:\n")
outfile.write(" locale: en_US.UTF-8\n")
outfile.write(" timezone: UTC\n")
outfile.write(" ntpServers:\n")
outfile.write(" - "+frame["variables"]["gateway"]+"\n")
outfile.write(" delegate_to: localhost\n")
outfile.write("\n")
outfile.close()
#02
def writeAddresspoolsubnet(nr,filenamepart):
for frame in variablesAll:
filePath = outputfolder+"/"+filename_prefix+frame["letter"]+"_"+nr+"_"+filenamepart+filename_sufix
outfile = open(filePath,'w')
writeFileheader(outfile,config_prefx+frame["letter"]+config_sufix)
outfile.close()
#open workbook and worksheet
workbook = xlrd.open_workbook(inputfilename)
worksheet = workbook.sheet_by_name(exceltabsubnets)
variablesHead = []
for col in range(worksheet.ncols):
name = convertToAnsibleVariableName(worksheet.cell_value(0,col))
variablesHead.append(name)
for row in range(1,worksheet.nrows):
variablesOneSubnet = {}
for col in range(worksheet.ncols):
val = str(worksheet.cell_value(row,col))
if(val=="#TODO" or val=="n/a" or val.startswith("#TODO")):
val = ""
if(val.find("#TODO") != -1):
pos = val.find("#TODO")
val = val[:pos-1]
if(val!=""):
variablesOneSubnet[variablesHead[col]] = val
writeAddresspoolsubnetOne(nr,filenamepart,variablesOneSubnet)
#02 helper
def writeAddresspoolsubnetOne(nr,filenamepart,variablesOneSubnet):
if(not "zone" in variablesOneSubnet):
print("variablesOneSubnet missing zone!")
return
if(not "name" in variablesOneSubnet):
print("variablesOneSubnet missing name!")
return
if(not "type" in variablesOneSubnet):
print("variablesOneSubnet missing typ!")
return
for frame in variablesAll:
filePath = outputfolder+"/"+filename_prefix+frame["letter"]+"_"+nr+"_"+filenamepart+filename_sufix
outfile = open(filePath,'a')
if(variablesOneSubnet["zone"].find(frame["letter"]) != -1):
if(variablesOneSubnet["type"]=="Subnet"):
if(not "subnetid" in variablesOneSubnet):
print("variablesOneSubnet missing subnetid!")
return
if(not "subnetmask" in variablesOneSubnet):
print("variablesOneSubnet missing subnetmask!")
return
outfile.write(" - name: Create subnet "+variablesOneSubnet["subnetid"]+"\n")
outfile.write(" oneview_id_pools_ipv4_subnet:\n")
outfile.write(" config: \"{{ config }}\"\n")
outfile.write(" state: present\n")
outfile.write(" data:\n")
outfile.write(" name: "+variablesOneSubnet["subnetid"]+"_Subnet\n")
outfile.write(" type: Subnet\n")
outfile.write(" networkId: "+variablesOneSubnet["subnetid"]+"\n")
outfile.write(" subnetmask: "+variablesOneSubnet["subnetmask"]+"\n")
if("gateway" in variablesOneSubnet):
outfile.write(" gateway: "+variablesOneSubnet["gateway"]+"\n")
if("domain" in variablesOneSubnet):
outfile.write(" domain: "+variablesOneSubnet["domain"]+"\n")
if("dnsserver1" in variablesOneSubnet):
outfile.write(" dnsServers:\n")
outfile.write(" - "+variablesOneSubnet["dnsserver1"]+"\n")
if("dnsserver2" in variablesOneSubnet):
outfile.write(" - "+variablesOneSubnet["dnsserver2"]+"\n")
if("dnsserver3" in variablesOneSubnet):
outfile.write(" - "+variablesOneSubnet["dnsserver3"]+"\n")
outfile.write(" delegate_to: localhost\n")
outfile.write("\n")
if(variablesOneSubnet["type"]=="Range"):
if(not "rangestart" in variablesOneSubnet):
print("variablesOneSubnet "+variablesOneSubnet["name"]+" missing rangestart!")
return
if(not "rangeend" in variablesOneSubnet):
print("variablesOneSubnet "+variablesOneSubnet["name"]+" missing rangeend!")
return
outfile.write(" - set_fact: subnet_uri=\"{{ id_pools_ipv4_subnet[\"uri\"] }}\" \n")
outfile.write(" - name: Create IPV4 range "+variablesOneSubnet["name"]+"\n")
outfile.write(" oneview_id_pools_ipv4_range:\n")
outfile.write(" config: \"{{ config }}\"\n")
outfile.write(" state: present\n")
outfile.write(" data:\n")
outfile.write(" name: "+variablesOneSubnet["name"]+"\n")
outfile.write(" subnetUri: \"{{ subnet_uri }}\" \n")
outfile.write(" type: Range\n")
outfile.write(" rangeCategory: Custom\n")
outfile.write(" startAddress: "+variablesOneSubnet["rangestart"]+"\n")
outfile.write(" endAddress: "+variablesOneSubnet["rangeend"]+"\n")
outfile.write(" delegate_to: localhost\n")
outfile.write("\n")
outfile.close()
#03
def writeAddHypervisorManager(nr,filenamepart):
for frame in variablesAll:
filePath = outputfolder+"/"+filename_prefix+frame["letter"]+"_"+nr+"_"+filenamepart+filename_sufix
outfile = open(filePath,'w')
writeFileheader(outfile,config_prefx+frame["letter"]+config_sufix)
writeFilepartRESTAPILogin(outfile,frame["variables"]["oneview_hostname"].lower()+'.'+frame["variables"]["domain_name"],"Administrator",frame["variables"]["administrator_passwort"])
#BEGIN
outfile.write(' - name: Initiate asynchronous registration of an external hypervisor manager with the appliance. (Using AUTH-Token) (Statuscode should be 202)\n')
outfile.write(' uri:\n')
outfile.write(' validate_certs: yes\n')
outfile.write(' headers:\n')
outfile.write(' Auth: "{{ var_token }}"\n')
outfile.write(' X-Api-Version: "'+restApiVersion+'"\n')
outfile.write(' Content-Type: application/json\n')
outfile.write(' url: https://'+frame["variables"]["oneview_hostname"].lower()+'.'+frame["variables"]["domain_name"]+'/rest/hypervisor-managers\n')
outfile.write(' method: POST\n')
outfile.write(' body_format: json\n')
outfile.write(' body:\n')
outfile.write(' type: "HypervisorManagerV2"\n')
outfile.write(' name: "'+variablesHypervisorAll["hostname"]+'"\n')
outfile.write(' username: "'+variablesHypervisorAll["username"]+'"\n')
outfile.write(' password: "'+variablesHypervisorAll["password"]+'"\n')
outfile.write(' hypervisorType: "Vmware"\n')
outfile.write(' preferences:\n')
outfile.write(' type: "Vmware"\n')
outfile.write(' drsEnabled: '+("true" if (variablesHypervisorAll["distributed_resource_scheduler"]=="Enabled") else "false")+'\n')
outfile.write(' haEnabled: '+("true" if (variablesHypervisorAll["high_availability"]=="Enabled") else "false")+'\n')
outfile.write(' distributedSwitchVersion: "'+variablesHypervisorAll["distributed_vswitch_version"]+'"\n')
outfile.write(' distributedSwitchUsage: "'+variablesHypervisorAll["use_distributed_vswitch_for"]+'"\n')
outfile.write(' multiNicVMotion: '+("true" if (variablesHypervisorAll["multi_nic_vmotion"]=="Enabled") else "false")+'\n')
outfile.write(' virtualSwitchType: "'+variablesHypervisorAll["vswitch_type"]+'"\n')
outfile.write(' status_code: 202\n')
outfile.write(' register: var_return\n')
outfile.write('\n')
outfile.write(' - debug:\n')
outfile.write(' var: var_return\n')
outfile.write('\n')
outfile.write(' - name: Taskinfo\n')
outfile.write(' uri:\n')
outfile.write(' validate_certs: yes\n')
outfile.write(' headers:\n')
outfile.write(' Auth: "{{ var_token }}"\n')
outfile.write(' X-Api-Version: "'+restApiVersion+'"\n')
outfile.write(' Content-Type: application/json\n')
outfile.write(' url: \'{{ var_return["location"] }}\'\n')
outfile.write(' method: GET\n')
outfile.write(' status_code: 200\n')
outfile.write(' register: var_taskinfo\n')
outfile.write('\n')
outfile.write(' - debug:\n')
outfile.write(' var: var_taskinfo\n')
outfile.write('\n')
#END
outfile.close()
#04
def writeCreatenetwork(nr,filenamepart):
for frame in variablesAll:
filePath = outputfolder+"/"+filename_prefix+frame["letter"]+"_"+nr+"_"+filenamepart+filename_sufix
outfile = open(filePath,'w')
writeFileheader(outfile,config_prefx+frame["letter"]+config_sufix)
outfile.close()
#open workbook and worksheet
workbook = xlrd.open_workbook(inputfilename)
worksheet = workbook.sheet_by_name(exceltabnets)
variablesHead = []
for col in range(worksheet.ncols):
name = convertToAnsibleVariableName(worksheet.cell_value(0,col))
variablesHead.append(name)
for row in range(1,worksheet.nrows):
variablesOneNet = {}
for col in range(worksheet.ncols):
val = worksheet.cell_value(row,col)
if(isinstance(val,float)):
val = str(int(val))
if(val=="#TODO" or val=="n/a" or val.startswith("#TODO")):
val = ""
if(val.find("#TODO") != -1):
pos = val.find("#TODO")
val = val[:pos-1]
if(val!=""):
variablesOneNet[variablesHead[col]] = val
writeCreatenetworkOne(nr,filenamepart,variablesOneNet)
#04 helper
def writeCreatenetworkOne(nr,filenamepart,variablesOneNet):
if(not "zone" in variablesOneNet):
print("variablesOneNet missing zone!")
return
if(not "ipv4subnet" in variablesOneNet):
print("variablesOneNet missing ipv4subnet!")
return
if(not "name" in variablesOneNet):
print("variablesOneNet missing name!")
return
if(not "vlanid" in variablesOneNet):
print("variablesOneNet missing vlanid!")
return
for frame in variablesAll:
filePath = outputfolder+"/"+filename_prefix+frame["letter"]+"_"+nr+"_"+filenamepart+filename_sufix
outfile = open(filePath,'a')
if(variablesOneNet["zone"].find(frame["letter"]) != -1):
if(variablesOneNet["ipv4subnet"]!="None"):
outfile.write(" - name: Gather facts about ID Pools IPV4 Subnets by name\n")
outfile.write(" oneview_id_pools_ipv4_subnet_facts:\n")
outfile.write(" config: \"{{ config }}\"\n")
outfile.write(" name: '"+variablesOneNet["ipv4subnet"]+"_Subnet'\n")
outfile.write(" delegate_to: localhost\n")
outfile.write("\n")
outfile.write(" - set_fact: subnet_uri=\"{{ id_pools_ipv4_subnets[0].uri }}\"\n")
outfile.write(" - debug: var=subnet_uri\n")
outfile.write("\n")
outfile.write(" - name: Create an Ethernet Network\n")
outfile.write(" oneview_ethernet_network:\n")
outfile.write(" config: \"{{ config }}\"\n")
outfile.write(" state: present\n")
outfile.write(" data:\n")
outfile.write(" name: \""+variablesOneNet["name"]+"\"\n")
outfile.write(" ethernetNetworkType: "+variablesOneNet["type"]+"\n")
outfile.write(" type: ethernet-networkV4\n")
outfile.write(" purpose: \""+variablesOneNet["purpose"]+"\"\n")
outfile.write(" smartLink: "+variablesOneNet["smartlink"].lower()+"\n")
outfile.write(" privateNetwork: "+variablesOneNet["privatenetwork"].lower()+"\n")
outfile.write(" vlanId: "+variablesOneNet["vlanid"]+"\n")
if(variablesOneNet["ipv4subnet"]!="None"):
outfile.write(" subnetUri: \"{{ subnet_uri }}\"\n")
outfile.write(" bandwidth:\n")
outfile.write(" typicalBandwidth: "+variablesOneNet["preferredbandwidth"]+"\n")
outfile.write(" maximumBandwidth: "+variablesOneNet["maxbandwidth"]+"\n")
outfile.write(" delegate_to: localhost\n")
outfile.write("\n")
outfile.close()
#05
def writeOSdeploymentServer(nr,filenamepart):
for frame in variablesAll:
filePath = outputfolder+"/"+filename_prefix+frame["letter"]+"_"+nr+"_"+filenamepart+filename_sufix
outfile = open(filePath,'w')
writeFileheader(outfile,config_prefx+frame["letter"]+config_sufix)
#BEGIN
outfile.write(' - name: Ensure that the Deployment Server is present'+"\n")
outfile.write(' oneview_os_deployment_server:'+"\n")
outfile.write(' config: "{{ config }}"'+"\n")
outfile.write(' state: present'+"\n")
outfile.write(' data:'+"\n")
outfile.write(' name: "'+frame["variables"]["oneview_hostname"]+'_OSDS"'+"\n")
outfile.write(' mgmtNetworkName: "oob-mgmt"'+"\n")
outfile.write(' applianceName: "'+frame["letter"]+'-Master2, appliance 2"'+"\n")
outfile.write(' deplManagersType: "Image Streamer"'+"\n")
outfile.write(''+"\n")
outfile.write(' - debug: var=os_deployment_server'+"\n")
outfile.write("\n")
#END
outfile.close()
#06
def writeNetworkset(nr,filenamepart):
#open workbook and worksheet
workbook = xlrd.open_workbook(inputfilename)
worksheet = workbook.sheet_by_name(exceltabnets)
variablesHead = []
variables = []
networksets = []
for col in range(worksheet.ncols):
name = convertToAnsibleVariableName(worksheet.cell_value(0,col))
variablesHead.append(name)
for row in range(1,worksheet.nrows):
variablesOneNet = {}
for col in range(worksheet.ncols):
val = worksheet.cell_value(row,col)
if(isinstance(val,float)):
val = str(int(val))
if(val=="#TODO" or val=="n/a" or val.startswith("#TODO")):
val = ""
if(val.find("#TODO") != -1):
pos = val.find("#TODO")
val = val[:pos-1]
variablesOneNet[variablesHead[col]] = val
if(variablesHead[col]=="networkset"):
if(val!=""):
if(not val in networksets):
networksets.append(val)
variables.append(variablesOneNet)
for frame in variablesAll:
filePath = outputfolder+"/"+filename_prefix+frame["letter"]+"_"+nr+"_"+filenamepart+filename_sufix
outfile = open(filePath,'w')
writeFileheader(outfile,config_prefx+frame["letter"]+config_sufix)
#BEGIN
for networkset in networksets:
outfile.write(' - name: Create Network Set '+networkset+"\n")
outfile.write(' oneview_network_set:'+"\n")
outfile.write(' config: "{{ config }}"'+"\n")
outfile.write(' state: present'+"\n")
outfile.write(' data:'+"\n")
outfile.write(' type: "network-setV4"'+"\n")
outfile.write(' name: "'+networkset+'"'+"\n")
outfile.write(' networkUris:'+"\n") # it is possible to pass names instead of URIs
for v in variables:
if(v["networkset"] == networkset):
if(frame["letter"] in v["zone"]):
outfile.write(' - '+v["name"]+"\n")
outfile.write(' delegate_to: localhost'+"\n")
outfile.write("\n")
#END
outfile.close()
#07
def writeLogicalInterconnectGroup(nr,filenamepart):
#open workbook and worksheet
workbook = xlrd.open_workbook(inputfilename)
worksheet = workbook.sheet_by_name(exceltabnets)
variablesHead = []
variables = []
for col in range(worksheet.ncols):
name = convertToAnsibleVariableName(worksheet.cell_value(0,col))
variablesHead.append(name)
for row in range(1,worksheet.nrows):
variablesOneNet = {}
for col in range(worksheet.ncols):
val = worksheet.cell_value(row,col)
if(isinstance(val,float)):
val = str(int(val))
if(val=="#TODO" or val=="n/a" or val.startswith("#TODO")):
val = ""
if(val.find("#TODO") != -1):
pos = val.find("#TODO")
val = val[:pos-1]
variablesOneNet[variablesHead[col]] = val
variables.append(variablesOneNet)
for frame in variablesAll:
filePath = outputfolder+"/"+filename_prefix+frame["letter"]+"_"+nr+"_"+filenamepart+filename_sufix
outfile = open(filePath,'w')
writeFileheader(outfile,config_prefx+frame["letter"]+config_sufix)
#BEGIN
outfile.write('#---------------------------- Logical Interconnect Group lig_sas'+"\n")
outfile.write(' - name: Create logical Interconnect Group lig_sas'+"\n")
outfile.write(' oneview_sas_logical_interconnect_group:'+"\n")
outfile.write(' config: "{{ config }}"'+"\n")
outfile.write(' state: present'+"\n")
outfile.write(' data:'+"\n")
outfile.write(' name: "lig_sas"'+"\n")
outfile.write(' enclosureType: "SY12000"'+"\n")
outfile.write(' redundancyType: ""'+"\n")
outfile.write(' type: "sas-logical-interconnect-groupV2"'+"\n")
outfile.write(' interconnectBaySet: 1'+"\n")
outfile.write(' enclosureIndexes:'+"\n")
outfile.write(' - 1'+"\n")
outfile.write(' interconnectMapTemplate:'+"\n")
outfile.write(' interconnectMapEntryTemplates:'+"\n")
outfile.write(' - permittedInterconnectTypeUri: "/rest/sas-interconnect-types/Synergy12GbSASConnectionModule"'+"\n")
outfile.write(' enclosureIndex: "1"'+"\n")
outfile.write(' logicalLocation: '+"\n")
outfile.write(' locationEntries: '+"\n")
outfile.write(' - relativeValue: 4'+"\n")
outfile.write(' type: "Bay" '+"\n")
outfile.write(' - relativeValue: 1'+"\n")
outfile.write(' type: "Enclosure" '+"\n")
outfile.write(' - permittedInterconnectTypeUri: "/rest/sas-interconnect-types/Synergy12GbSASConnectionModule"'+"\n")
outfile.write(' enclosureIndex: "1"'+"\n")
outfile.write(' logicalLocation: '+"\n")
outfile.write(' locationEntries: '+"\n")
outfile.write(' - relativeValue: 1'+"\n")
outfile.write(' type: "Bay" '+"\n")
outfile.write(' - relativeValue: 1'+"\n")
outfile.write(' type: "Enclosure" '+"\n")
outfile.write(' delegate_to: localhost'+"\n")
outfile.write(' '+"\n")
outfile.write('#---------------------------- Logical Interconnect Group lig_vc'+"\n")
for v in variables:
if(frame["letter"] in v["zone"]):
outfile.write(' - name: Get uri for network '+v["name"]+"\n")
outfile.write(' oneview_ethernet_network_facts:'+"\n")
outfile.write(' config: "{{ config }}"'+"\n")
outfile.write(' name: "'+v["name"]+'"'+"\n")
outfile.write(' - set_fact: var_'+convertToAnsibleVariableName(v["name"])+'="{{ethernet_networks.uri}}"'+"\n")
outfile.write("\n")
outfile.write(' - name: Create logical Interconnect Group lig_vc'+"\n")
outfile.write(' oneview_logical_interconnect_group:'+"\n")
outfile.write(' config: "{{ config }}"'+"\n")
outfile.write(' state: present'+"\n")
outfile.write(' data:'+"\n")
outfile.write(' name: "lig_vc"'+"\n")
outfile.write(' enclosureType: "SY12000"'+"\n")
outfile.write(' type: "logical-interconnect-groupV6"'+"\n")
outfile.write(' redundancyType: "HighlyAvailable"'+"\n")
outfile.write(' interconnectBaySet: 3'+"\n")
outfile.write(' ethernetSettings: '+"\n")
outfile.write(' type: "EthernetInterconnectSettingsV5"'+"\n")
outfile.write(' enableIgmpSnooping: false'+"\n")
outfile.write(' igmpIdleTimeoutInterval: 260'+"\n")
outfile.write(' enableNetworkLoopProtection: true'+"\n")
outfile.write(' enablePauseFloodProtection: true'+"\n")
outfile.write(' enableRichTLV: false'+"\n")
outfile.write(' enableTaggedLldp: true'+"\n")
outfile.write(' enableStormControl: false'+"\n")
outfile.write(' stormControlThreshold: 0'+"\n")
outfile.write(' enableFastMacCacheFailover: true'+"\n")
outfile.write(' macRefreshInterval: 5'+"\n")
outfile.write(' enclosureIndexes:'+"\n")
outfile.write(' - 1'+"\n")
outfile.write(' - 2'+"\n")
outfile.write(' - 3'+"\n")
outfile.write(' interconnectMapTemplate:'+"\n")
outfile.write(' interconnectMapEntryTemplates:'+"\n")
outfile.write(' - permittedInterconnectTypeName: "Synergy 20Gb Interconnect Link Module"'+"\n")
outfile.write(' enclosureIndex: "2"'+"\n")
outfile.write(' logicalLocation: '+"\n")
outfile.write(' locationEntries: '+"\n")
outfile.write(' - relativeValue: 3'+"\n")
outfile.write(' type: "Bay" '+"\n")
outfile.write(' - relativeValue: 2'+"\n")
outfile.write(' type: "Enclosure" '+"\n")
outfile.write(' - permittedInterconnectTypeName: "Synergy 20Gb Interconnect Link Module"'+"\n")
outfile.write(' enclosureIndex: "3"'+"\n")
outfile.write(' logicalLocation: '+"\n")
outfile.write(' locationEntries: '+"\n")
outfile.write(' - relativeValue: 6'+"\n")
outfile.write(' type: "Bay" '+"\n")
outfile.write(' - relativeValue: 3'+"\n")
outfile.write(' type: "Enclosure" '+"\n")
outfile.write(' - permittedInterconnectTypeName: "Synergy 20Gb Interconnect Link Module"'+"\n")
outfile.write(' enclosureIndex: "3"'+"\n")
outfile.write(' logicalLocation: '+"\n")
outfile.write(' locationEntries: '+"\n")
outfile.write(' - relativeValue: 3'+"\n")
outfile.write(' type: "Bay" '+"\n")
outfile.write(' - relativeValue: 3'+"\n")
outfile.write(' type: "Enclosure" '+"\n")
outfile.write(' - permittedInterconnectTypeName: "Synergy 20Gb Interconnect Link Module"'+"\n")
outfile.write(' enclosureIndex: "1"'+"\n")
outfile.write(' logicalLocation: '+"\n")
outfile.write(' locationEntries: '+"\n")
outfile.write(' - relativeValue: 1'+"\n")
outfile.write(' type: "Enclosure" '+"\n")
outfile.write(' - relativeValue: 6'+"\n")
outfile.write(' type: "Bay" '+"\n")
outfile.write(' - permittedInterconnectTypeName: "Virtual Connect SE 40Gb F8 Module for Synergy"'+"\n")
outfile.write(' enclosureIndex: "2"'+"\n")
outfile.write(' logicalLocation: '+"\n")
outfile.write(' locationEntries: '+"\n")
outfile.write(' - relativeValue: 6'+"\n")
outfile.write(' type: "Bay" '+"\n")
outfile.write(' - relativeValue: 2'+"\n")
outfile.write(' type: "Enclosure" '+"\n")
outfile.write(' - permittedInterconnectTypeName: "Virtual Connect SE 40Gb F8 Module for Synergy"'+"\n")
outfile.write(' enclosureIndex: "1"'+"\n")
outfile.write(' logicalLocation: '+"\n")
outfile.write(' locationEntries: '+"\n")
outfile.write(' - relativeValue: 1'+"\n")
outfile.write(' type: "Enclosure" '+"\n")
outfile.write(' - relativeValue: 3'+"\n")
outfile.write(' type: "Bay" '+"\n")
outfile.write(' internalNetworkUris:'+"\n")
for v in variables:
if(frame["letter"] in v["zone"] and v["uplinkset"]=="Internal"):
outfile.write(' - "{{var_'+convertToAnsibleVariableName(v["name"])+'}}" # networkName: '+v["name"]+' '+"\n")
outfile.write(' uplinkSets:'+"\n")
outfile.write(' - name: "iSCSI-Deployment"'+"\n")
outfile.write(' networkType: "Ethernet"'+"\n")
outfile.write(' ethernetNetworkType: "ImageStreamer"'+"\n")
outfile.write(' mode: "Auto"'+"\n")
outfile.write(' networkUris:'+"\n")
for v in variables:
if(frame["letter"] in v["zone"] and v["uplinkset"]=="iSCSI-Deployment"):
outfile.write(' - "{{var_'+convertToAnsibleVariableName(v["name"])+'}}" # networkName: '+v["name"]+' '+"\n")
outfile.write(' logicalPortConfigInfos:'+"\n")
outfile.write(' - desiredSpeed: "Auto"'+"\n")
outfile.write(' logicalLocation:'+"\n")
outfile.write(' locationEntries:'+"\n")
outfile.write(' - relativeValue: 63'+"\n")
outfile.write(' type: "Port" '+"\n")
outfile.write(' - relativeValue: 6'+"\n")
outfile.write(' type: "Bay" '+"\n")
outfile.write(' - relativeValue: 2'+"\n")
outfile.write(' type: "Enclosure" '+"\n")
outfile.write(' - desiredSpeed: "Auto"'+"\n")
outfile.write(' logicalLocation:'+"\n")
outfile.write(' locationEntries:'+"\n")
outfile.write(' - relativeValue: 1'+"\n")
outfile.write(' type: "Enclosure" '+"\n")
outfile.write(' - relativeValue: 62'+"\n")
outfile.write(' type: "Port" '+"\n")
outfile.write(' - relativeValue: 3'+"\n")
outfile.write(' type: "Bay" '+"\n")
outfile.write(' - desiredSpeed: "Auto"'+"\n")