-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathscreens.py
More file actions
1191 lines (975 loc) · 44.9 KB
/
Copy pathscreens.py
File metadata and controls
1191 lines (975 loc) · 44.9 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
# SPDX-License-Identifier: GPL-2.0-only
import string
import datetime
import os.path
import time
import generalui
from uicontroller import SKIP_SCREEN, EXIT, LEFT_BACKWARDS, RIGHT_FORWARDS, REPEAT_STEP
import constants
import diskutil
from disktools import *
from version import *
from xcp import logger
import snackutil
import util
import socket
import product
import upgrade
import netutil
from snack import *
import tui
import tui.network
import tui.progress
import driver
import tui.fcoe
MY_PRODUCT_BRAND = PRODUCT_BRAND or PLATFORM_NAME
def selectDefault(key, entries):
""" Given a list of (text, key) and a key to select, returns the appropriate
text,key pair, or None if not in entries. """
for text, k in entries:
if key == k:
return text, k
return None
# welcome screen:
def welcome_screen(answers):
driver_answers = {'driver-repos': []}
tui.update_help_line([None, "<F9> load driver"])
def load_driver(driver_answers):
tui.screen.popHelpLine()
tui.update_help_line([None, ' '])
drivers = driver.doInteractiveLoadDriver(tui, driver_answers)
logger.log(drivers)
logger.log(driver_answers)
if drivers[0]:
if 'extra-repos' not in answers: answers['extra-repos'] = []
answers['extra-repos'].append(drivers)
return True
global loop
global popup
loop = True
def fn9():
global loop
global popup
loop = True
popup = 'driver'
return False
def fn10():
global loop
global popup
loop = True
popup = 'storage'
return False
while loop:
loop = False
popup = None
driver_answers['network-hardware'] = answers['network-hardware'] = netutil.scanConfiguration()
button = snackutil.ButtonChoiceWindowEx(tui.screen,
"Welcome to %s Setup" % MY_PRODUCT_BRAND,
"""This setup tool can be used to install or upgrade %s on your system or restore your server from backup. Installing %s will erase all data on the disks selected for use.
Please make sure you have backed up any data you wish to preserve before proceeding.
To load a device driver press <F9>.
To setup advanced storage classes press <F10>.
""" % (MY_PRODUCT_BRAND, MY_PRODUCT_BRAND),
['Ok', 'Reboot'], width=60, help="welcome",
hotkeys={'F9': fn9, 'F10': fn10})
if popup == 'driver':
load_driver(driver_answers)
tui.update_help_line([None, "<F9> load driver"])
elif popup == 'storage':
tui.fcoe.select_fcoe_ifaces(answers)
tui.update_help_line([None, "<F9> load driver"])
tui.screen.popHelpLine()
if button == 'reboot':
return EXIT
logger.log("Waiting for partitions to appear...")
util.runCmd2(util.udevsettleCmd())
time.sleep(1)
diskutil.mpath_part_scan()
# ensure partitions/disks are not locked by LVM
lvm = LVMTool()
lvm.deactivateAll()
del lvm
tui.progress.showMessageDialog("Please wait", "Checking for existing products...")
answers['installed-products'] = product.find_installed_products()
answers['upgradeable-products'] = upgrade.filter_for_upgradeable_products(answers['installed-products'])
answers['backups'] = product.findXenSourceBackups()
tui.progress.clearModelessDialog()
diskutil.log_available_disks()
# CA-41142, ensure we have at least one network interface and one disk before proceeding
label = None
if len(diskutil.getDiskList()) == 0:
label = "No Disks"
text = "hard disks"
text_short = "disks"
if len(answers['network-hardware'].keys()) == 0:
label = "No Network Interfaces"
text = "network interfaces"
text_short = "interfaces"
if label:
text = """This host does not appear to have any %s.
If %s are present you may need to load a device driver on the previous screen for them to be detected.""" % (text, text_short)
ButtonChoiceWindow(tui.screen, label, text, ["Back"], width=48)
return REPEAT_STEP
return RIGHT_FORWARDS
def hardware_warnings(answers, ram_warning, vt_warning):
vt_not_found_text = "Hardware virtualization assist support is not available on this system. Either it is not present, or is disabled in the system's BIOS. This capability is required to start Windows virtual machines."
not_enough_ram_text = "%s requires %dMB of system memory in order to function normally. Your system appears to have less than this, which may cause problems during startup." % (MY_PRODUCT_BRAND, constants.MIN_SYSTEM_RAM_MB_RAW)
text = "The following problem(s) were found with your hardware:\n\n"
if vt_warning:
text += vt_not_found_text + "\n\n"
if ram_warning:
text += not_enough_ram_text + "\n\n"
text += "You may continue with the installation, though %s might have limited functionality until you have addressed these problems." % MY_PRODUCT_BRAND
button = ButtonChoiceWindow(
tui.screen,
"System Hardware",
text,
['Ok', 'Back'],
width=60, help="hwwarn"
)
if button == 'back': return LEFT_BACKWARDS
return RIGHT_FORWARDS
def overwrite_warning(answers):
warning_string = "Continuing will result in a clean installation, all existing configuration will be lost."
warning_string += "\n\nAlternatively, please contact a Technical Support Representative for the recommended upgrade path."
button = snackutil.ButtonChoiceWindowEx(
tui.screen,
"Warning",
("Only product installations that cannot be upgraded have been detected.\n\n%s" % warning_string),
['Ok', 'Back'],
width=60, help="overwrtwarn", default=1,
)
if button == 'back': return LEFT_BACKWARDS
return RIGHT_FORWARDS
def get_admin_interface(answers):
default = None
try:
if 'net-admin-interface' in answers:
default = answers['net-admin-interface']
except:
pass
net_hw = answers['network-hardware']
direction, iface = tui.network.select_netif("Which network interface would you like to use for connecting to the management server on your host?",
net_hw, False, default)
if direction == RIGHT_FORWARDS:
answers['net-admin-interface'] = iface
return direction
def get_admin_interface_configuration(answers):
if 'net-admin-interface' not in answers:
answers['net-admin-interface'] = answers['network-hardware'].keys()[0]
nic = answers['network-hardware'][answers['net-admin-interface']]
defaults = None
try:
if 'net-admin-configuration' in answers:
defaults = answers['net-admin-configuration']
elif 'runtime-iface-configuration' in answers:
all_dhcp, manual_config = answers['runtime-iface-configuration']
if not all_dhcp:
defaults = manual_config[answers['net-admin-interface']]
except:
pass
rc, conf = tui.network.get_iface_configuration(
nic, txt="Please specify how networking should be configured for the management interface on this host.",
defaults=defaults
)
if rc == RIGHT_FORWARDS:
answers['net-admin-configuration'] = conf
return rc
def get_installation_type(answers):
entries = []
for x in answers['upgradeable-products']:
entries.append(("Upgrade %s" % str(x), (x, x.settingsAvailable())))
for b in answers['backups']:
entries.append(("Restore %s from backup" % str(b), (b, None)))
entries.append( ("Perform clean installation", None) )
# default value?
if 'install-type' in answers and answers['install-type'] == constants.INSTALL_TYPE_REINSTALL:
default = selectDefault(answers['installation-to-overwrite'], entries)
elif 'install-type' in answers and answers['install-type'] == constants.INSTALL_TYPE_RESTORE:
default = selectDefault(answers['backup-to-restore'], entries)
else:
default = None
if len(answers['upgradeable-products']) > 0:
text = "One or more existing product installations that can be upgraded have been detected."
if len(answers['backups']) > 0:
text += " In addition one or more backups have been detected."
else:
text = "One or more backups have been detected."
text += "\n\nWhat would you like to do?"
tui.update_help_line([None, "<F5> more info"])
def more_info(context):
if not context: return True
obj, _ = context
if isinstance(obj, product.ExistingInstallation):
use = "%s installation" % obj.visual_brand
elif isinstance(obj, product.XenServerBackup):
use = "%s backup" % obj.visual_brand
else:
return True
date = "Unknown"
if 'INSTALLATION_DATE' in obj.inventory:
date = obj.inventory['INSTALLATION_DATE']
dev = "Unknown"
if 'PRIMARY_DISK' in obj.inventory:
pd = obj.inventory['PRIMARY_DISK']
if pd == "ToBeDetermined":
dev = diskutil.getHumanDiskName(obj.primary_disk)
else:
dev = "%s (%s)" % (diskutil.getHumanDiskName(os.path.realpath(pd)),
diskutil.getHumanDiskName(pd))
tui.update_help_line([' ', ' '])
args = ([("Use:", use),
("Version:", str(obj.visual_version))] +
([("Build:", str(obj.build))] if obj.build is not None else []) +
[("Installed:", date),
("Disk:", dev)])
snackutil.TableDialog(tui.screen, "Details", *args)
tui.screen.popHelpLine()
return True
(button, entry) = snackutil.ListboxChoiceWindowEx(
tui.screen,
"Action To Perform",
text,
entries,
['Ok', 'Back'], width=60, default=default, help='action:info',
hotkeys={'F5': more_info})
tui.screen.popHelpLine()
if button == 'back':
return LEFT_BACKWARDS
if entry is None:
answers['install-type'] = constants.INSTALL_TYPE_FRESH
answers['preserve-settings'] = False
if 'installation-to-overwrite' in answers:
del answers['installation-to-overwrite']
elif isinstance(entry[0], product.ExistingInstallation):
answers['install-type'] = constants.INSTALL_TYPE_REINSTALL
answers['installation-to-overwrite'], preservable = entry
answers['preserve-settings'] = preservable
if 'primary-disk' not in answers:
answers['primary-disk'] = answers['installation-to-overwrite'].primary_disk
for k in ['guest-disks', 'default-sr-uuid']:
if k in answers:
del answers[k]
elif isinstance(entry[0], product.XenServerBackup):
answers['install-type'] = constants.INSTALL_TYPE_RESTORE
answers['backup-to-restore'], _ = entry
return RIGHT_FORWARDS
def ha_master_upgrade(answers):
button = ButtonChoiceWindow(
tui.screen,
"High Availability Enabled",
"""High Availability must be disabled before upgrade.
Please reboot this host, disable High Availability on the pool, check which server is the pool master and then restart the upgrade procedure.""",
['Cancel', 'Back'],
width=60, help='hawarn'
)
if button == 'back': return LEFT_BACKWARDS
return EXIT
def master_not_upgraded(answers):
button = ButtonChoiceWindow(
tui.screen,
"Pool Master Version",
"The master host of this pool must be upgraded before this slave.",
['Cancel', 'Back'],
width=60, help='masterwarn'
)
if button == 'back': return LEFT_BACKWARDS
return EXIT
def upgrade_settings_warning(answers):
button = ButtonChoiceWindow(
tui.screen,
"Preserve Settings",
"""The configuration of %s cannot be automatically retained. You must re-enter the configuration manually.
Warning: You must use the current values. Failure to do so may result in an incorrect installation of the product.""" % str(answers['installation-to-overwrite']),
['Ok', 'Back'],
width=60, help='preswarn'
)
if button == 'back': return LEFT_BACKWARDS
return RIGHT_FORWARDS
def remind_driver_repos(answers):
driver_list = []
settings = answers['installation-to-overwrite'].readSettings()
for repo in settings['repo-list']:
pkid, name, is_supp = repo
if is_supp and name not in driver_list and \
pkid not in constants.INTERNAL_REPOS:
driver_list.append(name)
if len(driver_list) == 0:
return SKIP_SCREEN
text = ''
for driver in driver_list:
text += " * %s\n" % driver
button = ButtonChoiceWindow(
tui.screen,
"Installed Supplemental Packs",
"""The following Supplemental Packs are present in the current installation:
%s
Please ensure that the functionality they provide is either included in the version of %s being installed or by a Supplemental Pack for this release.""" % (text, MY_PRODUCT_BRAND),
['Ok', 'Back'],
width=60, help="suppackremind"
)
if button == 'back': return LEFT_BACKWARDS
return RIGHT_FORWARDS
def repartition_existing(answers):
button = ButtonChoiceWindow(
tui.screen,
"Convert Existing Installation",
"""The installer needs to change the disk layout of your existing installation.
The conversion will replace all previous system image partitions to create the %s disk partition layout.
Continue with installation?""" % (MY_PRODUCT_BRAND,),
['Continue', 'Back'], help='repartwarn'
)
if button == 'back': return LEFT_BACKWARDS
answers['backup-existing-installation'] = True
return RIGHT_FORWARDS
def force_backup_screen(answers):
text = "The installer needs to create a backup of your existing installation. This will erase all data currently on the backup partition (including previous backups)."
button = ButtonChoiceWindow(
tui.screen,
"Previous Installation Detected",
text,
['Continue', 'Back'], width=60, help='forceback'
)
if button == 'back': return LEFT_BACKWARDS
answers['backup-existing-installation'] = True
return RIGHT_FORWARDS
def backup_existing_installation(answers):
# default selection:
if 'backup-existing-installation' in answers:
if answers['backup-existing-installation']:
default = 0
else:
default = 1
else:
default = 0
button = snackutil.ButtonChoiceWindowEx(
tui.screen,
"Back-up Existing Installation?",
"""Would you like to back-up your existing installation before re-installing %s?
The backup will be placed on the backup partition of the destination disk (%s), overwriting any previous backups on that volume.""" % (MY_PRODUCT_BRAND, answers['installation-to-overwrite'].primary_disk),
['Yes', 'No', 'Back'], default=default, help='optbackup'
)
if button == 'back': return LEFT_BACKWARDS
answers['backup-existing-installation'] = (button == 'yes')
return RIGHT_FORWARDS
def eula_screen(answers):
eula_file = open(constants.EULA_PATH, 'r')
eula = string.join(eula_file.readlines())
eula_file.close()
while True:
button = snackutil.ButtonChoiceWindowEx(
tui.screen,
"End User License Agreement",
eula,
['Accept EULA', 'Back'], width=60, default=1, help='eula')
if button == 'accept eula':
return RIGHT_FORWARDS
elif button == 'back':
return LEFT_BACKWARDS
else:
ButtonChoiceWindow(
tui.screen,
"End User License Agreement",
"You must select 'Accept EULA' (by highlighting it with the cursor keys, then pressing either Space or Enter) in order to install this product.",
['Ok'])
def confirm_erase_volume_groups(answers):
problems = diskutil.findProblematicVGs(answers['guest-disks'])
if len(problems) == 0:
return SKIP_SCREEN
if len(problems) == 1:
logger.log("Problematic VGs: %s" % problems)
affected = "The volume group affected is %s. Are you sure you wish to continue?" % problems[0]
elif len(problems) > 1:
affected = "The volume groups affected are %s. Are you sure you wish to continue?" % generalui.makeHumanList(problems)
button = ButtonChoiceWindow(tui.screen,
"Conflicting LVM Volume Groups",
"""Some or all of the disks you selected to install %s onto contain parts of LVM volume groups. Proceeding with the installation will cause these volume groups to be deleted.
%s""" % (MY_PRODUCT_BRAND, affected),
['Continue', 'Back'], width=60, help='erasevg')
if button == 'back': return LEFT_BACKWARDS
return RIGHT_FORWARDS
def use_extra_media(answers):
rc = snackutil.ButtonChoiceWindowEx(
tui.screen,
"Supplemental Packs",
"Would you like to install any Supplemental Packs?",
['Yes', 'No'],
default=1, help='suppack'
)
answers['more-media'] = (rc != 'no')
return RIGHT_FORWARDS
def setup_runtime_networking(answers):
defaults = None
try:
if 'net-admin-interface' in answers:
defaults = {'net-admin-interface': answers['net-admin-interface']}
if 'runtime-iface-configuration' in answers and \
answers['net-admin-interface'] in answers['runtime-iface-configuration'][1]:
defaults['net-admin-configuration'] = answers['runtime-iface-configuration'][1][answers['net-admin-interface']]
elif 'installation-to-overwrite' in answers:
defaults = answers['installation-to-overwrite'].readSettings()
except:
pass
# Get the answers from the user
return tui.network.requireNetworking(answers, defaults)
def disk_more_info(context):
if not context: return True
usage = 'unknown'
(boot, root, state, storage, logs) = diskutil.probeDisk(context)
if root[0]:
usage = "%s installation" % MY_PRODUCT_BRAND
elif storage[0]:
usage = 'VM storage'
else:
# Determine disk is being used as an LVM SR with no partitioning
rv, out = util.runCmd2([ 'pvs', context, '-o', 'vg_name', '--noheadings' ], with_stdout=True)
if rv == 0:
vg_name = out.strip()
if vg_name.startswith('VG_XenStorage-'):
usage = 'VM Storage'
tui.update_help_line([' ', ' '])
snackutil.TableDialog(tui.screen, "Details", ("Disk:", diskutil.getHumanDiskName(context)),
("Vendor:", diskutil.getDiskDeviceVendor(context)),
("Model:", diskutil.getDiskDeviceModel(context)),
("Serial:", diskutil.getDiskSerialNumber(context)),
("Size:", diskutil.getHumanDiskSize(diskutil.getDiskDeviceSize(context))),
("Current usage:", usage))
tui.screen.popHelpLine()
return True
def sorted_disk_list():
return sorted(diskutil.getQualifiedDiskList(),
lambda x, y: len(x) == len(y) and cmp(x,y) or (len(x)-len(y)))
# select drive to use as the Dom0 disk:
def select_primary_disk(answers):
button = None
diskEntries = sorted_disk_list()
entries = []
target_is_sr = {}
min_primary_disk_size = constants.min_primary_disk_size
for de in diskEntries:
(vendor, model, size) = diskutil.getExtendedDiskInfo(de)
if diskutil.blockSizeToGBSize(size) < min_primary_disk_size:
logger.log("disk %s is too small: %s < %s GB" %
(de, diskutil.blockSizeToGBSize(size), min_primary_disk_size))
continue
# determine current usage
target_is_sr[de] = False
(boot, root, state, storage, logs) = diskutil.probeDisk(de)
if storage[0]:
target_is_sr[de] = True
(vendor, model, size) = diskutil.getExtendedDiskInfo(de)
stringEntry = "%s - %s [%s %s]" % (diskutil.getHumanDiskName(de), diskutil.getHumanDiskSize(size), vendor, model)
e = (stringEntry, de)
entries.append(e)
# we should have at least one disk
if len(entries) == 0:
ButtonChoiceWindow(tui.screen,
"No Primary Disk",
"No disk with sufficient space to install %s on was found." % MY_PRODUCT_BRAND,
['Cancel'])
return EXIT
# if only one disk, set default:
if len(entries) == 1:
answers['primary-disk'] = entries[0][1]
else:
# default value:
default = None
if 'primary-disk' in answers:
default = selectDefault(answers['primary-disk'], entries)
tui.update_help_line([None, "<F5> more info"])
scroll, height = snackutil.scrollHeight(4, len(entries))
(button, entry) = snackutil.ListboxChoiceWindowEx(
tui.screen,
"Select Primary Disk",
"""Please select the disk you would like to install %s on (disks with insufficient space are not shown).
You may need to change your system settings to boot from this disk.""" % (MY_PRODUCT_BRAND),
entries,
['Ok', 'Back'], 55, scroll, height, default, help='pridisk:info',
hotkeys={'F5': disk_more_info})
tui.screen.popHelpLine()
# entry contains the 'de' part of the tuple passed in
answers['primary-disk'] = entry
if 'installation-to-overwrite' in answers:
answers['target-is-sr'] = target_is_sr[answers['primary-disk']]
if button == 'back': return LEFT_BACKWARDS
# Warn the user if a utility partition is detected. Give them option to
# cancel the install.
tool = PartitionTool(answers['primary-disk'])
if tool.partTableType != constants.PARTITION_GPT:
if constants.GPT_SUPPORT and tool.utilityPartitions():
val = snackutil.ButtonChoiceWindowEx(tui.screen,
"Preexisting utility partition detected on dos partition.",
"this will be overwritten do you wish to continue?",
['Yes', 'No'], default=1)
if val == 'no':
return EXIT
else:
answers["preserve-first-partition"] = 'false'
if button is None: return SKIP_SCREEN
return RIGHT_FORWARDS
def check_sr_space(answers):
tool = LVMTool()
sr = tool.srPartition(answers['primary-disk'])
assert sr
# NB. there's some stuff here that's not really consistent with XCP
# but that's ok, since it's never called on an XCP host
root_size = constants.root_size
button = ButtonChoiceWindow(tui.screen,
"Insufficient Space",
"""The disk selected contains a storage repository which does not have enough space to also install %s on.
Either return to the previous screen and select a different disk or cancel the installation, restart the %s and use %s to free up %dMB of space in the local storage repository.""" % (MY_PRODUCT_BRAND, BRAND_SERVER, BRAND_CONSOLE, 2 * root_size),
['Back', 'Cancel'], width=60, help='insuffsr')
if button == 'back': return LEFT_BACKWARDS
return EXIT
def select_guest_disks(answers):
diskEntries = sorted_disk_list()
# CA-38329: filter out device mapper nodes (except primary disk) as these won't exist
# at XenServer boot and therefore cannot be added as physical volumes to Local SR.
# Also, since the DM nodes are multipathed SANs it doesn't make sense to include them
# in the "Local" SR.
allowed_in_local_sr = lambda dev: (dev == answers['primary-disk']) or (not isDeviceMapperNode(dev))
diskEntries = filter(allowed_in_local_sr, diskEntries)
if len(diskEntries) == 0 or constants.CC_PREPARATIONS:
answers['guest-disks'] = []
return SKIP_SCREEN
# set up defaults:
if 'guest-disks' in answers:
currently_selected = answers['guest-disks']
else:
currently_selected = answers['primary-disk']
srtype = constants.SR_TYPE_LVM
if 'sr-type' in answers:
srtype = answers['sr-type']
# Make a list of entries: (text, item)
entries = []
for de in diskEntries:
(vendor, model, size) = diskutil.getExtendedDiskInfo(de)
entry = "%s - %s [%s %s]" % (diskutil.getHumanDiskName(de), diskutil.getHumanDiskSize(size), vendor, model)
entries.append((entry, de))
text = TextboxReflowed(54, "Which disks would you like to use for %s storage? \n\nOne storage repository will be created that spans the selected disks. You can choose not to prepare any storage if you wish to create an advanced configuration after installation." % BRAND_GUEST)
buttons = ButtonBar(tui.screen, [('Ok', 'ok'), ('Back', 'back')])
scroll, _ = snackutil.scrollHeight(3, len(entries))
cbt = CheckboxTree(3, scroll)
for (c_text, c_item) in entries:
cbt.append(c_text, c_item, c_item in currently_selected)
txt = "Enable thin provisioning"
if len(BRAND_VDI) > 0:
txt += " (Optimized storage for %s)" % BRAND_VDI
tb = Checkbox(txt, srtype == constants.SR_TYPE_EXT and 1 or 0)
gf = GridFormHelp(tui.screen, 'Virtual Machine Storage', 'guestdisk:info', 1, 4)
gf.add(text, 0, 0, padding=(0, 0, 0, 1))
gf.add(cbt, 0, 1, padding=(0, 0, 0, 1))
gf.add(tb, 0, 2, padding=(0, 0, 0, 1))
gf.add(buttons, 0, 3, growx=1)
gf.addHotKey('F5')
tui.update_help_line([None, "<F5> more info"])
loop = True
while loop:
rc = gf.run()
if rc == 'F5':
disk_more_info(cbt.getCurrent())
else:
loop = False
tui.screen.popWindow()
tui.screen.popHelpLine()
button = buttons.buttonPressed(rc)
if button == 'back': return LEFT_BACKWARDS
answers['guest-disks'] = cbt.getSelection()
answers['sr-type'] = tb.selected() and constants.SR_TYPE_EXT or constants.SR_TYPE_LVM
answers['sr-on-primary'] = answers['primary-disk'] in answers['guest-disks']
# if the user select no disks for guest storage, check this is what
# they wanted:
if answers['guest-disks'] == []:
button = ButtonChoiceWindow(
tui.screen,
"Warning",
"""You didn't select any disks for %s storage. Are you sure this is what you want?
If you proceed, please refer to the user guide for details on provisioning storage after installation.""" % BRAND_GUEST,
['Continue', 'Back'], help='noguest'
)
if button == 'back': return REPEAT_STEP
return RIGHT_FORWARDS
def confirm_installation(answers):
if answers['install-type'] == constants.INSTALL_TYPE_RESTORE:
backup = answers['backup-to-restore']
label = "Confirm Restore"
text = "Are you sure you want to restore your installation with the backup on %s?\n\nYour existing installation will be overwritten with the backup (though VMs will still be intact).\n\nTHIS OPERATION CANNOT BE UNDONE." % diskutil.getHumanDiskName(backup.partition)
ok = 'Restore %s' % backup
else:
label = "Confirm Installation"
text1 = "We have collected all the information required to install %s. " % MY_PRODUCT_BRAND
if answers['install-type'] == constants.INSTALL_TYPE_FRESH:
disks = map(diskutil.getHumanDiskName, answers['guest-disks'])
if diskutil.getHumanDiskName(answers['primary-disk']) not in disks:
disks.append(diskutil.getHumanDiskName(answers['primary-disk']))
disks.sort()
if len(disks) == 1:
term = 'disk'
else:
term = 'disks'
disks_used = generalui.makeHumanList(disks)
text2 = "Please confirm you wish to proceed: all data on %s %s will be destroyed!" % (term, disks_used)
elif answers['install-type'] == constants.INSTALL_TYPE_REINSTALL:
if answers['primary-disk'] == answers['installation-to-overwrite'].primary_disk:
text2 = "The installation will be performed over %s" % str(answers['installation-to-overwrite'])
else:
text2 = "Setup will migrate the %s installation from %s to %s" % (str(answers['installation-to-overwrite']),
diskutil.getHumanDiskName(answers['installation-to-overwrite'].primary_disk),
diskutil.getHumanDiskName(answers['primary-disk']))
text2 += ", preserving existing %s in your storage repository." % BRAND_GUESTS
text = text1 + "\n\n" + text2
ok = 'Install %s' % MY_PRODUCT_BRAND
button = snackutil.ButtonChoiceWindowEx(
tui.screen, label, text,
[ok, 'Back'], default=1, width=50, help='confirm'
)
if button is None or button == 'back': return LEFT_BACKWARDS
return RIGHT_FORWARDS
def get_root_password(answers):
done = False
password_txt = "Please specify a password of at least %d characters for the root account." % (constants.MIN_PASSWD_LEN)
if PRODUCT_BRAND:
password_txt = "Please specify a password of at least %d characters for the root account. \n\n(This is the password used when connecting to the %s from %s.)" % (constants.MIN_PASSWD_LEN, BRAND_SERVER, BRAND_CONSOLE)
while not done:
(button, result) = snackutil.PasswordEntryWindow(
tui.screen, "Set Password", password_txt,
['Password', 'Confirm'], buttons=['Ok', 'Back'],
)
if button == 'back': return LEFT_BACKWARDS
(pw, conf) = result
if pw == conf:
if pw is None or len(pw) < constants.MIN_PASSWD_LEN:
ButtonChoiceWindow(tui.screen,
"Password Error",
"The password has to be %d characters or longer." % constants.MIN_PASSWD_LEN,
['Ok'], help='passwd')
else:
done = True
else:
ButtonChoiceWindow(tui.screen,
"Password Error",
"The passwords you entered did not match. Please try again.",
['Ok'])
# if they didn't select OK we should have returned already
assert button in ['ok', None]
answers['root-password'] = ('plaintext', pw)
return RIGHT_FORWARDS
def get_name_service_configuration(answers):
# horrible hack - need a tuple due to bug in snack that means
# we don't get an arge passed if we try to just pass False
def hn_callback((enabled, )):
hostname.setFlags(FLAG_DISABLED, enabled)
def ns_callback((enabled, )):
for entry in [ns1_entry, ns2_entry, ns3_entry]:
entry.setFlags(FLAG_DISABLED, enabled)
hide_rb = not answers['net-admin-configuration'].isDynamic()
# HOSTNAME:
hn_title = Textbox(len("Hostname Configuration"), 1, "Hostname Configuration")
# the hostname radio group:
if 'manual-hostname' not in answers:
# no current value set - if we currently have a useful hostname,
# use that, else make up a random one:
current_hn = socket.gethostname()
if current_hn in [None, '', '(none)', 'localhost', 'localhost.localdomain']:
answers['manual-hostname'] = True, util.mkRandomHostname()
else:
answers['manual-hostname'] = True, current_hn
use_manual_hostname, manual_hostname = answers['manual-hostname']
if manual_hostname is None:
manual_hostname = ""
hn_rbgroup = RadioGroup()
hn_dhcp_rb = hn_rbgroup.add("Automatically set via DHCP", "hn_dhcp", not use_manual_hostname)
hn_dhcp_rb.setCallback(hn_callback, data=(False,))
hn_manual_rb = hn_rbgroup.add("Manually specify:", "hn_manual", use_manual_hostname)
hn_manual_rb.setCallback(hn_callback, data=(True,))
# the hostname text box:
hostname = Entry(hide_rb and 30 or 42, text=manual_hostname)
hostname.setFlags(FLAG_DISABLED, use_manual_hostname)
hostname_grid = Grid(2, 1)
if hide_rb:
hostname_grid.setField(Textbox(15, 1, "Hostname:"), 0, 0)
else:
hostname_grid.setField(Textbox(4, 1, ""), 0, 0) # spacer
hostname_grid.setField(hostname, 1, 0)
# NAMESERVERS:
def nsvalue(answers, id):
nameservers = None
if 'manual-nameservers' in answers:
manual, nsl = answers['manual-nameservers']
if manual:
nameservers = nsl
elif 'runtime-iface-configuration' in answers:
all_dhcp, netdict = answers['runtime-iface-configuration']
if not all_dhcp and isinstance(netdict, dict):
nameservers = netdict.values()[0].dns
if isinstance(nameservers, list) and id < len(nameservers):
return nameservers[id]
return ""
ns_title = Textbox(len("DNS Configuration"), 1, "DNS Configuration")
use_manual_dns = nsvalue(answers, 0) != ""
if hide_rb:
use_manual_dns = True
# Name server radio group
ns_rbgroup = RadioGroup()
ns_dhcp_rb = ns_rbgroup.add("Automatically set via DHCP", "ns_dhcp",
not use_manual_dns)
ns_dhcp_rb.setCallback(ns_callback, (False,))
ns_manual_rb = ns_rbgroup.add("Manually specify:", "ns_dhcp",
use_manual_dns)
ns_manual_rb.setCallback(ns_callback, (True,))
# Name server text boxes
ns1_text = Textbox(15, 1, "DNS Server 1:")
ns1_entry = Entry(30, nsvalue(answers, 0))
ns1_grid = Grid(2, 1)
ns1_grid.setField(ns1_text, 0, 0)
ns1_grid.setField(ns1_entry, 1, 0)
ns2_text = Textbox(15, 1, "DNS Server 2:")
ns2_entry = Entry(30, nsvalue(answers, 1))
ns2_grid = Grid(2, 1)
ns2_grid.setField(ns2_text, 0, 0)
ns2_grid.setField(ns2_entry, 1, 0)
ns3_text = Textbox(15, 1, "DNS Server 3:")
ns3_entry = Entry(30, nsvalue(answers, 2))
ns3_grid = Grid(2, 1)
ns3_grid.setField(ns3_text, 0, 0)
ns3_grid.setField(ns3_entry, 1, 0)
if nsvalue(answers, 0) == "":
for entry in [ns1_entry, ns2_entry, ns3_entry]:
entry.setFlags(FLAG_DISABLED, use_manual_dns)
done = False
while not done:
buttons = ButtonBar(tui.screen, [('Ok', 'ok'), ('Back', 'back')])
# The form itself:
i = 1
gf = GridFormHelp(tui.screen, 'Hostname and DNS Configuration', 'dns', 1, 11)
gf.add(hn_title, 0, 0, padding=(0, 0, 0, 0))
if not hide_rb:
gf.add(hn_dhcp_rb, 0, 1, anchorLeft=True)
gf.add(hn_manual_rb, 0, 2, anchorLeft=True)
i += 2
gf.add(hostname_grid, 0, i, padding=(0, 0, 0, 1), anchorLeft=True)
gf.add(ns_title, 0, i+1, padding=(0, 0, 0, 0))
if not hide_rb:
gf.add(ns_dhcp_rb, 0, 5, anchorLeft=True)
gf.add(ns_manual_rb, 0, 6, anchorLeft=True)
i += 2
gf.add(ns1_grid, 0, i+2)
gf.add(ns2_grid, 0, i+3)
gf.add(ns3_grid, 0, i+4, padding=(0, 0, 0, 1))
gf.add(buttons, 0, 10, growx=1)
button = buttons.buttonPressed(gf.runOnce())
if button == 'back': return LEFT_BACKWARDS
# manual hostname?
if hn_manual_rb.selected():
answers['manual-hostname'] = (True, hostname.value())
else:
answers['manual-hostname'] = (False, None)
# manual nameservers?
if ns_manual_rb.selected():
answers['manual-nameservers'] = (True, [ns1_entry.value()])
if ns2_entry.value() != '':
answers['manual-nameservers'][1].append(ns2_entry.value())
if ns3_entry.value() != '':
answers['manual-nameservers'][1].append(ns3_entry.value())
if 'net-admin-configuration' in answers and not answers['net-admin-configuration'].isDynamic():
answers['net-admin-configuration'].dns = answers['manual-nameservers'][1]
else:
answers['manual-nameservers'] = (False, None)
# validate before allowing the user to continue:
done = True
if hn_manual_rb.selected():
if not netutil.valid_hostname(hostname.value(), fqdn=True):
done = False
ButtonChoiceWindow(tui.screen,
"Name Service Configuration",
"The hostname you entered was not valid.",
["Back"])
continue
if ns_manual_rb.selected():
if not netutil.valid_ip_addr(ns1_entry.value()) or \
(ns2_entry.value() != '' and not netutil.valid_ip_addr(ns2_entry.value())) or \
(ns3_entry.value() != '' and not netutil.valid_ip_addr(ns3_entry.value())):
done = False
ButtonChoiceWindow(tui.screen,
"Name Service Configuration",
"Please check that you have entered at least one nameserver, and that the nameservers you specified are valid.",
["Back"])
return RIGHT_FORWARDS
def get_timezone_region(answers):
entries = generalui.getTimeZoneRegions()
# default value?
default = None
if 'timezone-region' in answers:
default = answers['timezone-region']
(button, entry) = ListboxChoiceWindow(
tui.screen,
"Select Time Zone",
"Please select the geographical area that your %s is in:" % BRAND_SERVER,
entries, ['Ok', 'Back'], height=8, scroll=1,
default=default)
if button == 'back': return LEFT_BACKWARDS
answers['timezone-region'] = entries[entry]
return RIGHT_FORWARDS
def get_timezone_city(answers):
entries = generalui.getTimeZoneCities(answers['timezone-region'])
# default value?
default = None
if 'timezone-city' in answers and answers['timezone-city'] in entries:
default = answers['timezone-city'].replace('_', ' ')
(button, entry) = ListboxChoiceWindow(
tui.screen,
"Select Time Zone",
"Please select the city or area that the managed host is in (press a letter to jump to that place in the list):",
map(lambda x: x.replace('_', ' '), entries),
['Ok', 'Back'], height=8, scroll=1, default=default, help='gettz')