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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
|
"""
# Copyright 1999-2005 Gentoo Foundation
# This source code is distributed under the terms of version 2 of the GNU
# General Public License as published by the Free Software Foundation, a copy
# of which can be found in the main directory of this project.
Gentoo Linux Installer
$Id: GLIInstallProfile.py,v 1.96 2006/09/02 23:54:46 codeman Exp $
The GLI module contains all classes used in the Gentoo Linux Installer (or GLI).
The InstallProfile contains all information related to the new system to be
installed.
PROCEDURE TO ADD NEW VARIABLES:
1. Add a handler to the list. If the variable has children make sure you do it right.
Look at the existing structure to get an idea.
2. Create a section for the two or three functions.
3. Create the get_variable_name and set_variable_name functions.
Ensure the set function has correct error checking.
4. If a simple value, add to the list in the general serialize() function.
If more complex add a serialize_variable_name to the list of special cases.
Then add the serialize_variable_name function to the section for the variable.
"""
import string
import xml.sax
import os
import GLIUtility
import SimpleXMLParser
import Partitioning
import xml.dom.minidom
from GLIException import *
import gettext
try:
gettext.install('GLIInstallProfile', './languages')
translator = gettext.translation('GLIInstallProfile', './languages')
_ = translator.gettext
except:
_ = gettext.gettext
##
# This class contains all the settings used during the install
class InstallProfile:
"""
An object representation of a profile.
InstallProfile is an object representation of a parsed installation
profile file.
"""
##
# Initializes all variables to default values and adds handlers.
def __init__(self):
# Configuration information - profile data
# All variables must be declared here with a default value to ensure
# the XML will correctly serialize.
self._cron_daemon_pkg = "vixie-cron"
self._logging_daemon_pkg = "syslog-ng"
self._boot_device = ""
self._boot_loader_mbr = True
self._boot_loader_pkg = ""
self._kernel_modules = []
self._kernel_config_uri = ""
self._kernel_build_method = "genkernel"
self._bootloader_kernel_args = ""
self._kernel_initrd = True
self._kernel_bootsplash = False
self._kernel_source_pkg = "gentoo-sources"
self._users = []
self._root_pass_hash = ""
self._time_zone = "UTC"
self._stage_tarball_uri = ""
self._install_stage = 3
self._portage_tree_sync_type = "sync"
self._portage_tree_snapshot_uri = ""
self._domainname = "localdomain"
self._hostname = "localhost"
self._http_proxy = ""
self._ftp_proxy = ""
self._rsync_proxy = ""
self._nisdomainname = ""
self._mounts = []
self._network_mounts = []
self._temp_partition_table = []
self._network_interfaces = {}
self._make_conf = {}
self._install_rp_pppoe = False
self._install_pcmcia_cs = False
self._dns_servers = ()
self._default_gateway = ()
self._install_packages = ()
self._services = ()
self._mta_pkg = ""
self._grp_install = False
self._post_install_script_uri = ""
self._etc_files = {}
self._temp_etc_file = {}
self._dynamic_stage3 = False
self._install_distcc = False
self._do_recommended_partitioning = "" #For fully-automated installs only.
self._yes_iam_sure = False #For use with do_recommended_partitioning only.
self._verbose = False
self.xmldoc = ""
# This is the root mount point
self._root_mount_point = "/mnt/gentoo"
# Parser handler calls. For each XML attribute and children of that attribute, a handler is needed.
self._parser = SimpleXMLParser.SimpleXMLParser()
self._parser.addHandler('gli-profile/bootloader', self.set_boot_loader_pkg)
self._parser.addHandler('gli-profile/boot-device', self.set_boot_device)
self._parser.addHandler('gli-profile/bootloader-kernel-args', self.set_bootloader_kernel_args)
self._parser.addHandler('gli-profile/bootloader-mbr', self.set_boot_loader_mbr)
self._parser.addHandler('gli-profile/cron-daemon', self.set_cron_daemon_pkg)
self._parser.addHandler('gli-profile/default-gateway', self.set_default_gateway)
self._parser.addHandler('gli-profile/dns-servers', self.set_dns_servers)
self._parser.addHandler('gli-profile/domainname', self.set_domainname)
self._parser.addHandler('gli-profile/dynamic-stage3', self.set_dynamic_stage3)
self._parser.addHandler('gli-profile/etc-files/file', self.add_etc_files_file, call_on_null=True)
self._parser.addHandler('gli-profile/etc-files/file/entry', self.add_etc_files_file_entry, call_on_null=True)
self._parser.addHandler('gli-profile/ftp-proxy', self.set_ftp_proxy)
self._parser.addHandler('gli-profile/grp-install', self.set_grp_install)
self._parser.addHandler('gli-profile/hostname', self.set_hostname)
self._parser.addHandler('gli-profile/http-proxy', self.set_http_proxy)
self._parser.addHandler('gli-profile/install-distcc', self.set_install_distcc)
self._parser.addHandler('gli-profile/install-packages', self.set_install_packages)
self._parser.addHandler('gli-profile/install-pcmcia-cs', self.set_install_pcmcia_cs)
self._parser.addHandler('gli-profile/install-stage', self.set_install_stage)
self._parser.addHandler('gli-profile/kernel-bootsplash', self.set_kernel_bootsplash)
self._parser.addHandler('gli-profile/kernel-build-method', self.set_kernel_build_method)
self._parser.addHandler('gli-profile/kernel-config', self.set_kernel_config_uri)
self._parser.addHandler('gli-profile/kernel-initrd', self.set_kernel_initrd)
self._parser.addHandler('gli-profile/kernel-modules', self.set_kernel_modules)
self._parser.addHandler('gli-profile/kernel-source', self.set_kernel_source_pkg)
self._parser.addHandler('gli-profile/logging-daemon', self.set_logging_daemon_pkg)
self._parser.addHandler('gli-profile/mounts/mount', self.add_mount, call_on_null=True)
self._parser.addHandler('gli-profile/mta', self.set_mta_pkg)
self._parser.addHandler('gli-profile/network-interfaces/device', self.add_network_interface)
self._parser.addHandler('gli-profile/network-mounts/netmount', self.add_netmount, call_on_null=True)
self._parser.addHandler('gli-profile/nisdomainname', self.set_nisdomainname)
self._parser.addHandler('gli-profile/portage-snapshot', self.set_portage_tree_snapshot_uri)
self._parser.addHandler('gli-profile/portage-tree-sync', self.set_portage_tree_sync_type)
self._parser.addHandler('gli-profile/post-install-script-uri', self.set_post_install_script_uri)
self._parser.addHandler('gli-profile/recommended-partitioning', self.set_do_recommended_partitioning)
self._parser.addHandler('gli-profile/root-mount-point', self.set_root_mount_point)
self._parser.addHandler('gli-profile/root-pass-hash', self.set_root_pass_hash)
self._parser.addHandler('gli-profile/rsync-proxy', self.set_rsync_proxy)
self._parser.addHandler('gli-profile/services', self.set_services)
self._parser.addHandler('gli-profile/stage-tarball', self.set_stage_tarball_uri)
self._parser.addHandler('gli-profile/time-zone', self.set_time_zone)
self._parser.addHandler('gli-profile/users/user', self.add_user)
self._parser.addHandler('gli-profile/yes-iam-sure', self.set_yes_iam_sure)
self._parser.addHandler('gli-profile/verbose', self.set_verbose)
##
# Parses the given filename populating the client_configuration.
# @param filename Parameter description
def parse(self, filename):
self._parser.parse(filename)
##
# This method serializes the configuration data and output a nice XML document.
# NOTE: this method currently does not serialize: _partition_tables or _kernel_modules
def serialize(self):
xmltab = { 'boot-device': self.get_boot_device,
'bootloader': self.get_boot_loader_pkg,
'bootloader-mbr': self.get_boot_loader_mbr,
'bootloader-kernel-args': self.get_bootloader_kernel_args,
'cron-daemon': self.get_cron_daemon_pkg,
'domainname': self.get_domainname,
'dynamic-stage3': self.get_dynamic_stage3,
'ftp-proxy': self.get_ftp_proxy,
'grp-install': self.get_grp_install,
'hostname': self.get_hostname,
'http-proxy': self.get_http_proxy,
'install-distcc': self.get_install_distcc,
'install-pcmcia-cs': self.get_install_pcmcia_cs,
'install-stage': self.get_install_stage,
'kernel-bootsplash': self.get_kernel_bootsplash,
'kernel-build-method': self.get_kernel_build_method,
'kernel-config': self.get_kernel_config_uri,
'kernel-initrd': self.get_kernel_initrd,
'kernel-source': self.get_kernel_source_pkg,
'logging-daemon': self.get_logging_daemon_pkg,
'mta': self.get_mta_pkg,
'nisdomainname': self.get_nisdomainname,
'portage-snapshot': self.get_portage_tree_snapshot_uri,
'portage-tree-sync': self.get_portage_tree_sync_type,
'post-install-script-uri': self.get_post_install_script_uri,
'recommended-partitioning': self.get_do_recommended_partitioning,
'root-mount-point': self.get_root_mount_point,
'root-pass-hash': self.get_root_pass_hash,
'rsync-proxy': self.get_rsync_proxy,
'stage-tarball': self.get_stage_tarball_uri,
'time-zone': self.get_time_zone,
'yes-iam-sure': self.get_yes_iam_sure,
'verbose': self.get_verbose,
}
self.xmldoc = "<?xml version=\"1.0\"?>"
self.xmldoc += "<gli-profile>"
# Normal cases
for key in xmltab.keys():
self.xmldoc += "<%s>%s</%s>" % (key, xmltab[key](), key)
# Special cases
self.serialize_default_gateway()
self.serialize_dns_servers()
self.serialize_install_packages()
self.serialize_kernel_modules()
self.serialize_mounts()
self.serialize_network_interfaces()
self.serialize_network_mounts()
self.serialize_services()
self.serialize_users()
self.serialize_etc_files()
self.xmldoc += "</gli-profile>"
dom = xml.dom.minidom.parseString(self.xmldoc)
return dom.toprettyxml()
############################################################################
############################################################################
#### Boot Device Selection
##
# boot_device is a string to decide which device to install the bootloader to
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param boot_loader_pkg boot device with full /dev
# @param xml_attr not used here
def set_boot_device(self, xml_path, boot_device, xml_attr):
#check data type
if type(boot_device) != str:
raise GLIException("BootDevice", 'fatal', 'set_boot_device', "Input must be type 'string'!")
self._boot_device = boot_device
##
# returns boot_device
def get_boot_device(self):
return self._boot_device
############################################################################
#### Bootloader Package Selection
##
# boot_loader_pkg is a string to decide which boot loader to install. (ie. 'grub')
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param boot_loader_pkg bootloader package name (like grub or lilo)
# @param xml_attr not used here
def set_boot_loader_pkg(self, xml_path, boot_loader_pkg, xml_attr):
# Check data type
if type(boot_loader_pkg) != str:
raise GLIException("BootLoaderPKG", 'fatal', 'set_boot_loader_pkg', "Input must be type 'string'!")
self._boot_loader_pkg = boot_loader_pkg
##
# returns boot_loader_pkg
def get_boot_loader_pkg(self):
return self._boot_loader_pkg
############################################################################
#### Bootloader Kernel Arguments
##
# FIXME: agaffney, what error checking needs to be done here?
# kernel_args are the arguments to pass the kernel at boot from the bootloader.
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param bootloader_kernel_args FIXME no idea.
# @param xml_attr not used here.
def set_bootloader_kernel_args(self, xml_path, bootloader_kernel_args, xml_attr):
self._bootloader_kernel_args = bootloader_kernel_args
##
# Returns kernel arguments
def get_bootloader_kernel_args(self):
return self._bootloader_kernel_args
############################################################################
#### Bootloader Installation to MBR
##
# boot_loader_mbr is a bool. True installs boot loader to MBR.
# False installs boot loader to the boot or root partition.
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param boot_loader_mbr
# @param xml_attr Parameter description
def set_boot_loader_mbr(self, xml_path, boot_loader_mbr, xml_attr):
# Check data type
if type(boot_loader_mbr) != bool:
if type(boot_loader_mbr) == str:
boot_loader_mbr = GLIUtility.strtobool(boot_loader_mbr)
else:
raise GLIException("BootLoaderMBRError", 'fatal', 'set_boot_loader_mbr', "Input must be type 'bool'!")
self._boot_loader_mbr = boot_loader_mbr
##
# returns boot_loader_mbr
def get_boot_loader_mbr(self):
return self._boot_loader_mbr
############################################################################
#### Cron Daemon Package
##
# cron_daemon_pkg is a string to determine which cron daemon to install and configure (ie. 'vixie-cron')
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param cron_daemon_pkg package name
# @param xml_attr Not used here.
def set_cron_daemon_pkg(self, xml_path, cron_daemon_pkg, xml_attr):
# Check data type
if type(cron_daemon_pkg) != str:
raise GLIException("CronDaemonPKGError", 'fatal', 'set_cron_daemon_pkg', "Input must be type 'string'!")
self._cron_daemon_pkg = cron_daemon_pkg
##
# Returns the cron daemon pkg name
def get_cron_daemon_pkg(self):
return self._cron_daemon_pkg
############################################################################
#### Network Gateway
##
# Set the default gateway for the post-installed system.
# The format of the input is: <default-gateway interface="interface name">ip of gateway</default-gateway>
# It saves this information in the following format: (<interface>, <ip of gateway>)
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param gateway gateway ip address
# @param xml_attr Parameter description
def set_default_gateway(self, xml_path, gateway, xml_attr):
if not GLIUtility.is_realstring(gateway):
raise GLIException('DefaultGatewayError', 'fatal', 'set_default_gateway', "The gateway must be a non-empty string!")
if not 'interface' in xml_attr.keys():
raise GLIException('DefaultGatewayError', 'fatal', 'set_default_gateway', 'No interface information specified!')
interface = str(xml_attr['interface'])
if not GLIUtility.is_eth_device(interface):
raise GLIException('DefaultGatewayError', 'fatal', 'set_default_gateway', "Invalid device!")
if not GLIUtility.is_ip(gateway):
raise GLIException("DefaultGateway", 'fatal', 'set_default_gateway', "The IP Provided is not valid!")
self._default_gateway = (interface, gateway)
##
# Returns the default gateway
def get_default_gateway(self):
return self._default_gateway
##
# Serializes default_gateway
def serialize_default_gateway(self):
if self.get_default_gateway() != ():
gw = self.get_default_gateway()
self.xmldoc += "<default-gateway interface=\"%s\">%s</default-gateway>" % (gw[0], gw[1])
############################################################################
#### DNS Servers
##
# Set the DNS servers for the post-installed system.
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param dns_servers a tuple or space-separated list of dns servers
# @param xml_attr Parameter description
def set_dns_servers(self, xml_path, dns_servers, xml_attr):
if type(dns_servers) == tuple:
dns_servers = dns_servers[0:3]
elif type(dns_servers) == str:
dns_servers = string.split(dns_servers)
else:
raise GLIException("DnsServersError", 'fatal', 'set_dns_servers', "Invalid input!")
for server in dns_servers:
if not GLIUtility.is_ip(server):
raise GLIException("DnsServersError", 'fatal', 'set_dns_servers', server + " must be a valid IP address!")
self._dns_servers = dns_servers
##
# This returns a tuple of the form: (<nameserver 1>, <nameserver 2>, <nameserver 3>)
def get_dns_servers(self):
return self._dns_servers
##
# Serializes DNS Servers
def serialize_dns_servers(self):
if self.get_dns_servers() != ():
self.xmldoc += "<dns-servers>"
self.xmldoc += string.join(self.get_dns_servers(), ' ')
self.xmldoc += "</dns-servers>"
###################################################################
##
# Set whether or not to automatically run do_recommended() on install.
# This is for fully-automated installs. Takes a value of the drive to partition.
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param do_recommended_partitioning string of the DRIVE to partition.
# @param xml_attr not used here
def set_do_recommended_partitioning(self, xml_path, do_recommended, xml_attr):
if type(do_recommended) != str:
raise GLIException("DoRecommendedPartitioning", 'fatal', 'set_do_recommended_partitioning', "Input must be a string!")
self._do_recommended_partitioning = do_recommended
##
# Returns the drive to run with do_recommended() on install
def get_do_recommended_partitioning(self):
return self._do_recommended_partitioning
############################################################################
#### Domainname
##
# domainname is a string containing the domainname for the new system. (ie. 'mydomain.com'; NOT FQDN)
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param domainname string of the domain name
# @param xml_attr not used here
def set_domainname(self, xml_path, domainname, xml_attr):
# Check type
if type(domainname) != str:
raise GLIException("DomainnameError", 'fatal', 'set_domainname', "Must be a string!")
self._domainname = domainname
##
# Returns domainname
def get_domainname(self):
return self._domainname
###################################################################
##
# Set whether or not to build the stage3 from the LiveCD
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param dynamic_stage3 True/False
# @param xml_attr not used here
def set_dynamic_stage3(self, xml_path, dynamic_stage3, xml_attr):
if type(dynamic_stage3) != bool:
if type(dynamic_stage3) == str:
self._dynamic_stage3 = GLIUtility.strtobool(dynamic_stage3)
else:
raise GLIException("DynamicStage3", 'fatal', 'set_dynamic_stage3', "Input must be type 'bool'!")
else:
self._dynamic_stage3 = dynamic_stage3
##
# Returns whether or not to build the stage3 from the LiveCD
def get_dynamic_stage3(self):
return self._dynamic_stage3
##
# Used internally for XML parsing...adds an entry to a file
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param value uhh...the value
# @param attr used for XML parsing
def add_etc_files_file_entry(self, xml_path, value, attr):
if 'name' in attr.getNames():
if not self._temp_etc_file:
self._temp_etc_file = {}
self._temp_etc_file[attr['name']] = value
else:
if not self._temp_etc_file:
self._temp_etc_file = []
self._temp_etc_file.append(value)
##
# Used internally for XML parsing...adds a file
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param unused this should be obvious
# @param attr used for XML parsing
def add_etc_files_file(self, xml_path, unused, attr):
self._etc_files[attr['name']] = self._temp_etc_file
self._temp_etc_file = None
##
# Returns etc_files structure
def get_etc_files(self):
return self._etc_files
##
# Replaces etc_files structure with one passed in
# @param etc_files new etc_files structure
def set_etc_files(self, etc_files):
self._etc_files = etc_files
##
# Serializes the etc_files structure
def serialize_etc_files(self):
self.xmldoc += "<etc-files>"
for etc_file in self._etc_files:
self.xmldoc += "<file name=\"%s\">" % etc_file
for entry in self._etc_files[etc_file]:
self.xmldoc += "<entry"
if isinstance(self._etc_files[etc_file], dict):
self.xmldoc += " name=\"%s\">%s" % (entry, self._etc_files[etc_file][entry])
else:
self.xmldoc += ">%s" % entry
self.xmldoc += "</entry>"
self.xmldoc += "</file>"
self.xmldoc += "</etc-files>"
############################################################################
#### FTP Proxy
##
# FTP proxy is a uri containing a proxy if needed for ftp traffic. (ie. 'ftp://myhost.mydomain:myport')
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param ftp_proxy ftp proxy address
# @param xml_attr not used here
def set_ftp_proxy(self, xml_path, ftp_proxy, xml_attr):
# Check type
if ftp_proxy and not GLIUtility.is_uri(ftp_proxy):
raise GLIException("FTPProxyError", 'fatal', 'set_ftp_proxy', "Must be a uri!")
self._ftp_proxy = ftp_proxy
##
# Returns FTP proxy
def get_ftp_proxy(self):
return self._ftp_proxy
############################################################################
#### GRP Install
##
# grp_install is a bool. True installs GRP. False doesn't.
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param grp_install boolean
# @param xml_attr Parameter description
def set_grp_install(self, xml_path, grp_install, xml_attr):
# Check data type
if type(grp_install) != bool:
if type(grp_install) == str:
grp_install = GLIUtility.strtobool(grp_install)
else:
raise GLIException("GRPInstall", 'fatal', 'set_grp_install', "Input must be type 'bool'!")
self._grp_install = grp_install
##
# returns grp_install
def get_grp_install(self):
return self._grp_install
############################################################################
#### Hostname
##
# Hostname is a string containing the hostname for the new system. (ie. 'myhost'; NOT 'myhost.mydomain.com')
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param hostname string of hostname
# @param xml_attr not used here.
def set_hostname(self, xml_path, hostname, xml_attr):
# Check type
if type(hostname) != str:
raise GLIException("HostnameError", 'fatal', 'set_hostname', "Must be a string!")
self._hostname = hostname
##
# Returns hostname
def get_hostname(self):
return self._hostname
############################################################################
#### HTTP Proxy
##
# HTTP proxy is a URI containing a proxy if needed for http traffic. (ie. 'http://myhost.mydomain:myport')
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param http_proxy http proxy address
# @param xml_attr not used here
def set_http_proxy(self, xml_path, http_proxy, xml_attr):
# Check type
if http_proxy and not GLIUtility.is_uri(http_proxy):
raise GLIException("HTTPProxyError", 'fatal', 'set_http_proxy', "Must be a uri!")
self._http_proxy = http_proxy
##
# Returns HTTP proxy
def get_http_proxy(self):
return self._http_proxy
############################################################################
#### Install Distcc
##
# This tells the installer whether or not to install the distcc package
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param install_distcc boolean
# @param xml_attr Parameter description
def set_install_distcc(self, xml_path, install_distcc, xml_attr):
if type(install_distcc) != bool:
if type(install_distcc) == str:
install_distcc = GLIUtility.strtobool(install_distcc)
else:
raise GLIException("InstallDistcc", 'fatal', 'set_install_distcc', "Input must be type 'bool'!")
self._install_distcc = install_distcc
##
# Returns the boolean _install_distcc
def get_install_distcc(self):
return self._install_distcc
############################################################################
#### Install Package List
##
# Returns the list of packages to include in the Extra Packages screens.
def get_install_package_list(self):
install_package_list = {
'Desktop': (_(u"Popular Desktop Applications"),
{"media-sound/audacious": _(u"GTK+ music player"),
"media-sound/easytag": _(u"A GTK+ tagging program for MP3, OGG, FLAC, and more"),
"mail-client/evolution": _(u"A GNOME groupware application, a Microsoft Outlook workalike"),
"net-im/gaim": _(u"GTK+ Instant Messenger client"),
"net-ftp/gftp": _(u"GTK+ FTP Client"),
"media-gfx/gimp": _(u"GNU Image Manipulation Program"),
"app-cdr/gnomebaker": _(u"GNOME CD Writing Software"),
"media-gfx/gtkam": _(u"GTK+ application for transferring pictures from a digital camera"),
"media-gfx/inkscape": _(u"A SVG based generic vector-drawing program"),
"app-cdr/k3b": _(u"KDE CD Writing Software"),
"app-office/koffice": _(u"An integrated office suite for KDE, the K Desktop Environment"),
"www-client/mozilla-firefox": _(u"The Mozilla Firefox Web Browser"),
"mail-client/mozilla-thunderbird": _(u"Thunderbird Mail Client"),
"media-video/mplayer": _(u"Media Player for Linux"),
"app-office/openoffice": _(u"OpenOffice.org, a full office productivity suite."),
"app-office/openoffice-bin": _(u"Same as OpenOffice but a binary package (no compiling!)"),
"net-nntp/pan": _(u"GTK news reader"),
"media-sound/rhythmbox": _(u"Music management and playback software for GNOME"),
"www-client/seamonkey": _(u"Open replacement for the Mozilla Suite"),
"mail-client/sylpheed": _(u"A light weight email client and news reader"),
"mail-client/sylpheed-claws": _(u"A light weight email client and news reader"),
"media-video/vlc": _(u"VLC media player - Video player and streamer"),
"net-irc/xchat": _(u"GTK+ Graphical IRC Client"),
"media-video/xine-ui": _(u"Xine movie player") }),
'Servers': (_(u"Applications often found on servers."),
{"net-www/apache": _(u"Apache Web Server"),
"net-print/cups": _(u"The Common Unix Printing System"),
"mail-mta/exim": _(u"A highly configurable, drop-in replacement for sendmail"),
"net-firewall/iptables": _(u"Linux kernel (2.4+) firewall, NAT and packet mangling tools"),
"dev-db/mysql": _(u"A fast, multi-threaded, multi-user SQL database server"),
"dev-lang/php": _(u"The PHP scripting language"),
"mail-mta/postfix": _(u"A fast and secure drop-in replacement for sendmail"),
"dev-db/postgresql": _(u"sophisticated Object-Relational DBMS"),
"net-ftp/proftpd": _(u"ProFTP Server"),
"net-fs/samba": _(u"SAMBA client/server programs for UNIX"),
"mail-mta/sendmail": _(u"Widely-used Mail Transport Agent (MTA)"), }),
'X11': (_(u"Window managers and X selection."),
{"x11-themes/gentoo-artwork-livecd": _(u"Desktop background used on this disk"),
"gnome-base/gnome": _(u"The Gnome Desktop Environment"),
"kde-base/kde-meta": _(u"The K Desktop Environment"),
"x11-wm/blackbox": _(u"A small, fast, full-featured window manager for X"),
"x11-wm/enlightenment": _(u"Enlightenment Window Manager"),
"x11-wm/fluxbox": _(u"Fluxbox is an X11 window manager featuring tabs and an iconbar"),
"x11-wm/icewm": _(u"IceWM is designed for speed, size, and simplicity"),
"x11-wm/windowmaker": _(u"Windowmaker is a window manager featuring the look and feel of NEXTSTEP"),
"xfce-base/xfce4": _(u"XFCE Desktop Environment"),
"x11-base/xorg-x11": _(u"An X11 implementation maintained by the X.Org Foundation") }),
'Misc': (_(u"Miscellaneous Applications you may want."),
{"net-p2p/bittorrent": _(u"tool for distributing files via a distributed network of nodes"),
"app-editors/bluefish": _(u"GTK+ Web IDE"),
"app-editors/emacs": _(u"An incredibly powerful, extensible text editor"),
"app-admin/gkrellm": _(u"Single process stack of various system monitors"),
"app-editors/gvim": _(u"GUI version of the Vim text editor"),
"net-misc/keychain": _(u"ssh-agent manager"),
"app-admin/logrotate": _(u"Rotates, compresses, and mails system logs"),
"net-misc/ntp": _(u"Network Time Protocol suite/programs"),
"net-misc/rdesktop": _(u"A Remote Desktop Protocol Client"),
"sys-apps/slocate": _(u"Secure way to index and quickly search for files on your system"),
"net-analyzer/traceroute": _(u"Utility to trace the route of IP packets"),
"app-portage/ufed": _(u"Gentoo Linux USE flags editor"),
"app-editors/vim": _(u"Vim, an improved vi-style text editor"),
"net-analyzer/wireshark": _(u"A commercial-quality network protocol analyzer") }),
'Recommended': (_(u"Applications recommended by the GLI Team."),
{"dev-util/anjuta": _(u"A versatile IDE for GNOME"),
"app-forensics/chkrootkit": _(u"a tool to locally check for signs of a rootkit"),
"games-arcade/crack-attack": _(u"Addictive OpenGL-based block game"),
"app-crypt/gnupg": _(u"The GNU Privacy Guard, a GPL PGP replacement"),
"net-analyzer/net-snmp": _(u"Software for generating and retrieving SNMP data"),
"net-analyzer/netcat": _(u"the network swiss army knife"),
"net-analyzer/nmap": _(u"A utility for network exploration or security auditing"),
"app-misc/screen": _(u"full-screen window manager that multiplexes between several processes"),
"app-text/xpdf": _(u"An X Viewer for PDF Files") })
}
return install_package_list
############################################################################
#### Install Packages
##
# Sets up the list of packages to be installed for the new system.
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param install_packages The space-separated list of packages to install.
# @param xml_attr Parameter description
def set_install_packages(self, xml_path, install_packages, xml_attr):
if type(install_packages) == str:
install_packages = string.split(install_packages)
else:
raise GLIException("InstallPackagesError", 'fatal', 'set_install_packages', "Invalid input!")
for install_package in install_packages:
if not GLIUtility.is_realstring(install_package):
raise GLIException("InstallPackagesError", 'fatal', 'set_install_packages', install_package + " must be a valid string!")
self._install_packages = install_packages
##
# This returns a list of the packages
def get_install_packages(self):
return self._install_packages
##
# Serializes install_packages
def serialize_install_packages(self):
if self.get_install_packages() != ():
self.xmldoc += "<install-packages>"
self.xmldoc += string.join(self.get_install_packages(), ' ')
self.xmldoc += "</install-packages>"
############################################################################
#### PCMCIA-CS
##
# This tells the installer whether or not to install the pcmcia_cs package
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param install_pcmcia boolean
# @param xml_attr Parameter description
def set_install_pcmcia_cs(self, xml_path, install_pcmcia, xml_attr):
if type(install_pcmcia) != bool:
if type(install_pcmcia) == str:
install_pcmcia = GLIUtility.strtobool(install_pcmcia)
else:
raise GLIException("InstallPcmciaCS", 'fatal', 'set_install_pcmcia_cs', "Input must be type 'bool'!")
self._install_pcmcia_cs = install_pcmcia
##
# Returns the boolean _install_pcmcia_cs
def get_install_pcmcia_cs(self):
return self._install_pcmcia_cs
############################################################################
#### Install Stage
##
# install_stage is a integer to define which stage install to use. Appropriate stages are 1-3.
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param install_stage install stage number
# @param xml_attr not used here.
def set_install_stage(self, xml_path, install_stage, xml_attr):
# Check type
if type(install_stage) != int:
if type(install_stage) == str:
install_stage = int(install_stage)
else:
raise GLIException("InstallStageError", 'fatal', 'set_install_stage', "Must be an integer!")
# Check for stage bounds
if 0 < install_stage < 4:
self._install_stage = install_stage
else:
raise GLIException("InstallStageError", 'fatal', 'set_install_stage', "install_stage must be 1-3!")
##
# Returns install_stage
def get_install_stage(self):
return self._install_stage
############################################################################
#### Kernel Bootsplash Option
##
# kernel_bootsplash is a bool to determine whether or not to install bootsplash into the kernel.
# True builds in bootsplash support to the initrd.
# WARNING: kernel_source_pkg must contain a kernel with bootsplash support or the bootsplash will not appear.
# If you set this to true, it will build an initrd kernel even if you chose false for kernel_initrd!
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param kernel_bootsplash boolean
# @param xml_attr not used here.
def set_kernel_bootsplash(self, xml_path, kernel_bootsplash, xml_attr):
# Check type
if type(kernel_bootsplash) != bool:
if type(kernel_bootsplash) == str:
kernel_bootsplash = GLIUtility.strtobool(kernel_bootsplash)
else:
raise GLIException("KernelBootsplashError", 'fatal', 'set_kernel_bootsplash', "Must be a bool!")
self._kernel_bootsplash = kernel_bootsplash
##
# Returns kernel_bootsplash
def get_kernel_bootsplash(self):
return self._kernel_bootsplash
############################################################################
#### Kernel Build Method
##
# kernel_build_method is a string specifying what build method you wish to use for the kernel.
# Can also be a http:// or ftp:// path.
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param kernel_build_method URI of kernel .config file
# @param xml_attr not used here.
def set_kernel_build_method(self, xml_path, kernel_build_method, xml_attr):
# Check type
if type(kernel_build_method) != str:
raise GLIException("KernelBuildMethodError", 'fatal', 'set_kernel_build_method', "Must be a string!")
self._kernel_build_method = kernel_build_method
##
# Returns kernel_build_method
def get_kernel_build_method(self):
return self._kernel_build_method
############################################################################
#### Kernel Configuration URI
##
# kernel_config_uri is a string that is the path to the kernel config file you wish to use.
# Can also be a http:// or ftp:// path.
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param kernel_config_uri URI of kernel .config file
# @param xml_attr not used here.
def set_kernel_config_uri(self, xml_path, kernel_config_uri, xml_attr):
# Check type
if type(kernel_config_uri) != str:
raise GLIException("KernelConfigURIError", 'fatal', 'set_kernel_config_uri', "Must be a string!")
# Check validity (now done in the FE)
#if not (kernel_config_uri):
# raise GLIException("KernelConfigURIError", 'fatal', 'set_kernel_config_uri', "Empty Kernel URI!")
self._kernel_config_uri = kernel_config_uri
##
# Returns kernel_config_uri
def get_kernel_config_uri(self):
return self._kernel_config_uri
############################################################################
#### Kernel Initrd Option
##
# kernel_initrd is a bool to determine whether or not to build an initrd kernel. False builds a non-initrd kernel.
# (overwritten by kernel_bootsplash; needs genkernel non-initrd support not yet present)
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param kernel_initrd boolean
# @param xml_attr not used here
def set_kernel_initrd(self, xml_path, kernel_initrd, xml_attr):
# Check type
if type(kernel_initrd) != bool:
if type(kernel_initrd) == str:
kernel_initrd = GLIUtility.strtobool(kernel_initrd)
else:
raise GLIException("KernelInitRDError", 'fatal', 'set_kernel_initrd', "Must be a bool!")
self._kernel_initrd = kernel_initrd
##
# Returns kernel_initrd
def get_kernel_initrd(self):
return self._kernel_initrd
############################################################################
#### Kernel Modules
##
# "kernel_modules is a tuple of strings containing names of modules to automatically load at boot time. (ie. '( 'ide-scsi', )')"
# @param kernel_modules Parameter description
def set_kernel_modules(self, kernel_modules):
# Check type
if isinstance(kernel_modules, str):
# raise GLIException("KernelModulesError", 'fatal', 'set_kernel_modules', "Must be a tuple!")
kernel_modules = kernel_modules.split(" ")
self._kernel_modules = kernel_modules
##
# Returns kernel_modules
def get_kernel_modules(self):
return self._kernel_modules
##
# Serializes kernel modules
def serialize_kernel_modules(self):
if self.get_kernel_modules() != []:
kernel_modules = self.get_kernel_modules()
self.xmldoc += "<kernel-modules>%s</kernel-modules>" % " ".join(kernel_modules)
############################################################################
#### Kernel Sources
##
# kernel_source_pkg is a string to define which kernel source to use. (ie. 'gentoo-sources')
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param kernel_source_pkg package name of the kernel sources to be emerged
# @param xml_attr not used here.
def set_kernel_source_pkg(self, xml_path, kernel_source_pkg, xml_attr):
# Check type
if type(kernel_source_pkg) != str:
raise GLIException("KernelSourcePKGError", 'fatal', 'set_kernel_source_pkg', "Must be a string!")
self._kernel_source_pkg = kernel_source_pkg
##
# Returns kernel_source_pkg
def get_kernel_source_pkg(self):
return self._kernel_source_pkg
############################################################################
#### Logging Daemon Package
##
# logging_daemon_pkg is a string to determine which logging daemon to install and configure (ie. 'sysklogd')
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param logging_daemon_pkg package name of logging daemon to be emerged
# @param xml_attr Parameter description
def set_logging_daemon_pkg(self, xml_path, logging_daemon_pkg, xml_attr):
# Check data type
if type(logging_daemon_pkg) != str:
raise GLIException("LoggingDaemonPKGError", 'fatal', 'set_logging_daemon_pkg', "Input must be type 'string'!")
self._logging_daemon_pkg = logging_daemon_pkg
##
# Returns logging daemon pkg name
def get_logging_daemon_pkg(self):
return self._logging_daemon_pkg
############################################################################
#### /etc/make.conf Configuration
##
# Adds a variable to the new system make.conf
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param data a string that is the value of the variable name.
# @param attr an xml attribute that contains the name of the variable
# OR attr is a variable name, like 'USE'. This makes it easier for front-end designers.
def make_conf_add_var(self, xml_path, data, attr):
if 'name' not in attr.keys():
raise GLIException("MakeConfError", 'fatal', 'make_conf_add_var', "Every value needs to have a variable name!")
varName = attr['name']
if not "make.conf" in self._etc_files:
self._etc_files['make.conf'] = {}
self._make_conf[str(varName)] = str(data)
##
# make_conf is a dictionary that will be set to _make_conf
# There is no checking that needs to be done, so please sure sure that the make_conf dictionary
# that is passed in is valid.
# @param make_conf a dictionary that will be set to _make_conf
def set_make_conf(self, make_conf):
self._etc_files['make.conf'] = make_conf
##
# Return a dictionary of the make.conf
def get_make_conf(self):
if "make.conf" in self._etc_files:
return self._etc_files['make.conf']
else:
return {}
##
# Serializes make.conf (no longer used)
def serialize_make_conf(self):
if self.get_make_conf() != {}:
self.xmldoc += "<make-conf>"
# keys should always be in the same order!
make_conf = self.get_make_conf()
make_conf_keys = make_conf.keys()
make_conf_keys.sort()
for var in make_conf_keys:
self.xmldoc += "<variable name=\"%s\">%s</variable>" % (var, make_conf[var])
self.xmldoc += "</make-conf>"
############################################################################
#### Mounts
##
# Mounts used during the installation and for fstab and bootloader config.
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param unused Parameter description
# @param attr Parameter description
def add_mount(self, xml_path, unused, attr):
mount_entry = {'devnode': '', 'mountopts': '', 'mountpoint': '', 'type': ''}
if type(attr) == tuple:
netmount_entry['devnode'] = attr[0]
netmount_entry['mountopts'] = attr[1]
netmount_entry['mountpoint'] = attr[2]
netmount_entry['type'] = attr[3]
else:
if "devnode" in attr.getNames():
for attrName in attr.getNames():
mount_entry[attrName] = str(attr.getValue(attrName))
self._mounts.append(mount_entry)
##
# Sets Mounts given a mounts found probably in the config file. Not sure if used.
# @param netmounts Parameter description
def set_mounts(self, mounts):
self._mounts = mounts
##
# Returns the mounts.
def get_mounts(self):
return self._mounts
##
# Serializes mounts
def serialize_mounts(self):
if self.get_mounts() != {}:
mounts = self.get_mounts()
self.xmldoc += "<mounts>"
for mount in mounts:
self.xmldoc += "<mount devnode=\"%s\" type=\"%s\" mountpoint=\"%s\" mountopts=\"%s\" />" % (mount['devnode'], mount['type'], mount['mountpoint'], mount['mountopts'])
self.xmldoc += "</mounts>"
############################################################################
#### MTA Selection
##
# Sets the intended MTA package
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param mta package name of mta
# @param xml_attr Parameter description
def set_mta_pkg(self, xml_path, mta_pkg, xml_attr):
if type(mta_pkg) != str:
raise GLIException("MTAError", 'fatal', 'set_mta_pkg', "The MTA must be a string!")
self._mta_pkg = mta_pkg
##
# returns the MTA
def get_mta_pkg(self):
return self._mta_pkg
############################################################################
#### Network Interface Selection
##
# This adds an ethernet device to the _network_interfaces dictionary.
# The format of this dictionary is:
# { <eth_device> : (options tuple), ... }
#
# eth_device can be a valid ethernet device eth0, eth1, wlan*... OR
# it can be a valid MAC address.
#
# The format of the options tuple is for a static IP:
# ( <ip address>, <broadcast>, <netmask> )
#
# For DHCP, the format of the options tuple is:
# ( 'dhcp', <dhcp options>, None )
#
# We keep the None as a placeholder, to not break anything that uses this
# in other parts of the installer.
#
# Aliases are no longer needed in the tuple because they can be treated like
# an individual interface. GLIUtility.is_eth_device will recognize
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param device the type and name of the device
# @param attr should be dhcp or a tuple of the ip addresses.
def add_network_interface(self, xml_path, device, attr):
options = None
ip = broadcast = netmask = dhcp_options = None
dhcp = True
if type(device) != str:
raise GLIException("NetworkInterfacesError", 'fatal', 'add_network_interface', "Invalid or unimplimented device type (" + device + ")!")
if not GLIUtility.is_eth_device(device):
device = GLIUtility.format_mac(device)
if not GLIUtility.is_mac(device):
raise GLIException("NetworkInterfacesError", 'fatal', 'add_network_interface', "Invalid or unimplimented device type (" + device + ")!")
if type(attr) == tuple:
ip = attr[0]
dhcp_options = broadcast = attr[1]
netmask = attr[2]
if ip != 'dhcp':
dhcp = False
else:
for attrName in attr.keys():
if attrName == 'ip':
ip = str(attr[attrName])
elif attrName == 'broadcast':
broadcast = str(attr[attrName])
elif attrName == 'netmask':
netmask = str(attr[attrName])
elif attrName == 'options':
dhcp_options = str(attr[attrName])
if ip != 'dhcp' and ip != None:
dhcp = False
if not dhcp:
if not GLIUtility.is_ip(ip):
raise GLIException("NetworkInterfacesError", 'fatal', 'add_network_interface', "The ip address you specified for " + device + " is not valid!")
if not GLIUtility.is_ip(broadcast):
raise GLIException("NetworkInterfacesError", 'fatal', 'add_network_interface', "The broadcast address you specified for " + device + " is not valid!")
if not GLIUtility.is_ip(netmask):
raise GLIException("NetworkInterfacesError", 'fatal', 'add_network_interface', "The netmask address you specified for " + device + " is not valid!")
options = (ip, broadcast, netmask)
else:
options = ('dhcp', dhcp_options, None)
self._network_interfaces[device] = options
##
# This method sets the network interfaces diction to network_interfaces.
# This method uses the function add_network_interfaces to do all of the real work.
# @param network_interfaces a dict with all the networking info. see add_ for specification.
def set_network_interfaces(self, network_interfaces):
# Check type
if type(network_interfaces) != dict:
raise GLIException("NetworkInterfacesError", 'fatal', 'set_network_interfaces', "Must be a dictionary!")
self._network_interfaces = {}
for device in network_interfaces:
self.add_network_interface(None, device, network_interfaces[device])
##
# Returns network_interfaces
def get_network_interfaces(self):
return self._network_interfaces
##
# Serialize Network Interfaces
def serialize_network_interfaces(self):
if self.get_network_interfaces() != {}:
self.xmldoc += "<network-interfaces>"
interfaces = self.get_network_interfaces()
for iface in interfaces:
if interfaces[iface][0] == 'dhcp':
attrs = "ip=\"dhcp\""
if interfaces[iface][1] != None:
dhcp_options = "options=\"%s\"" % interfaces[iface][1]
attrs = attrs + " " + dhcp_options
self.xmldoc += "<device %s>%s</device>" % (attrs, iface)
else:
self.xmldoc += "<device ip=\"%s\" broadcast=\"%s\" netmask=\"%s\">%s</device>" % (interfaces[iface][0], interfaces[iface][1], interfaces[iface][2], iface)
self.xmldoc += "</network-interfaces>"
############################################################################
#### Network Mounts
##
# FIXME: agaffney: Brief description of function
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param unused Parameter description
# @param attr Parameter description
def add_netmount(self, xml_path, unused, attr):
netmount_entry = {'export': '', 'host': '', 'mountopts': '', 'mountpoint': '', 'type': ''}
if type(attr) == tuple:
netmount_entry['export'] = attr[0]
netmount_entry['host'] = attr[1]
netmount_entry['mountopts'] = attr[2]
netmount_entry['mountpoint'] = attr[3]
netmount_entry['type'] = attr[4]
else:
if "export" in attr.getNames():
for attrName in attr.getNames():
netmount_entry[attrName] = str(attr.getValue(attrName))
self._network_mounts.append(netmount_entry)
##
# Sets Network Mounts given a netmounts found probably in the config file. Not sure if used.
# @param netmounts Parameter description
def set_network_mounts(self, netmounts):
self._network_mounts = netmounts
##
# Returns the network mounts.
def get_network_mounts(self):
return self._network_mounts
##
# Serializes network mounts
def serialize_network_mounts(self):
if self.get_network_mounts() != {}:
netmounts = self.get_network_mounts()
self.xmldoc += "<network-mounts>"
for mount in netmounts:
self.xmldoc += "<netmount host=\"%s\" export=\"%s\" type=\"%s\" mountpoint=\"%s\" mountopts=\"%s\" />" % (mount['host'], mount['export'], mount['type'], mount['mountpoint'], mount['mountopts'])
self.xmldoc += "</network-mounts>"
############################################################################
#### NIS Domain Name
##
# nisdomainname is a string containing the NIS domainname for the new system.
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param nisdomainname the name. is a string.
# @param xml_attr not used here
def set_nisdomainname(self, xml_path, nisdomainname, xml_attr):
# Check type
if type(nisdomainname) != str:
raise GLIException("NISDomainnameError", 'fatal', 'set_nisdomainname', "Must be a string!")
self._nisdomainname = nisdomainname
##
# Returns nisdomainname
def get_nisdomainname(self):
return self._nisdomainname
############################################################################
#### Portage Snapshot URI
##
# portage_tree_snapshot_uri is a string defining the path to a portage tree
# snapshot. (ie. 'file:///mnt/cdrom/snapshots/portage-*.tar.bz2')
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param portage_tree_snapshot_uri URI of the portage tree shapshot location
# @param xml_attr not used here
def set_portage_tree_snapshot_uri(self, xml_path, portage_tree_snapshot_uri, xml_attr):
# Check type
if type(portage_tree_snapshot_uri) != str:
raise GLIException("PortageTreeSnapshotURIError", 'fatal', 'set_portage_tree_snapshot_uri', "Must be a string!")
self._portage_tree_snapshot_uri = portage_tree_snapshot_uri
##
# Returns portage_tree_snapshot_uri
def get_portage_tree_snapshot_uri(self):
return self._portage_tree_snapshot_uri
############################################################################
#### Portage Tree Sync Type
##
# Sets the sync type to be used by portage
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param portage_tree_sync string with sync type
# @param xml_attr not used here
def set_portage_tree_sync_type(self, xml_path, portage_tree_sync, xml_attr):
# Check type
if type(portage_tree_sync) != str:
raise GLIException("PortageTreeSyncError", 'fatal', 'set_portage_tree_sync_type', "Must be a string!")
if string.lower(portage_tree_sync) not in ('sync', 'webrsync', 'custom', 'snapshot', 'none'):
raise GLIException("PortageTreeSyncError", 'fatal', 'set_portage_tree_sync_type', "Invalid Input!")
self._portage_tree_sync_type = string.lower(portage_tree_sync)
##
# Returns portage_tree_sync
def get_portage_tree_sync_type(self):
return self._portage_tree_sync_type
############################################################################
#### Post-Install Script URI
##
# Sets the URI for the post install script
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param post_install_script_uri the URI
# @param xml_attr Parameter description
def set_post_install_script_uri(self, xml_path, post_install_script_uri, xml_attr):
self._post_install_script_uri = post_install_script_uri
##
# Returns the URI for the post install script
def get_post_install_script_uri(self):
return self._post_install_script_uri
############################################################################
#### /etc/rc.conf Configuration
##
# Adds a variable set for the new system rc.conf
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param data a string that is the value of the variable name.
# @param attr an xml attribute that contains the name of the variable
def rc_conf_add_var(self, xml_path, data, attr):
if 'name' not in attr.keys():
raise GLIException("RCConfError", 'fatal', 'rc_conf_add_var', "Every value needs to have a variable name!")
varName = attr['name']
if not "rc.conf" in self._etc_files:
self._etc_files['rc.conf'] = {}
self._etc_files[str(varName)] = str(data)
##
# rc_conf is a dictionary that will be set to _rc_conf
# There is no checking that needs to be done, so please sure sure that the rc_conf dictionary
# that is passed in is valid.Brief description of function
# @param rc_conf dictionary in the format specified above.
def set_rc_conf(self, rc_conf):
self._etc_files['rc.conf'] = rc_conf
##
# Return a dictionary of the make.conf
def get_rc_conf(self):
if "rc.conf" in self._etc_files:
return self._etc_files['rc.conf']
else:
return {}
##
# Serializes rc.conf (no longer used)
def serialize_rc_conf(self):
if self.get_rc_conf() != {}:
self.xmldoc += "<rc-conf>"
rc_conf = self.get_rc_conf()
for var in rc_conf:
self.xmldoc += "<variable name=\"%s\">%s</variable>" % (var, rc_conf[var])
self.xmldoc += "</rc-conf>"
############################################################################
#### Root Mount Point For New System
##
# Sets the root_mount_point for the new system to be installed to
# @param xml_path not used here.
# @param root_mount_point new location for the root mount point
# @param xml_attr not used here.
def set_root_mount_point(self, xml_path, root_mount_point, xml_attr):
self._root_mount_point = root_mount_point
##
# Returns the root_mount_point
def get_root_mount_point(self):
return self._root_mount_point
############################################################################
#### Root Password Hash
##
# root_pass_hash is a string containing an md5 password hash to be assinged as the password for the root user.
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param root_pass_hash Parameter description
# @param xml_attr Parameter description
def set_root_pass_hash(self, xml_path, root_pass_hash, xml_attr):
# Check type
if type(root_pass_hash) != str:
raise GLIException("RootPassHashError", 'fatal', 'set_root_pass_hash', "Must be a string!")
self._root_pass_hash = root_pass_hash
##
# Returns root_pass_hash
def get_root_pass_hash(self):
return self._root_pass_hash
############################################################################
#### RSYNC Proxy
##
# RSYNC proxy is a uri containing a proxy if needed for rsync traffic. (ie. 'rsync://myhost.mydomain:myport')
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param rsync_proxy the proxy address
# @param xml_attr not used here
def set_rsync_proxy(self, xml_path, rsync_proxy, xml_attr):
# Check type
if rsync_proxy and not GLIUtility.is_uri(rsync_proxy):
raise GLIException("RSYNCProxyError", 'fatal', 'set_rsync_proxy', "Must be a uri!")
self._rsync_proxy = rsync_proxy
##
# Returns RSYNC proxy
def get_rsync_proxy(self):
return self._rsync_proxy
############################################################################
#### Services
##
# Set the services to be started on bootup. Services should be
# seperated by ','. WARNING: This used to be ' ' instead!
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param services comma-separated list of services
# @param xml_attr Parameter description
def set_services(self, xml_path, services, xml_attr):
if type(services) == str:
services = services.split(',')
else:
raise GLIException("ServicesError", 'fatal', 'set_services', "Invalid input!")
for service in services:
if not GLIUtility.is_realstring(service):
raise GLIException("ServicesError", 'fatal', 'set_services', service + " must be a valid string!")
self._services = services
##
# This returns a list of the packages:
def get_services(self):
return self._services
##
# Serializes services
def serialize_services(self):
if self.get_services() != ():
self.xmldoc += "<services>"
self.xmldoc += string.join(self.get_services(), ',')
self.xmldoc += "</services>"
############################################################################
#### Stage Tarball URI
##
# stage_tarball_uri is a string that is the full path to the tarball you
# wish to use. (ie. 'file:///path/to/mytarball.tar.bz2')
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param stage_tarball_uri string of URI for stage tarball location.
# @param xml_attr not used here.
def set_stage_tarball_uri(self, xml_path, stage_tarball_uri, xml_attr):
# Check type
if type(stage_tarball_uri) != str:
raise GLIException("StageTarballURIError", 'fatal', 'set_stage_tarball_uri', "Must be a string!")
# Check validity (now done in the FE)
#if not stage_tarball_uri:
# raise GLIException("CustomStage3TarballURIError", 'fatal', 'set_stage_tarball_uri', "Empty URI!")
self._stage_tarball_uri = stage_tarball_uri
##
# Returns stage_tarball_uri
def get_stage_tarball_uri(self):
return self._stage_tarball_uri
############################################################################
#### Timezone
##
# time_zone is a string defining the time zone to use.
# Time zones are found in /usr/share/zoneinfo/. Syntax is 'UTC' or 'US/Eastern'.
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param time_zone string of the intended timezone
# @param xml_attr not used here.
def set_time_zone(self, xml_path, time_zone, xml_attr):
# Check type
if type(time_zone) != str:
raise GLIException("TimeZoneError", 'fatal', 'set_time_zone', "Must be a string!")
self._time_zone = time_zone
##
# Returns time_zone
def get_time_zone(self):
return self._time_zone
############################################################################
#### Users
##
# Adds a user to the list of users
# @param xml_path Used internally by the XML parser. Should be None when calling directly
# @param username name of user to be added
# @param attr=None parameters for the user.
def add_user(self, xml_path, username, attr=None):
"""
This will take a username (that is a string) and a set of attributes and it will verify everything is valid
and convert it into a 7-tuple set. Then it adds this tuple into the users list.
username and hash are manditory. All other attributes are optional. Or this method will
take a 7-tuple set, verify it's correctness and then append it to the _users list.
All items are strings except <uid>, which is an integer, and groups, which is a tuple.
The finished tuples look like this:
( <user name>, <password hash>, (<tuple of groups>), <shell>, <home directory>, <user id>, <user comment> )
"""
hash = ''
shell = None
groups = None
shell = None
homedir = None
uid = None
comment = None
if type(username) == tuple:
if len(username) != 7:
raise GLIException("UserError", 'fatal', 'add_user', "Wrong format for user tuple!")
username_tmp = username[0]
hash = username[1]
groups = username[2]
shell = username[3]
homedir = username[4]
uid = username[5]
comment = username[6]
username = username_tmp
if type(groups) != tuple:
if groups != None:
groups = tuple(groups.split(','))
else:
for attrName in attr.keys():
if attrName == 'groups':
groups = tuple(str(attr[attrName]).split(','))
elif attrName == 'shell':
shell = str(attr[attrName])
elif attrName == 'hash':
hash = str(attr[attrName])
elif attrName == 'homedir':
homedir = str(attr[attrName])
elif attrName == 'uid':
if attr[attrName]:
uid = int(attr[attrName])
elif attrName == 'comment':
comment = str(attr[attrName])
allowable_nonalphnum_characters = '_-'
if not GLIUtility.is_realstring(username):
raise GLIException("UserError", 'fatal', 'add_user', "username must be a non-empty string")
if username[0] not in (string.lowercase + string.uppercase):
raise GLIException("UsersError", 'fatal', 'add_user', "A username must start with a letter!")
for x in username:
if x not in (string.lowercase + string.uppercase + string.digits + allowable_nonalphnum_characters):
raise GLIException("UsersError", 'fatal', 'add_user', "A username must contain only letters, numbers, or these symbols: " + allowable_nonalphnum_characters)
for user in self._users:
if username == user[0]:
raise GLIException("UserError", 'fatal', 'add_user', "This username already exists!")
if (hash == None) or (hash == ''):
raise GLIException("UserError", 'fatal', 'add_user', "A password hash must be given for every user!")
self._users.append((username,hash,groups,shell,homedir,uid,comment))
##
# Remove "username" from the _users list.
# @param username name of user to be removed
def remove_user(self, username):
for user in self._users:
if username == user[0]:
self._users.remove(user)
break
##
# users is a tuple(user) of tuple's. This sets _users to this set of tuples.
# @param users a tuple(user) of tuple's.
def set_users(self, users):
self._users = []
if users != None:
for user in users:
self._users.append(user)
##
# Returns users
def get_users(self):
return self._users
##
# Serializes users
def serialize_users(self):
if self.get_users() != []:
self.xmldoc += "<users>"
users = self.get_users()
for user in users:
attrstr = ""
username = user[0]
if user[1] != None:
attrstr += "hash=\"%s\" " % user[1]
if user[2] != None:
attrstr += "groups=\"%s\" " % string.join(user[2],',')
if user[3] != None:
attrstr += "shell=\"%s\" " % user[3]
if user[4] != None:
attrstr += "homedir=\"%s\" " % user[4]
if user[5] != None:
attrstr += "uid=\"%s\" " % user[5]
if user[6] != None:
attrstr += "comment=\"%s\" " % user[6]
self.xmldoc += "<user %s>%s</user>" % (string.strip(attrstr), username)
self.xmldoc += "</users>"
##
# Sets the special additional check for do_recommended as a safeguard to make
# sure people don't accidentally trash their drives.
# @param xml_path not used here.
# @param yes_iam_sure flag. boolean.
# @param xml_attr not used here.
def set_yes_iam_sure(self, xml_path, yes_iam_sure, xml_attr):
if type(yes_iam_sure) == str:
yes_iam_sure = GLIUtility.strtobool(yes_iam_sure)
self._yes_iam_sure = yes_iam_sure
##
# Returns the yes_iam_sure flag. For use with do_recommended
def get_yes_iam_sure(self):
return self._yes_iam_sure
##
# Sets the Verbose mode (DEBUG mode)
# @param xml_path not used here.
# @param verbose flag. boolean.
# @param xml_attr not used here.
def set_verbose(self, xml_path, verbose, xml_attr):
if type(verbose) == str:
verbose = GLIUtility.strtobool(verbose)
self._verbose = verbose
##
# Returns the verbose (DEBUG) flag
def get_verbose(self):
return self._verbose
|