-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEnabledLinksFromPhEDExDataSrv.py
executable file
·813 lines (677 loc) · 26.8 KB
/
EnabledLinksFromPhEDExDataSrv.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
#!/usr/bin/env python
""" @author: Josep Flix / John Artieda """
import xml.dom.minidom, os, time
from xml import xpath
import re, datetime, string, sys, pprint
from optparse import OptionParser
usage = "usage: (example) %prog -p ~/www/SR2 -u http://cms-site-readiness.web.cern.ch/cms-site-readiness"
parser = OptionParser(usage=usage, version="%prog 1.0")
parser.add_option("-p", "--path_out", dest="path_out", help="Sets the PATH to store the produced data", metavar="PATH")
parser.add_option("-u", "--url", dest="url", help="Sets the base URL where produced data is accessible", metavar="URL")
parser.add_option("-c", "--css", metavar="PATH", default=".", help="css file path")
(options, args) = parser.parse_args()
if len(sys.argv) != 5:
parser.error("incorrect number of arguments. Check needed arguments with --help")
def getTierNumber(name):
l=re.match("^T(\d+)",name);
if not l:
print "Error getting the Tier number from %s" % name
return
if name=="T0_CH_CERN": return 0
else: return l.group(1)
def Buff2CMS(unicode_buffer):
buffer=str(unicode_buffer)
name=buffer
i=string.find(buffer,"_MSS")
if i>0:
name=buffer[0:i]
i=string.find(buffer,"_Export")
if i>0:
name=buffer[0:i]
return name
def Buff2CMS2(unicode_buffer):
buffer=str(unicode_buffer)
name=buffer
i=string.find(buffer,"_Buffer")
if i>0:
name=buffer[0:i]
i=string.find(buffer,"_Disk")
if i>0:
name=buffer[0:i]
i=string.find(buffer,"_MSS")
if i>0:
name=buffer[0:i]
i=string.find(buffer,"_ECHO")
if i>0:
name=buffer[0:i]
i=string.find(buffer,"_Export")
if i>0:
name=buffer[0:i]
return name
def TierExceptions(name):
i=0
if name=="": i=1
if name=="T1_CH_CERN": i=1
if name=="T1_CH_CERN_Buffer": i=1
if name=="T2_CH_CAF": i=1
if name=="T1_RAL_Stage": i=1
if name=="T1_DE_FZK": i=1
if name=="T2_RU_IHEP_Disk": i=1
if name=="T2_KIPT": i=1
if name=="T2_CUKUROVA": i=1
if name[0:2]=="XT": i=1
return i
today=datetime.datetime.utcnow()
timestamp=today.strftime("%Y-%m-%d %H:%M:%S")
todaystampfileSSB=today.strftime("%Y-%m-%d 00:00:01")
timestamphtml=today.strftime("%Y%m%d")
pathN=options.path_out + "/INPUTxmls"
fileN=pathN + "/enabledlinks.xml"
pathout= options.path_out + "/toSSB"
pathoutHTML= options.path_out + "/HTML"
pathoutPLOTS= options.path_out + "/PLOTS"
pathoutASCII= options.path_out + "/ASCii"
filehtml= pathoutHTML + '/CommissionedLinks_Sites_' + timestamphtml +'.html'
slinkhtml= './CommissionedLinks_Sites.html'
if options.url.find("pic.es") > 0:
linkmetrics = options.url + "/CommLinksReports/CommissionedLinks_Sites_" + timestamphtml +'.html'
elif options.url.find("cern.ch") > 0:
linkmetrics = options.url + "/CommLinksReports/HTML/CommissionedLinks_Sites_" + timestamphtml +'.html'
if not os.path.exists(options.path_out):
os.makedirs(options.path_out)
if not os.path.exists(pathout):
os.makedirs(pathout)
if not os.path.exists(pathoutHTML):
os.makedirs(pathoutHTML)
if not os.path.exists(pathoutPLOTS):
os.makedirs(pathoutPLOTS)
if not os.path.exists(pathN):
os.makedirs(pathN)
if not os.path.exists(pathoutASCII):
os.makedirs(pathoutASCII)
# Metric Thresholds
T1downlinkT0=1
T1uplinksT2s=20
T1downlinksuplinksT1s=4
T2uplinkT1s=2
T2downlinkT1s=4
# Output files :: feeds to SSB
# T1 :: commissioned downlink with the Tier-0 (T1downlinkT0)
metricPage1="%s/CommissionedLinks_SSBfeed_Tier1_1.txt" % pathout
# T1 :: >= (T1uplinksT2s) commissioned uplinks to Tier-2 sites
metricPage2="%s/CommissionedLinks_SSBfeed_Tier1_2.txt" % pathout
# T1 :: >= (T1downlinksuplinksT1s) downlinks/uplinks to other Tier-1 sites
metricPage3="%s/CommissionedLinks_SSBfeed_Tier1_3.txt" % pathout
# T2 :: >= (T2uplinkT1s) uplinks to Tier-1 sites
metricPage4="%s/CommissionedLinks_SSBfeed_Tier2_1.txt" % pathout
# T2 :: >= (T2downlinkT1s) downlinks from Tier-1 sites
metricPage5="%s/CommissionedLinks_SSBfeed_Tier2_2.txt" % pathout
url='https://cmsweb.cern.ch/phedex/datasvc/xml/prod/Links'
os.system("curl -ks -H 'Accept: text/xml' '%s' > %s" % (url,fileN))
f=file(fileN,'r')
t= xml.dom.minidom.parse(f)
f.close()
sites={}
siteStatus1={}; siteStatus2={}; siteStatus3={}; siteStatus4={}; siteStatus5={}
siteColor1={}; siteColor2={}; siteColor3={}; siteColor4={}; siteColor5={}
for url in xpath.Evaluate('/phedex/link', t):
source=url.getAttribute("from")
if source.find("MSS")>0 : continue
sourceName=Buff2CMS(source)
sourceTier=getTierNumber(sourceName)
target=url.getAttribute("to")
if target.find("MSS")>0: continue
targetName=Buff2CMS(target)
targetTier=getTierNumber(targetName)
# exceptions
if TierExceptions(sourceName) or TierExceptions(targetName): continue
if targetTier=="3" or sourceTier=="3" : continue
if not sites.has_key(sourceName):
sites[sourceName]={'upT0':[], 'downT0':[],'upT1':[], 'downT1':[], 'upT2':[], 'downT2':[]}
value=url.getAttribute("status")
if (value != "deactivated" ):
if not sites.has_key(targetName):
sites[targetName]={'upT0':[], 'downT0':[],'upT1':[], 'downT1':[], 'upT2':[], 'downT2':[]}
uplink='upT%s' % targetTier
downlink='downT%s' % sourceTier
sites[sourceName][uplink].append(targetName)
sites[targetName][downlink].append(sourceName)
if sourceTier=="1" :
sourceName2=Buff2CMS2(source) # if site has _Buffer or _Disk also creates site name T1_XX_YYY
if not sites.has_key(sourceName2):
sites[sourceName2]={'upT0':[], 'downT0':[],'upT1':[], 'downT1':[], 'upT2':[], 'downT2':[]}
if (value != "deactivated" ):
sites[sourceName2][uplink].append(targetName) # T1_XX_YYY adds _Buffer and _Disk links
if targetTier=="1" :
targetName2=Buff2CMS2(target) # if site has _Buffer or _Disk also creates site name T1_XX_YYY
if (value != "deactivated" ):
if not sites.has_key(targetName2):
sites[targetName2]={'upT0':[], 'downT0':[],'upT1':[], 'downT1':[], 'upT2':[], 'downT2':[]}
sites[targetName2][downlink].append(sourceName) # T1_XX_YYY adds _Buffer or _Disk links
# Build txt feed to SSB
keys=sites.keys()
keys.sort()
for i in range(0,len(keys)):
site=keys[i]
isT1=0
isT2=0
if site[1]=="1": isT1=1
if site[1]=="2": isT2=1
toT0=len(sites[site]["upT0"])
fromT0=len(sites[site]["downT0"])
toT1=len(sites[site]["upT1"])
fromT1=len(sites[site]["downT1"])
toT2=len(sites[site]["upT2"])
fromT2=len(sites[site]["downT2"])
if isT1:
siteStatus1[site]=fromT0
siteStatus2[site]=toT2
ss3="%i(d)-%i(u)" % (fromT1,toT1)
siteStatus3[site]=ss3
siteStatus4[site]="n/a"
siteStatus5[site]="n/a"
site2=Buff2CMS2(site) # if name has _Buffer or _Disk --> create site name T1_XX_YYY
siteColor1[site]="green"
siteColor2[site]="green"
siteColor3[site]="green"
siteColor1[site2]="green"
siteColor2[site2]="green"
siteColor3[site2]="green"
if fromT0<T1downlinkT0:
siteColor1[site]="red"
siteColor1[site2]="red" # if either Buffer or Disk are red, site should be red
if toT2<T1uplinksT2s:
siteColor2[site]="red"
siteColor2[site2]="red" # if either Buffer or Disk are red, site should be red
if toT1<T1downlinksuplinksT1s or fromT1<T1downlinksuplinksT1s:
siteColor3[site]="red"
siteColor3[site2]="red" # if either Buffer or Disk are red, site should be red
if isT2:
siteStatus1[site]="n/a"
siteStatus2[site]="n/a"
siteStatus3[site]="n/a"
siteStatus4[site]=toT1
siteStatus5[site]=fromT1
if toT1<T2uplinkT1s:
siteColor4[site]="red"
else:
siteColor4[site]="green"
if fromT1<T2downlinkT1s:
siteColor5[site]="red"
else:
siteColor5[site]="green"
# Think how to manage CERN T0
# T1:
# siteStatus1[site]=fromT0
# siteStatus2[site]=toT2
# ss3="%i(d)-%i(u)" % (fromT1,toT1)
# siteStatus3[site]=ss3
# T2:
# siteStatus4[site]=toT1
# siteStatus5[site]=fromT1
if site=="T0_CH_CERN":
siteStatus1[site]="n/a"
siteStatus2[site]="n/a"
siteStatus3[site]="n/a"
siteStatus4[site]="n/a"
siteStatus5[site]="n/a"
# Build SSB txt input files
span = 86400
reptime="# - Report made on %s (UTC)\n" % timestamp
f=file(metricPage1,'w')
f.write('# Site Status derived from DDT Commissioned Links\n')
f.write('#\n')
mesT1_1="T1 needs DDT commissioned downlink from T0_CH_CERN"
mesT1_1_2="T1::downlinkT0"
mes="# - Status of %s (Requirement: %s)\n" % (mesT1_1_2,mesT1_1)
f.write(mes)
f.write('#\n')
f.write(reptime)
f.write('#\n')
siteList2Delete = []
for i in range(0,len(keys)):
site=keys[i]
try:
status=siteStatus1[site]
except KeyError:
print "No panic. I just couldn't find the site: %s." % site
print "I will delete it from the site pool and continue."
print "--Please try to find the reason. (Is this site new?"
print "If so, ask transfer team whether they are currently working on this site or not.)"
siteList2Delete.append(i)
continue
if status=="n/a": continue
color=siteColor1[site]
link = linkmetrics + "#" + mesT1_1_2
f.write('%s\t%s\t%s\t%s\t%s\n' % (todaystampfileSSB, site, status, color, link))
f.close()
for i in siteList2Delete:
del keys[i]
f=file(metricPage2,'w')
f.write('# Site Status derived from DDT Commissioned Links\n')
mesT1_2="T1 needs >= %s DDT commissioned uplinks to T2 sites" % T1uplinksT2s
mesT1_2_2="T1::uplinksT2s"
mesT2_2_2="T2::downlinkT1s"
mes="# - Status of %s (Requirement: %s)\n" % (mesT1_2_2,mesT1_2)
f.write('#\n')
f.write(mes)
f.write('#\n')
f.write(reptime)
f.write('#\n')
for i in range(0,len(keys)):
site=keys[i]
status=siteStatus2[site]
if status=="n/a": continue
color=siteColor2[site]
link = linkmetrics + "#" + mesT1_2_2 + "_and_" + mesT2_2_2
f.write('%s\t%s\t%s\t%s\t%s\n' % (todaystampfileSSB, site, status, color, link))
f.close()
f=file(metricPage3,'w')
f.write('# Site Status derived from DDT Commissioned Links\n')
mesT1_3="T1 needs >= %s DDT commissioned uplinks and downlinks, respectively, with other T1 sites" % T1downlinksuplinksT1s
mesT1_3_2="T1::downlinks/uplinksT1s"
mes="# - Status of %s (Requirement: %s)\n" % (mesT1_3_2,mesT1_3)
f.write('#\n')
f.write(mes)
f.write('#\n')
f.write(reptime)
f.write('#\n')
for i in range(0,len(keys)):
site=keys[i]
status=siteStatus3[site]
if status=="n/a": continue
color=siteColor3[site]
link = linkmetrics + "#" + mesT1_3_2
f.write('%s\t%s\t%s\t%s\t%s\n' % (todaystampfileSSB, site, status, color, link))
f.close()
f=file(metricPage4,'w')
f.write('# Site Status derived from DDT Commissioned Links\n')
mesT2_1="T2 needs >= %s commissioned uplinks to T1 sites" % T2uplinkT1s
mesT2_1_2="T2::uplinkT1s"
mes="# - Status of %s (Requirement: %s)\n" % (mesT2_1_2,mesT2_1)
f.write('#\n')
f.write(mes)
f.write('#\n')
f.write(reptime)
f.write('#\n')
for i in range(0,len(keys)):
site=keys[i]
status=siteStatus4[site]
if status=="n/a": continue
color=siteColor4[site]
link = linkmetrics + "#" + mesT2_1_2
f.write('%s\t%s\t%s\t%s\t%s\n' % (todaystampfileSSB, site, status, color, link))
f.close()
f=file(metricPage5,'w')
f.write('# Site Status derived from DDT Commissioned Links\n')
mesT2_2="T2 needs >= %s commissioned downlinks from T1 sites" % T2downlinkT1s
#mesT2_2_2="T2::downlinkT1s"
mes="# - Status of %s (Requirement: %s)\n" % (mesT2_2_2,mesT2_2)
f.write('#\n')
f.write(mes)
f.write('#\n')
f.write(reptime)
f.write('#\n')
for i in range(0,len(keys)):
site=keys[i]
status=siteStatus5[site]
if status=="n/a": continue
color=siteColor5[site]
link = linkmetrics + "#" + mesT1_2_2 + "_and_" + mesT2_2_2
f.write('%s\t%s\t%s\t%s\t%s\n' % (todaystampfileSSB, site, status, color, link))
f.close()
####################################################################
# Print Site html view
####################################################################
# --> Fill all available T1s and T2s:
availableT1 = {}
availableT2 = {}
for i in range(0,len(keys)):
site=keys[i]
if site[1]=="1":
if "_Buffer" not in site and "_Disk" not in site: continue
if not availableT1.has_key(site):
availableT1[site]={}
elif site[1]=="2":
if not availableT2.has_key(site):
availableT2[site]={}
keyst1=availableT1.keys()
keyst1.sort()
keyst2=availableT2.keys()
keyst2.sort()
fileHandle = open ( filehtml , 'w' )
fileHandle.write("<html><head><link type=\"text/css\" rel=\"stylesheet\" href=\""+options.css+"/style-css-links.css\"/></head>\n")
fileHandle.write("<body><center>\n")
lw1="15"
lw2="550"
# T1_1 view
dw="75"
dw2="125"
fileHandle.write("<a name=\""+ mesT1_1_2 + "\"></a>\n\n")
fileHandle.write("<p><div id=\"metrics\"> Status of " + mesT1_1_2 + "</div>\n")
fileHandle.write("<br><div id=\"site\">" + reptime + "</div>\n")
#legends
fileHandle.write("<br>\n")
fileHandle.write("<table border=\"0\" cellspacing=\"0\" class=leg>\n")
fileHandle.write("<tr height=15>\n")
mes="Site status for %s (Requirement: %s).\n" % (mesT1_1_2,mesT1_1)
fileHandle.write("<td width=" + lw2 + " colspan=2><div id=\"legendexp\">" + mes + "</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw1 + " bgcolor=66FF44></td>\n")
fileHandle.write("<td width=" + lw2 + "><div id=\"legend\"> = Site satisfies the requirement.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw1 + " bgcolor=FF6600></td>\n")
fileHandle.write("<td width=" + lw2 + "><div id=\"legend\"> = Site failing the requirement.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("</table>\n")
fileHandle.write("<p>\n")
fileHandle.write("<p>\n")
fileHandle.write("<table border=\"0\" cellspacing=\"0\" class=leg>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw2 + " colspan=2><div id=\"legendexp\">Status on Data Transfer Links.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw1 + " bgcolor=green></td>\n")
fileHandle.write("<td width=" + lw2 + "><div id=\"legend\"> = Link is DDT-commissioned and enabled in Production PhEDEx instance.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw1 + " bgcolor=red></td>\n")
fileHandle.write("<td width=" + lw2 + "><div id=\"legend\"> = Link is not DDT-commissioned and is disabled in Production PhEDEx instance.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("</table>\n")
fileHandle.write("<p>\n")
fileHandle.write("<table border=\"0\" cellspacing=\"0\" class=stat>\n")
fileHandle.write("<p>\n")
for j in range(0,3):
fileHandle.write("<tr height=15>\n")
if j==0 or j==1:
fileHandle.write("<td width=" + dw2 + "><div id=\"site\"></div></td>\n")
if j==2:
fileHandle.write("<td width=" + dw2 + "><div id=\"site\"> T0_CH_CERN to:</div></td>\n")
for i in range(0,len(keyst1)):
site=keyst1[i]
if site[1]!="1": continue
#if "T1_CH_CERN" in site: continue
fromT0=len(sites[site]["downT0"])
if j==1:
if siteColor1[site]=="green":
color="66FF44"
if siteColor1[site]=="red":
color="FF6600"
if siteColor1[site]=="white":
color="white"
fileHandle.write("<td width=" + dw + " bgcolor=" + color + "><div id=\"site\">" + site + "</div></td>\n")
if j==0:
mes="%i link enabled" % siteStatus1[site]
fileHandle.write("<td width=" + dw + "><div id=enabled>" + mes + "</div></td>\n")
if j==2:
fileHandle.write("<td width=" + dw + " bgcolor=" + siteColor1[site] + "></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("</table>\n")
fileHandle.write("<p><br>\n")
# T1_3 view
dw="75"
dw2="150"
dw3="50"
fileHandle.write("<a name=\""+ mesT1_3_2 + "\"></a>\n\n")
fileHandle.write("<p><div id=\"metrics\"> Status of " + mesT1_3_2 + "</div>\n")
fileHandle.write("<br><div id=\"site\">" + reptime + "</div>\n")
#legends
lw2="800"
fileHandle.write("<br>\n")
fileHandle.write("<table border=\"0\" cellspacing=\"0\" class=leg>\n")
fileHandle.write("<tr height=15>\n")
mes="Site status for %s (Requirement: %s).\n" % (mesT1_3_2,mesT1_3)
fileHandle.write("<td width=" + lw2 + " colspan=2><div id=\"legendexp\">" + mes + "</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw1 + " bgcolor=66FF44></td>\n")
fileHandle.write("<td width=" + lw2 + "><div id=\"legend\"> = Site satisfies the requirement.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw1 + " bgcolor=FF6600></td>\n")
fileHandle.write("<td width=" + lw2 + "><div id=\"legend\"> = Site failing the requirement.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("</table>\n")
fileHandle.write("<p>\n")
fileHandle.write("<p>\n")
fileHandle.write("<table border=\"0\" cellspacing=\"0\" class=leg>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw2 + " colspan=2><div id=\"legendexp\">Status on Data Transfer Links.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw1 + " bgcolor=green></td>\n")
fileHandle.write("<td width=" + lw2 + "><div id=\"legend\"> = Link is DDT-commissioned and enabled in Production PhEDEx instance.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw1 + " bgcolor=red></td>\n")
fileHandle.write("<td width=" + lw2 + "><div id=\"legend\"> = Link is not DDT-commissioned and is disabled in Production PhEDEx instance.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("</table>\n")
fileHandle.write("<p>\n")
fileHandle.write("<table border=\"0\" cellspacing=\"0\" class=stat>\n")
fileHandle.write("<p>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + dw2 + "><div id=\"site\"></div></td>\n")
for k in range(0,len(availableT1)):
t1site2=keyst1[k]
mes="%s links enabled" % siteStatus3[t1site2]
fileHandle.write("<td width=" + dw + " colspan=2><div id=enabled>" + mes + "</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + dw2 + "><div id=\"site\"></div></td>\n")
for k in range(0,len(availableT1)):
t1site2=keyst1[k]
if siteColor3[t1site2]=="green":
color="66FF44"
if siteColor3[t1site2]=="red":
color="FF6600"
if siteColor3[t1site2]=="white":
color="white"
fileHandle.write("<td width=" + dw3 + " colspan=2 bgcolor=" + color + "><div id=\"site\">" + t1site2 + "</div></td>\n")
fileHandle.write("</tr>\n")
for j in range(0,len(availableT1)):
t1site=keyst1[j]
if siteColor3[t1site]=="green":
color="66FF44"
if siteColor3[t1site]=="red":
color="FF6600"
if siteColor3[t1site]=="white":
color="white"
fileHandle.write("<td width=" + dw + " bgcolor=" + color + "><div id=\"site\">" + t1site + "</div></td>\n")
for k in range(0,len(availableT1)):
t1site2=keyst1[k]
if sites[t1site]["upT1"].count(t1site2) != 0:
color="green"
else:
color="red"
if t1site==t1site2:
color="black"
if color=="black":
fileHandle.write("<td width=" + dw3 + " bgcolor=" + color + "><div id=comment></div></td>\n")
else:
fileHandle.write("<td width=" + dw3 + " bgcolor=" + color + "><div id=comment>to:</div></td>\n")
if sites[t1site]["downT1"].count(t1site2) != 0:
color="green"
else:
color="red"
if t1site==t1site2:
color="black"
if color=="black":
fileHandle.write("<td width=" + dw3 + " bgcolor=" + color + "><div id=comment></div></td>\n")
else:
fileHandle.write("<td width=" + dw3 + " bgcolor=" + color + "><div id=comment>from:</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("</table>\n")
fileHandle.write("<p><br>\n")
# T2_1 view
dw="75"
dw2="125"
fileHandle.write("<a name=\""+ mesT2_1_2 + "\"></a>\n\n")
fileHandle.write("<p><div id=\"metrics\"> Status of " + mesT2_1_2 + "</div>\n")
fileHandle.write("<br><div id=\"site\">" + reptime + "</div>\n")
#legends
lw2="550"
fileHandle.write("<br>\n")
fileHandle.write("<table border=\"0\" cellspacing=\"0\" class=leg>\n")
fileHandle.write("<tr height=15>\n")
mes="Site status for %s (Requirement: %s).\n" % (mesT2_1_2,mesT2_1)
fileHandle.write("<td width=" + lw2 + " colspan=2><div id=\"legendexp\">" + mes + "</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw1 + " bgcolor=66FF44></td>\n")
fileHandle.write("<td width=" + lw2 + "><div id=\"legend\"> = Site satisfies the requirement.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw1 + " bgcolor=FF6600></td>\n")
fileHandle.write("<td width=" + lw2 + "><div id=\"legend\"> = Site failing the requirement.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("</table>\n")
fileHandle.write("<p>\n")
fileHandle.write("<p>\n")
fileHandle.write("<table border=\"0\" cellspacing=\"0\" class=leg>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw2 + " colspan=2><div id=\"legendexp\">Status on Data Transfer Links.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw1 + " bgcolor=green></td>\n")
fileHandle.write("<td width=" + lw2 + "><div id=\"legend\"> = Link is DDT-commissioned and enabled in Production PhEDEx instance.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw1 + " bgcolor=red></td>\n")
fileHandle.write("<td width=" + lw2 + "><div id=\"legend\"> = Link is not DDT-commissioned and is disabled in Production PhEDEx instance.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("</table>\n")
fileHandle.write("<p>\n")
fileHandle.write("<table border=\"0\" cellspacing=\"0\" class=stat>\n")
fileHandle.write("<p>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + dw2 + "><div id=\"site\"></div></td>\n")
fileHandle.write("<td width=" + dw2 + "><div id=\"site\"></div></td>\n")
for k in range(0,len(availableT1)):
t1site=keyst1[k]
fileHandle.write("<td width=" + dw + "><div id=\"site\">" + t1site + "</div></td>\n")
fileHandle.write("</tr>\n")
for j in range(0,len(availableT2)):
t2site=keyst2[j]
fileHandle.write("<tr height=15>\n")
mes="%s links enabled" % siteStatus4[t2site]
fileHandle.write("<td width=" + dw + "><div id=enabled>" + mes + "</div></td>\n")
if siteColor4[t2site]=="green":
color="66FF44"
if siteColor4[t2site]=="red":
color="FF6600"
if siteColor4[t2site]=="white":
color="white"
fileHandle.write("<td width=" + dw2 + " bgcolor=" + color +"><div id=\"site\">" + t2site + " to:</div></td>\n")
for k in range(0,len(availableT1)):
t1site=keyst1[k]
if sites[t2site]["upT1"].count(t1site) != 0:
color="green"
else:
color="red"
fileHandle.write("<td width=" + dw + " bgcolor=" + color + "></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("</table>\n")
fileHandle.write("<p><br>\n")
# T2_2 view
dw="75"
dw2="125"
fileHandle.write("<a name=\""+ mesT1_2_2 + "_and_" + mesT2_2_2 + "\"></a>\n\n")
fileHandle.write("<p><div id=\"metrics\"> Status of " + mesT2_2_2 + " & " + mesT1_2_2 + "</div>\n")
fileHandle.write("<br><div id=\"site\">" + reptime + "</div>\n")
#legends
fileHandle.write("<br>\n")
fileHandle.write("<table border=\"0\" cellspacing=\"0\" class=leg>\n")
fileHandle.write("<tr height=15>\n")
mes="Site status for %s (Requirement: %s).\n" % (mesT2_2_2,mesT2_2)
fileHandle.write("<td width=" + lw2 + " colspan=2><div id=\"legendexp\">" + mes + "</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
mes="Site status for %s (Requirement: %s).\n" % (mesT1_2_2,mesT1_2)
fileHandle.write("<td width=" + lw2 + " colspan=2><div id=\"legendexp\">" + mes + "</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw1 + " bgcolor=66FF44></td>\n")
fileHandle.write("<td width=" + lw2 + "><div id=\"legend\"> = Site satisfies the requirement.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw1 + " bgcolor=FF6600></td>\n")
fileHandle.write("<td width=" + lw2 + "><div id=\"legend\"> = Site failing the requirement.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("</table>\n")
fileHandle.write("<p>\n")
fileHandle.write("<p>\n")
fileHandle.write("<table border=\"0\" cellspacing=\"0\" class=leg>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw2 + " colspan=2><div id=\"legendexp\">Status on Data Transfer Links.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw1 + " bgcolor=green></td>\n")
fileHandle.write("<td width=" + lw2 + "><div id=\"legend\"> = Link is DDT-commissioned and enabled in Production PhEDEx instance.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + lw1 + " bgcolor=red></td>\n")
fileHandle.write("<td width=" + lw2 + "><div id=\"legend\"> = Link is not DDT-commissioned and is disabled in Production PhEDEx instance.</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("</table>\n")
fileHandle.write("<p>\n")
fileHandle.write("<table border=\"0\" cellspacing=\"0\" class=stat>\n")
fileHandle.write("<p>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + dw2 + "><div id=\"site\"></div></td>\n")
fileHandle.write("<td width=" + dw2 + "><div id=\"site2\">(T1::uplinksT2s)</div></td>\n")
for k in range(0,len(availableT1)):
t1site=keyst1[k]
mes="%i links enabled" % siteStatus2[t1site]
fileHandle.write("<td width=" + dw + "><div id=enabled>" + mes + "</div></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("<tr height=15>\n")
fileHandle.write("<td width=" + dw2 + "><div id=\"site\">(T2::downlinkT1s)</div></td>\n")
fileHandle.write("<td width=" + dw2 + "><div id=\"site\"></div></td>\n")
for k in range(0,len(availableT1)):
t1site=keyst1[k]
if siteColor2[t1site]=="green":
color="66FF44"
if siteColor2[t1site]=="red":
color="FF6600"
if siteColor2[t1site]=="white":
color="white"
fileHandle.write("<td width=" + dw + " bgcolor=" + color + "><div id=\"site\">" + t1site + "</div></td>\n")
fileHandle.write("</tr>\n")
#fileHandle.write("<tr height=15>\n")
#fileHandle.write("<td width=" + dw2 + "><div id=\"site\"></div></td>\n")
#fileHandle.write("<td width=" + dw2 + "><div id=\"site\"></div></td>\n")
#for k in range(0,len(availableT1)):
# t1site=keyst1[k]
# fileHandle.write("<td width=" + dw + "><div id=\"site\">" + t1site + "</div></td>\n")
#fileHandle.write("</tr>\n")
for j in range(0,len(availableT2)):
t2site=keyst2[j]
fileHandle.write("<tr height=15>\n")
mes="%s links enabled" % siteStatus5[t2site]
fileHandle.write("<td width=" + dw + "><div id=enabled>" + mes + "</div></td>\n")
if siteColor5[t2site]=="green":
color="66FF44"
if siteColor5[t2site]=="red":
color="FF6600"
if siteColor5[t2site]=="white":
color="white"
fileHandle.write("<td width=" + dw2 + " bgcolor=" + color +"><div id=\"site\">" + t2site + " from:</div></td>\n")
for k in range(0,len(availableT1)):
t1site=keyst1[k]
if sites[t2site]["downT1"].count(t1site) != 0:
color="green"
else:
color="red"
fileHandle.write("<td width=" + dw + " bgcolor=" + color + "></td>\n")
fileHandle.write("</tr>\n")
fileHandle.write("</table>\n")
fileHandle.write("<p><br>\n")
fileHandle.write("</center></html></body>")
fileHandle.close()
os.chdir(pathoutHTML)
if os.path.isfile(slinkhtml): os.remove(slinkhtml)
os.symlink(os.path.split(filehtml)[1],slinkhtml)