-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathXSFeatureSRCreate.py
More file actions
1455 lines (1254 loc) · 61.8 KB
/
Copy pathXSFeatureSRCreate.py
File metadata and controls
1455 lines (1254 loc) · 61.8 KB
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
# Copyright (c) 2008-2009 Citrix Systems Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
if __name__ == "__main__":
raise Exception("This script is a plugin for xsconsole and cannot run independently")
from XSConsoleStandard import *
import xml.dom.minidom
class SRNewDialogue(Dialogue):
srTypes = {
'NFS': 'nfs',
'ISCSI': 'lvmoiscsi',
'HBA': 'lvmohba',
'EQUAL': 'equal',
'NETAPP': 'netapp',
'CIFS_ISO': 'iso',
'NFS_ISO': 'iso'
}
srTypeNames = {
'NFS': Lang('NFS VHD'),
'ISCSI': Lang('Software iSCSI'),
'HBA': Lang('Hardware HBA'),
'EQUAL': Lang('Dell EqualLogic'),
'NETAPP': Lang('NetApp'),
'CIFS_ISO': Lang('Windows File Sharing (CIFS) ISO Library'),
'NFS_ISO': Lang('NFS ISO Library')
}
netAppProvisioning = {
'THICK' : Struct(name=Lang('Thick Provisioning'), config={'allocation':'thick'}),
'THIN_NO_ASIS' : Struct(name=Lang('Thin Provisioning Without A-SIS Deduplication'), config={'allocation':'thin','asis':'false'}),
'THIN_ASIS' : Struct(name=Lang('Thin Provisioning With A-SIS Deduplication'), config={'allocation':'thin', 'asis':'true'})
}
def NetAppProvisioningName(self, inType):
return self.netAppProvisioning[inType].name
def NetAppProvisioningConfig(self, inType):
return self.netAppProvisioning[inType].config
def __init__(self, inVariant):
Dialogue.__init__(self)
self.variant = inVariant
self.srParams = {}
self.createMenu = Menu()
if self.variant == 'CREATE':
choices = ['NFS', 'ISCSI', 'HBA', 'EQUAL', 'NETAPP']
else: # ATTACH choices
choices = ['NFS', 'ISCSI', 'HBA', 'EQUAL', 'NETAPP', 'CIFS_ISO', 'NFS_ISO']
srSupportedTypes = Task.Sync(lambda x: x.xenapi.SR.get_supported_types())
for type in choices:
if self.srTypes[type] in srSupportedTypes:
self.createMenu.AddChoice(name = self.srTypeNames[type],
onAction = self.HandleCreateChoice,
handle = type)
self.ChangeState('INITIAL')
def IQNString(self, inIQN, inLUN = None):
if inLUN is None or int(inLUN) > 999: # LUN not present or more than 3 characters
retVal = "TPGT %-5.5s %-60.60s" % (inIQN.tpgt[:5], inIQN.name[:60])
else:
retVal = "TPGT %-5.5s %-52.52s LUN %-3.3s" % (inIQN.tpgt[:5], inIQN.name[:52], str(inLUN)[:3])
return retVal
def LUNString(self, inLUN):
retVal = "LUN %-4.4s %s" % (inLUN.LUNid[:4], (SizeUtils.SRSizeString(inLUN.size)+ ' ('+inLUN.vendor)[:62]+')')
return retVal
def AggregateString(self, inAggregate):
retVal = "%-60.60s %-9.9s" % (inAggregate.name[:60], (SizeUtils.SRSizeString(inAggregate.size))[:9])
return retVal
def NetAppSRString(self, inNetAppSR):
retVal = "%-36.36s %-22.22s %-9.9s" % (self.ExtendedSRName(inNetAppSR.uuid)[:36], inNetAppSR.aggregate[:22], (SizeUtils.SRSizeString(inNetAppSR.size))[:9])
return retVal
def DeviceString(self, inDevice):
idLen=72
idPrefix = inDevice.vendor[:10]+' ' + ('%7s' % SizeUtils.SRSizeString(inDevice.size)) + ' '
idString = idPrefix + inDevice.serial + ' ' + inDevice.path
if len(idString) > idLen:
idString = idPrefix + inDevice.serial + ' ' + inDevice.path[:5]+'...'
spaceLeft = idLen - len(idString)
if spaceLeft > 0:
idString += inDevice.path[-spaceLeft:]
retVal = idString[:72]
return retVal
def EqualSizeStr(self, inSize):
if re.match(r'.*B$', inSize):
retVal = inSize
else:
retVal = SizeUtils.SRSizeString(inSize)
return retVal
def StoragePoolString(self, inStoragePool):
retVal = "%-39.39s %32.32s" % (inStoragePool.name[:39], (self.EqualSizeStr(inStoragePool.capacity))[:12] + (' ('+self.EqualSizeStr(inStoragePool.freespace)[:12]+Lang(' free)'))[:32])
return retVal
def EqualSRString(self, inSR):
retVal = "%-56.56s %-12.12s" % (self.ExtendedSRName(inSR.uuid)[:56], (SizeUtils.SRSizeString(inSR.size))[:12])
return retVal
def ExtendedSRName(self, inUUID):
retVal = inUUID
matchingSRs = [ sr for sr in HotAccessor().sr if sr.uuid() == inUUID ]
if len(matchingSRs) > 0:
sr = matchingSRs[0]
retVal = sr.name_label(Lang('<Unknown>'))
if len(sr.PBDs()) == 0:
retVal += Lang(' (detached)')
return retVal
def BuildPanePROBE_NFS(self):
self.srMenu = Menu()
names = {}
for sr in HotAccessor().sr:
names[sr.uuid()] = sr.name_label(Lang('<Unknown>'))
if len(sr.PBDs()) == 0:
names[sr.uuid()] += Lang(' (detached)')
for srChoice in self.srChoices:
self.srMenu.AddChoice(name = self.ExtendedSRName(srChoice),
onAction = self.HandleProbeChoice,
handle = srChoice)
if self.srMenu.NumChoices() == 0:
self.srMenu.AddChoice(name = Lang('<No Storage Repositories Detected>'))
def BuildPanePROBE_ISCSI_IQN(self):
self.iqnMenu = Menu()
for iqnChoice in self.iqnChoices:
self.iqnMenu.AddChoice(name = self.IQNString(iqnChoice),
onAction = self.HandleIQNChoice,
handle = iqnChoice)
if self.iqnMenu.NumChoices() == 0:
self.iqnMenu.AddChoice(name = Lang('<No IQNs Detected>'))
def BuildPanePROBE_ISCSI_LUN(self):
self.lunMenu = Menu()
for lunChoice in self.lunChoices:
self.lunMenu.AddChoice(name = self.LUNString(lunChoice),
onAction = self.HandleLUNChoice,
handle = lunChoice)
if self.lunMenu.NumChoices() == 0:
self.lunMenu.AddChoice(name = Lang('<No LUNs Detected>'))
def BuildPanePROBE_ISCSI_SR(self):
self.srMenu = Menu()
for srChoice in self.srChoices:
self.srMenu.AddChoice(name = self.ExtendedSRName(srChoice),
onAction = self.HandleiSCSISRChoice,
handle = srChoice)
if self.srMenu.NumChoices() == 0:
self.srMenu.AddChoice(name = Lang('<No Storage Repositories Detected>'))
def BuildPanePROBE_NETAPP_AGGREGATE(self):
self.aggregateMenu = Menu()
for aggregateChoice in self.aggregateChoices:
self.aggregateMenu.AddChoice(name = self.AggregateString(aggregateChoice),
onAction = self.HandleAggregateChoice,
handle = aggregateChoice)
if self.aggregateMenu.NumChoices() == 0:
self.aggregateMenu.AddChoice(name = Lang('<No Aggregates Detected>'))
def BuildPanePROBE_NETAPP_PROVISIONING(self):
self.provisioningMenu = Menu()
self.provisioningMenu.AddChoice(name = self.NetAppProvisioningName('THICK'),
onAction = self.HandleProvisioningChoice,
handle = 'THICK')
self.provisioningMenu.AddChoice(name = self.NetAppProvisioningName('THIN_NO_ASIS'),
onAction = self.HandleProvisioningChoice,
handle = 'THIN_NO_ASIS')
if self.srParams['aggregate'].asisdedup.lower().startswith('true'):
self.provisioningMenu.AddChoice(name = self.NetAppProvisioningName('THIN_ASIS'),
onAction = self.HandleProvisioningChoice,
handle = 'THIN_ASIS')
else:
self.provisioningMenu.AddChoice(name = Lang('<This Aggregate Does Not Support A-SIS Deduplication>'))
def BuildPanePROBE_NETAPP_SR(self):
self.srMenu = Menu()
for srChoice in self.netAppSRChoices:
self.srMenu.AddChoice(name = self.NetAppSRString(srChoice),
onAction = self.HandleNetAppSRChoice,
handle = srChoice)
if self.srMenu.NumChoices() == 0:
self.srMenu.AddChoice(name = Lang('<No Storage Repositories Detected>'))
def BuildPanePROBE_HBA_DEVICE(self):
self.deviceMenu = Menu()
for deviceChoice in self.deviceChoices:
self.deviceMenu.AddChoice(name = self.DeviceString(deviceChoice),
onAction = self.HandleDeviceChoice,
handle = deviceChoice)
if self.deviceMenu.NumChoices() == 0:
self.deviceMenu.AddChoice(name = Lang('<No Devices Detected>'))
def BuildPanePROBE_HBA_SR(self):
self.srMenu = Menu()
for srChoice in self.srChoices:
self.srMenu.AddChoice(name = self.ExtendedSRName(srChoice),
onAction = self.HandleHBASRChoice,
handle = srChoice)
if self.srMenu.NumChoices() == 0:
self.srMenu.AddChoice(name = Lang('<No Storage Repositories Detected>'))
def BuildPanePROBE_EQUAL_STORAGEPOOL(self):
self.storagePoolMenu = Menu()
for storagePoolChoice in self.storagePoolChoices:
self.storagePoolMenu.AddChoice(name = self.StoragePoolString(storagePoolChoice),
onAction = self.HandleStoragePoolChoice,
handle = storagePoolChoice)
if self.storagePoolMenu.NumChoices() == 0:
self.storagePoolMenu.AddChoice(name = Lang('<No Storage Pools Detected>'))
def BuildPanePROBE_EQUAL_SR(self):
self.srMenu = Menu()
for srChoice in self.equalSRChoices:
self.srMenu.AddChoice(name = self.EqualSRString(srChoice),
onAction = self.HandleEqualSRChoice,
handle = srChoice)
if self.srMenu.NumChoices() == 0:
self.srMenu.AddChoice(name = Lang('<No Storage Repositories Detected>'))
def BuildPane(self):
pane = self.NewPane(DialoguePane(self.parent))
pane.TitleSet(Lang("New Storage Repository"))
pane.AddBox()
if hasattr(self, 'BuildPane'+self.state):
handled = getattr(self, 'BuildPane'+self.state)() # Despatch method named 'BuildPane'+self.state
def UpdateFieldsINITIAL(self):
pane = self.Pane()
pane.ResetFields()
pane.AddTitleField(Lang('Please select the type of Storage Repository to ')+Lang(self.variant.lower()))
pane.AddMenuField(self.createMenu)
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
def UpdateFieldsGATHER_NFS(self):
pane = self.Pane()
pane.ResetFields()
pane.AddTitleField(Lang('Please enter a name and path for the NFS Storage Repository'))
pane.AddInputField(Lang('Name', 16), self.srParams.get('name', Lang('NFS virtual disk storage')), 'name')
pane.AddInputField(Lang('Description', 16), '', 'description')
pane.AddInputField(Lang('Share Name', 16), self.srParams.get('sharename', 'server:/path'), 'sharename')
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
if pane.CurrentInput() is None:
pane.InputIndexSet(0)
def UpdateFieldsGATHER_NFS_ISO(self):
pane = self.Pane()
pane.ResetFields()
pane.AddTitleField(Lang('Please enter a name and path for the NFS ISO Library'))
pane.AddInputField(Lang('Name', 20), self.srParams.get('name', Lang('NFS ISO Library')), 'name')
pane.AddInputField(Lang('Description', 20), '', 'description')
pane.AddInputField(Lang('Share Name', 20), self.srParams.get('sharename', 'server:/path'), 'sharename')
pane.AddInputField(Lang('Advanced Options', 20), '', 'options')
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
if pane.CurrentInput() is None:
pane.InputIndexSet(0)
def UpdateFieldsGATHER_CIFS_ISO(self):
pane = self.Pane()
pane.ResetFields()
pane.AddTitleField(Lang('Please enter a name and path for the CIFS ISO Library. Leave the Username/Password fields blank if not required.'))
pane.AddInputField(Lang('Name', 20), self.srParams.get('name', Lang('CIFS ISO Library')), 'name')
pane.AddInputField(Lang('Description', 20), '', 'description')
pane.AddInputField(Lang('Share Name', 20), self.srParams.get('sharename', '\\\\server\\sharename'), 'sharename')
pane.AddInputField(Lang('Username', 20), '', 'username')
pane.AddPasswordField(Lang('Password', 20), '', 'cifspassword')
pane.AddInputField(Lang('Advanced Options', 20), '', 'options')
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
if pane.CurrentInput() is None:
pane.InputIndexSet(0)
def UpdateFieldsGATHER_ISCSI(self):
pane = self.Pane()
pane.ResetFields()
pane.AddTitleField(Lang('Please enter the configuration details for the iSCSI Storage Repository'))
pane.AddInputField(Lang('Name', 26), self.srParams.get('name', Lang('iSCSI virtual disk storage')), 'name')
pane.AddInputField(Lang('Description', 26), '', 'description')
pane.AddInputField(Lang('Initiator IQN', 26), HotAccessor().local_host.other_config.iscsi_iqn(''), 'localiqn')
pane.AddInputField(Lang('Port Number', 26), '3260', 'port')
pane.AddInputField(Lang('Hostname of iSCSI Target', 26), '', 'remotehost')
pane.AddInputField(Lang('Username', 26), '', 'username')
pane.AddPasswordField(Lang('Password', 26), '', 'password')
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
if pane.CurrentInput() is None:
pane.InputIndexSet(0)
def UpdateFieldsGATHER_NETAPP(self):
pane = self.Pane()
pane.ResetFields()
pane.AddTitleField(Lang('Please enter the configuration details for the NetApp Storage Repository. Leave CHAP Username/Password blank if not required.'))
pane.AddInputField(Lang('Name', 26), self.srParams.get('name', Lang('NetApp virtual disk storage')), 'name')
pane.AddInputField(Lang('Description', 26), '', 'description')
pane.AddInputField(Lang('NetApp Filer Address', 26), '', 'target')
pane.AddInputField(Lang('Username', 26), '', 'username')
pane.AddPasswordField(Lang('Password', 26), '', 'password')
pane.AddInputField(Lang('CHAP Username', 26), '', 'chapuser')
pane.AddPasswordField(Lang('CHAP Password', 26), '', 'chappassword')
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
if pane.CurrentInput() is None:
pane.InputIndexSet(0)
def UpdateFieldsGATHER_HBA(self):
data = Data.Inst()
pane = self.Pane()
pane.ResetFields()
pane.AddTitleField(Lang('Hardware HBA'))
# Text copied from XenCenter
pane.AddWrappedTextField(Lang(Language.Inst().Branding(data.host.software_version.product_brand('')) + ' Hosts support Fibre Channel (FC) and shared Serial Attached SCSI (SAS) '
'storage area networks (SANs) using host bus adapters (HBAs). All FC or shared SAS configuration required '
'to expose a LUN to the host must be completed manually, including storage devices, network devices, '
'and the HBA within the host. Once all configuration is completed the HBA will expose '
'a SCSI device backed by the LUN to the host. The SCSI device can then be used to access the '
'LUN as if it were a locally attached SCSI device.'))
pane.NewLine()
pane.AddWrappedTextField(Lang('Press <Enter> to scan for HBA devices.'))
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
def UpdateFieldsGATHER_EQUAL(self):
pane = self.Pane()
pane.ResetFields()
pane.AddTitleField(Lang('Please enter the configuration details for the Dell EqualLogic Storage Repository. Leave CHAP Username/Password blank if not required.'))
pane.AddInputField(Lang('Name', 26), self.srParams.get('name', Lang('Dell EqualLogic virtual disk storage')), 'name')
pane.AddInputField(Lang('Description', 26), '', 'description')
pane.AddInputField(Lang('Filer Address', 26), '', 'target')
pane.AddInputField(Lang('Username', 26), '', 'username')
pane.AddPasswordField(Lang('Password', 26), '', 'password')
pane.AddInputField(Lang('CHAP Username', 26), '', 'chapuser')
pane.AddPasswordField(Lang('CHAP Password', 26), '', 'chappassword')
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
if pane.CurrentInput() is None:
pane.InputIndexSet(0)
def UpdateFieldsPROBE_NFS(self):
pane = self.Pane()
pane.ResetFields()
pane.AddWarningField('WARNING')
pane.AddWrappedBoldTextField(Lang('You must ensure that the chosen SR is not in use by any server '
'that is not a member of this Pool. Failure to do so may result in data loss.'))
pane.NewLine()
pane.AddWrappedBoldTextField(Lang('Please select the Storage Repository to ')+Lang(self.variant.lower()))
pane.NewLine()
pane.AddMenuField(self.srMenu, 7) # Only room for 7 menu items
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
def UpdateFieldsPROBE_ISCSI_IQN(self):
pane = self.Pane()
pane.ResetFields()
pane.AddTitleField(Lang('Please select from the list of discovered IQNs.'))
pane.AddMenuField(self.iqnMenu)
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel"), Lang("<Space>") : Lang("More Information On Item") } )
def UpdateFieldsPROBE_ISCSI_LUN(self):
pane = self.Pane()
pane.ResetFields()
pane.AddTitleField(Lang('Please select from the list of discovered LUNs.'))
pane.AddMenuField(self.lunMenu)
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
def UpdateFieldsPROBE_ISCSI_SR(self):
pane = self.Pane()
pane.ResetFields()
pane.AddWarningField('WARNING')
pane.AddWrappedBoldTextField(Lang('You must ensure that the chosen SR is not in use by any server '
'that is not a member of this Pool. Failure to do so may result in data loss.'))
pane.NewLine()
pane.AddTitleField(Lang('Please select from the list of discovered Storage Repositories.'))
pane.AddMenuField(self.srMenu, 7) # Only room for 7 menu items
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
def UpdateFieldsPROBE_NETAPP_AGGREGATE(self):
pane = self.Pane()
pane.ResetFields()
pane.AddTitleField(Lang('Please select from the list of discovered Aggregates.'))
pane.AddMenuField(self.aggregateMenu)
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
def UpdateFieldsPROBE_NETAPP_FLEXVOLS(self):
pane = self.Pane()
pane.ResetFields()
pane.AddTitleField(Lang('Please enter the number of FlexVols to assign to this Storage Repository.'))
pane.AddInputField(Lang('Number of FlexVols',24), '8', 'numflexvols')
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
if pane.CurrentInput() is None:
pane.InputIndexSet(0)
def UpdateFieldsPROBE_NETAPP_PROVISIONING(self):
pane = self.Pane()
pane.ResetFields()
pane.AddTitleField(Lang('Please select the provisioning type for this Storare Repository.'))
pane.AddMenuField(self.provisioningMenu)
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
def UpdateFieldsPROBE_NETAPP_SR(self):
pane = self.Pane()
pane.ResetFields()
pane.AddWarningField('WARNING')
pane.AddWrappedBoldTextField(Lang('You must ensure that the chosen SR is not in use by any server '
'that is not a member of this Pool. Failure to do so may result in data loss.'))
pane.NewLine()
pane.AddTitleField(Lang('Please select from the list of discovered Storage Repositories.'))
pane.AddMenuField(self.srMenu, 7) # Only room for 7 menu items
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
def UpdateFieldsPROBE_HBA_DEVICE(self):
pane = self.Pane()
pane.ResetFields()
pane.AddTitleField(Lang('Please select from the list of discovered HBA devices.'))
pane.AddMenuField(self.deviceMenu)
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
def UpdateFieldsPROBE_HBA_NAME(self):
pane = self.Pane()
pane.ResetFields()
if self.hbaWarn:
pane.AddWarningField(Lang('This device already contains a Storage Repository, and this Create operation will overwrite it. Choose Attach Existing Storage Repository to retain the original contents.'))
pane.AddTitleField(Lang('Please enter the name and description for the HBA Storage Repository.'))
pane.AddInputField(Lang('Name', 26), self.srParams.get('name', Lang('Hardware HBA virtual disk storage')), 'name')
pane.AddInputField(Lang('Description', 26), '', 'description')
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
if pane.CurrentInput() is None:
pane.InputIndexSet(0)
def UpdateFieldsPROBE_HBA_SR(self):
pane = self.Pane()
pane.ResetFields()
pane.AddWarningField('WARNING')
pane.AddWrappedBoldTextField(Lang('You must ensure that the chosen SR is not in use by any server '
'that is not a member of this Pool. Failure to do so may result in data loss.'))
pane.NewLine()
pane.AddTitleField(Lang('Please select from the list of discovered Storage Repositories.'))
pane.AddMenuField(self.srMenu, 7) # Only room for 7 menu items
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
def UpdateFieldsPROBE_EQUAL_STORAGEPOOL(self):
pane = self.Pane()
pane.ResetFields()
pane.AddTitleField(Lang('Please select from the list of discovered Storage Pools.'))
pane.AddMenuField(self.storagePoolMenu)
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
def UpdateFieldsPROBE_EQUAL_SR(self):
pane = self.Pane()
pane.ResetFields()
pane.AddWarningField('WARNING')
pane.AddWrappedBoldTextField(Lang('You must ensure that the chosen SR is not in use by any server '
'that is not a member of this Pool. Failure to do so may result in data loss.'))
pane.NewLine()
pane.AddTitleField(Lang('Please select from the list of discovered Storage Repositories.'))
pane.AddMenuField(self.srMenu, 7) # Only room for 7 menu items
pane.AddKeyHelpField( { Lang("<Enter>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
def UpdateFieldsCONFIRM(self):
pane = self.Pane()
pane.ResetFields()
pane.AddTitleField(Lang('Press <F8> to ')+Lang(self.variant.lower())+Lang(' this Storage Repository'))
pane.AddStatusField(Lang('SR Type', 26), self.srTypeNames[self.createType])
for name, value in self.extraInfo:
pane.AddStatusField(name.ljust(26, ' '), value)
pane.NewLine()
pane.AddKeyHelpField( { Lang("<F8>") : Lang("OK"), Lang("<Esc>") : Lang("Cancel") } )
def UpdateFields(self):
self.Pane().ResetPosition()
getattr(self, 'UpdateFields'+self.state)() # Despatch method named 'UpdateFields'+self.state
def ChangeState(self, inState):
self.state = inState
self.BuildPane()
self.UpdateFields()
def HandleKeyINITIAL(self, inKey):
return self.createMenu.HandleKey(inKey)
def HandleInputFieldKeys(self, inKey):
handled = True
pane = self.Pane()
if pane.CurrentInput() is None:
pane.InputIndexSet(0)
if inKey in ['KEY_ENTER', 'KEY_TAB']:
pane.ActivateNextInput()
elif inKey == 'KEY_BTAB':
pane.ActivatePreviousInput()
elif pane.CurrentInput().HandleKey(inKey):
pass # Leave handled as True
else:
handled = False
return handled
def HandleKeyGATHER_NFS(self, inKey):
handled = True
pane = self.Pane()
if inKey == 'KEY_ENTER' and pane.IsLastInput():
try:
inputValues = pane.GetFieldValues()
if self.variant == 'ATTACH':
Layout.Inst().TransientBanner(Lang('Probing for Storage Repositories...'))
self.HandleCommonData(inputValues)
self.HandleNFSData(inputValues)
except Exception as e:
pane.InputIndexSet(None)
Layout.Inst().PushDialogue(InfoDialogue(Lang("Operation Failed"), Lang(e)))
else:
handled = self.HandleInputFieldKeys(inKey)
return handled
def HandleKeyGATHER_NFS_ISO(self, inKey):
return self.HandleKeyGATHER_NFS(inKey)
def HandleKeyGATHER_CIFS_ISO(self, inKey):
handled = True
pane = self.Pane()
if inKey == 'KEY_ENTER' and pane.IsLastInput():
try:
inputValues = pane.GetFieldValues()
self.HandleCommonData(inputValues)
self.HandleCIFSData(inputValues)
except Exception as e:
pane.InputIndexSet(None)
Layout.Inst().PushDialogue(InfoDialogue(Lang("Operation Failed"), Lang(e)))
else:
handled = self.HandleInputFieldKeys(inKey)
return handled
def HandleKeyGATHER_ISCSI(self, inKey):
handled = True
pane = self.Pane()
if inKey == 'KEY_ENTER' and pane.IsLastInput():
try:
inputValues = pane.GetFieldValues()
self.HandleCommonData(inputValues)
self.HandleISCSIData(inputValues)
except Exception as e:
pane.InputIndexSet(None)
Layout.Inst().PushDialogue(InfoDialogue(Lang("Operation Failed"), Lang(e)))
else:
handled = self.HandleInputFieldKeys(inKey)
return handled
def HandleKeyGATHER_NETAPP(self, inKey):
handled = True
pane = self.Pane()
if inKey == 'KEY_ENTER' and pane.IsLastInput():
try:
inputValues = pane.GetFieldValues()
Layout.Inst().TransientBanner(Lang('Probing NetApp...'))
self.HandleCommonData(inputValues)
self.HandleNetAppData(inputValues)
except Exception as e:
pane.InputIndexSet(None)
Layout.Inst().PushDialogue(InfoDialogue(Lang("Operation Failed"), Lang(e)))
else:
handled = self.HandleInputFieldKeys(inKey)
return handled
def HandleKeyGATHER_HBA(self, inKey):
handled = True
pane = self.Pane()
if inKey == 'KEY_ENTER':
try:
# No input fields for HBA
Layout.Inst().TransientBanner(Lang('Probing for HBA Devices...'))
self.HandleHBAData({})
except Exception as e:
Layout.Inst().PushDialogue(InfoDialogue(Lang("Operation Failed"), Lang(e)))
else:
handled = False
return handled
def HandleKeyPROBE_HBA_NAME(self, inKey):
handled = True
pane = self.Pane()
if inKey == 'KEY_ENTER' and pane.IsLastInput():
try:
inputValues = pane.GetFieldValues()
self.srParams['name'] = inputValues['name']
self.srParams['description'] = inputValues['description']
self.extraInfo += [ # Array of tuples
(Lang('Name'), self.srParams['name']),
(Lang('Description'), self.srParams['description'])
]
if self.variant == 'ATTACH':
self.ChangeState('PROBE_HBA_SR')
else:
self.ChangeState('CONFIRM')
except Exception as e:
pane.InputIndexSet(None)
Layout.Inst().PushDialogue(InfoDialogue(Lang("Operation Failed"), Lang(e)))
else:
handled = self.HandleInputFieldKeys(inKey)
return handled
def HandleKeyGATHER_EQUAL(self, inKey):
handled = True
pane = self.Pane()
if inKey == 'KEY_ENTER' and pane.IsLastInput():
try:
inputValues = pane.GetFieldValues()
Layout.Inst().TransientBanner(Lang('Probing Dell EqualLogic Server...'))
self.HandleCommonData(inputValues)
self.HandleEqualData(inputValues)
except Exception as e:
pane.InputIndexSet(None)
Layout.Inst().PushDialogue(InfoDialogue(Lang("Operation Failed"), Lang(e)))
else:
handled = self.HandleInputFieldKeys(inKey)
return handled
def HandleKeyPROBE_NFS(self, inKey):
return self.srMenu.HandleKey(inKey)
def HandleKeyPROBE_ISCSI_IQN(self, inKey):
handled = False
if inKey == ' ':
try:
iqn = self.iqnChoices[self.iqnMenu.ChoiceIndex()]
message = Lang("Portal", 12)+iqn.portal+"\n"
message += Lang("TPGT", 12)+iqn.tpgt+"\n"
message += Lang("IQN", 12)+iqn.name
Layout.Inst().PushDialogue(InfoDialogue( Lang("IQN Information"), message))
except Exception as e:
Layout.Inst().PushDialogue(InfoDialogue( Lang("Failed: ")+Lang(e)))
handled = True
else:
handled =self.iqnMenu.HandleKey(inKey)
return handled
def HandleKeyPROBE_ISCSI_LUN(self, inKey):
return self.lunMenu.HandleKey(inKey)
def HandleKeyPROBE_ISCSI_SR(self, inKey):
return self.srMenu.HandleKey(inKey)
def HandleKeyPROBE_NETAPP_AGGREGATE(self, inKey):
return self.aggregateMenu.HandleKey(inKey)
def HandleKeyPROBE_NETAPP_FLEXVOLS(self, inKey):
handled = True
pane = self.Pane()
if inKey == 'KEY_ENTER' and pane.IsLastInput():
try:
numFlexVols = int(pane.GetFieldValues()['numflexvols'])
if numFlexVols < 1 or numFlexVols > 32:
raise Exception(Lang('The number of FlexVols must be between 1 and 32'))
self.srParams['numflexvols'] = numFlexVols
self.ChangeState('PROBE_NETAPP_PROVISIONING')
except Exception as e:
pane.InputIndexSet(None)
Layout.Inst().PushDialogue(InfoDialogue(Lang("Invalid Value"), Lang(e)))
else:
handled = self.HandleInputFieldKeys(inKey)
return handled
def HandleKeyPROBE_NETAPP_PROVISIONING(self, inKey):
return self.provisioningMenu.HandleKey(inKey)
def HandleKeyPROBE_NETAPP_SR(self, inKey):
return self.srMenu.HandleKey(inKey)
def HandleKeyPROBE_HBA_DEVICE(self, inKey):
return self.deviceMenu.HandleKey(inKey)
def HandleKeyPROBE_HBA_SR(self, inKey):
return self.srMenu.HandleKey(inKey)
def HandleKeyPROBE_EQUAL_STORAGEPOOL(self, inKey):
return self.storagePoolMenu.HandleKey(inKey)
def HandleKeyPROBE_EQUAL_SR(self, inKey):
return self.srMenu.HandleKey(inKey)
def HandleKeyCONFIRM(self, inKey):
handled = False
if inKey == 'KEY_F(8)':
try:
# Despatch method named 'Commit'+self.srCreateType+'_'+self.variant
getattr(self, 'Commit'+self.createType+'_'+self.variant)()
except Exception as e:
Layout.Inst().PopDialogue()
Layout.Inst().PushDialogue(InfoDialogue(Lang("Operation Failed"), Lang(e)))
handled = True
return handled
def HandleKey(self, inKey):
handled = False
if hasattr(self, 'HandleKey'+self.state):
handled = getattr(self, 'HandleKey'+self.state)(inKey)
if not handled and inKey in ('KEY_ESCAPE', 'KEY_LEFT'):
Layout.Inst().PopDialogue()
handled = True
return handled
def HandleCommonData(self, inParams):
if not inParams['name']:
raise Exception(Lang('Name field must be non empty'))
def HandleNFSData(self, inParams):
self.srParams = inParams
match = re.match(r'([^:]*):([^:]*)$', self.srParams['sharename'])
if not match:
raise Exception(Lang('Share name must contain a single colon, e.g. server:/path'))
self.srParams['server'] = IPUtils.AssertValidNetworkName(match.group(1))
self.srParams['serverpath'] = IPUtils.AssertValidNFSPathName(match.group(2))
self.extraInfo = [ # Array of tuples
(Lang('Name'), self.srParams['name']),
(Lang('Share Name'), self.srParams['sharename'])
]
if self.variant == 'CREATE' or self.createType == 'NFS_ISO':
self.ChangeState('CONFIRM')
elif self.variant == 'ATTACH':
xmlSRList = Task.Sync(lambda x: x.xenapi.SR.probe(
HotAccessor().local_host_ref().OpaqueRef(), # host
{ # device_config
'server':self.srParams['server'],
'serverpath':self.srParams['serverpath'],
},
self.srTypes['NFS'] # type
)
)
if xmlSRList == '':
self.srChoices = []
else:
# Parse XML for UUID values
xmlDoc = xml.dom.minidom.parseString(xmlSRList)
self.srChoices = [ str(node.firstChild.nodeValue.strip()) for node in xmlDoc.getElementsByTagName("UUID") ]
self.ChangeState('PROBE_NFS')
else:
raise Exception('Bad self.variant') # Logic error
def HandleCIFSData(self, inParams):
self.srParams = inParams
match = re.match(r'\\\\([^\\]*)\\([^\\]*)$', self.srParams['sharename'])
if not match:
raise Exception(Lang('Share name must be of the form \\\\server\\path'))
self.srParams['server'] = IPUtils.AssertValidNetworkName(match.group(1))
self.srParams['serverpath'] = IPUtils.AssertValidCIFSPathName(match.group(2))
self.extraInfo = [ # Array of tuples
(Lang('Name'), self.srParams['name']),
(Lang('Share Name'), self.srParams['sharename'])
]
self.ChangeState('CONFIRM')
def HandleISCSIData(self, inParams):
self.srParams = inParams
self.extraInfo = [ # Array of tuples
(Lang('Initiator IQN'), self.srParams['localiqn']),
(Lang('Port Number'), self.srParams['port']),
(Lang('Hostname of iSCSI Target'), self.srParams['remotehost']),
(Lang('Username'), self.srParams['username']),
(Lang('Password'), '*' * len(self.srParams['password']))
]
try:
# This task will raise an exception with details of available IQNs
Task.Sync(lambda x: x.xenapi.SR.probe(
HotAccessor().local_host_ref().OpaqueRef(), # host
{ # device_config
'target':self.srParams['remotehost'],
'port':self.srParams['port']
},
self.srTypes['ISCSI'] # type
)
)
except XenAPI.Failure as e:
if e.details[0] != 'SR_BACKEND_FAILURE_96':
raise
# Parse XML for UUID values
self.iqnChoices = []
if e.details[3] != '':
xmlDoc = xml.dom.minidom.parseString(e.details[3])
for tgt in xmlDoc.getElementsByTagName('TGT'):
try:
index = str(tgt.getElementsByTagName('Index')[0].firstChild.nodeValue.strip())
iqn = str(tgt.getElementsByTagName('TargetIQN')[0].firstChild.nodeValue.strip())
self.iqnChoices.append(Struct(
portal = self.srParams['remotehost']+':'+self.srParams['port'],
tpgt=index,
name=iqn,
iqn=iqn))
except Exception as e:
pass # Ignore failures
self.ChangeState('PROBE_ISCSI_IQN')
def NetAppBaseConfig(self):
retVal = {
'target':self.srParams['target'],
'username':self.srParams['username'],
'password':self.srParams['password']
}
if self.srParams['chapuser'] != '':
retVal.update({
'chapuser':self.srParams['chapuser'],
'chappassword':self.srParams['chappassword']
})
return retVal
def HandleNetAppData(self, inParams):
self.srParams = inParams
self.extraInfo = [ # Array of tuples
(Lang('NetApp Filer Address'), self.srParams['target']),
(Lang('Username'), self.srParams['username']),
(Lang('Password'), '*' * len(self.srParams['password'])),
(Lang('CHAP Username'), self.srParams['chapuser']),
(Lang('CHAP Password'), '*' * len(self.srParams['chappassword']))
]
if self.variant == 'CREATE':
# To create, we need the list of aggregates, which is obtained using a fake SR.create.
# This will fail because we're not supplying an aggregate name
try:
srRef = Task.Sync(lambda x: x.xenapi.SR.create(
HotAccessor().local_host_ref().OpaqueRef(), # host
self.NetAppBaseConfig(), # device_config
'0', # physical_size
self.srParams['name'], # name_label
self.srParams['description'], # name_description
self.srTypes['NETAPP'], # type
'user', # content_type
True # shared
)
)
except XenAPI.Failure as e:
if e.details[0] != 'SR_BACKEND_FAILURE_123':
raise
# Parse XML for UUID values
self.aggregateChoices = []
if e.details[3] != '':
xmlDoc = xml.dom.minidom.parseString(e.details[3])
for aggregate in xmlDoc.getElementsByTagName('Aggr'):
try:
name = str(aggregate.getElementsByTagName('Name')[0].firstChild.nodeValue.strip())
size = str(aggregate.getElementsByTagName('Size')[0].firstChild.nodeValue.strip())
disks = str(aggregate.getElementsByTagName('Disks')[0].firstChild.nodeValue.strip())
raidType = str(aggregate.getElementsByTagName('RAIDType')[0].firstChild.nodeValue.strip())
asisdedup = str(aggregate.getElementsByTagName('asis_dedup')[0].firstChild.nodeValue.strip())
self.aggregateChoices.append(Struct(
name = name,
size = size,
disks = disks,
raidType = raidType,
asisdedup = asisdedup)) # NetApp's Advanced Single Instance Storage Deduplication, 'true' if supported
except Exception as e:
pass # Ignore failures
self.ChangeState('PROBE_NETAPP_AGGREGATE')
elif self.variant=='ATTACH':
# This probe returns xml directly
xmlOutput = Task.Sync(lambda x: x.xenapi.SR.probe(
HotAccessor().local_host_ref().OpaqueRef(), # host
self.NetAppBaseConfig(), # device_config
self.srTypes['NETAPP'] # type
)
)
self.netAppSRChoices = []
xmlDoc = xml.dom.minidom.parseString(xmlOutput)
for xmlSR in xmlDoc.getElementsByTagName('SR'):
try:
uuid = str(xmlSR.getElementsByTagName('UUID')[0].firstChild.nodeValue.strip())
size = str(xmlSR.getElementsByTagName('Size')[0].firstChild.nodeValue.strip())
aggregate = str(xmlSR.getElementsByTagName('Aggregate')[0].firstChild.nodeValue.strip())
self.netAppSRChoices.append(Struct(
uuid = uuid,
size = size,
aggregate = aggregate
))
except Exception as e:
pass # Ignore failures
self.ChangeState('PROBE_NETAPP_SR')
else:
raise Exception('bad self.variant') # Logic error
def HandleHBAData(self, inParams):
self.extraInfo = []
# To create, we need the list of devices, which is obtained using SR.probe.
# This will fail because we're not supplying a device name
try:
srRef = Task.Sync(lambda x: x.xenapi.SR.probe(
HotAccessor().local_host_ref().OpaqueRef(), # host
{}, # device_config
self.srTypes['HBA'], # type
)
)
except XenAPI.Failure as e:
if e.details[0] != 'SR_BACKEND_FAILURE_107':
raise
# Parse XML for UUID values
self.deviceChoices = []
if e.details[3] != '':
xmlDoc = xml.dom.minidom.parseString(e.details[3])
for device in xmlDoc.getElementsByTagName('BlockDevice'):
try:
deviceInfo = Struct()
for name in ('path', 'SCSIid', 'vendor', 'serial', 'size', 'adapter', 'channel', 'id', 'lun', 'hba'):
setattr(deviceInfo, name.lower(), str(device.getElementsByTagName(name)[0].firstChild.nodeValue.strip()))
self.deviceChoices.append(deviceInfo)
except Exception as e:
pass # Ignore failures
self.ChangeState('PROBE_HBA_DEVICE')
def EqualBaseConfig(self):
retVal = {
'target':self.srParams['target'],
'username':self.srParams['username'],
'password':self.srParams['password']
}
if self.srParams['chapuser'] != '':
retVal.update({
'chapuser':self.srParams['chapuser'],
'chappassword':self.srParams['chappassword']
})
return retVal
def HandleEqualData(self, inParams):
self.srParams = inParams
self.extraInfo = [ # Array of tuples
(Lang('Filer Address'), self.srParams['target']),
(Lang('Username'), self.srParams['username']),
(Lang('Password'), '*' * len(self.srParams['password'])),
(Lang('CHAP Username'), self.srParams['chapuser']),
(Lang('CHAP Password'), '*' * len(self.srParams['chappassword']))
]
if self.variant == 'CREATE':
# To create, we need the list of aggregates, which is obtained using a fake SR.create.
# This will fail because we're not supplying an aggregate name
try:
srRef = Task.Sync(lambda x: x.xenapi.SR.create(
HotAccessor().local_host_ref().OpaqueRef(), # host
self.NetAppBaseConfig(), # device_config
'0', # physical_size
self.srParams['name'], # name_label
self.srParams['description'], # name_description
self.srTypes['EQUAL'], # type
'user', # content_type
True # shared
)
)
except XenAPI.Failure as e:
if e.details[0] != 'SR_BACKEND_FAILURE_163':