/[smeserver]/cdrom.image/sme7/product/installclasses/smeinstallclass.py
ViewVC logotype

Annotation of /cdrom.image/sme7/product/installclasses/smeinstallclass.py

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (hide annotations) (download) (as text)
Thu Aug 26 22:09:11 2010 UTC (14 years, 2 months ago) by slords
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +29 -40 lines
Content type: text/x-python
Installer classes cleanup to fix dmraid crashes

1 slords 1.1 from installclass import BaseInstallClass
2     from rhpl.translate import N_, _
3     from constants import *
4     import os
5     import iutil
6     from fsset import *
7    
8     from autopart import getAutopartitionBoot, autoCreatePartitionRequests, autoCreateLVMPartitionRequests
9     from rhpl.log import log
10     import string
11     import partRequests
12     import partedUtils
13    
14     class Script:
15     def __repr__(self):
16 slords 1.3 str = ("(s: '%s' i: %s c: %d)") % \
17 slords 1.1 (self.script, self.interp, self.inChroot)
18     return string.replace(str, "\n", "|")
19    
20     def __init__(self, script, interp, inChroot, logfile = None):
21     self.script = script
22     self.interp = interp
23     self.inChroot = inChroot
24     self.logfile = logfile
25    
26     def run(self, chroot, serial):
27     scriptRoot = "/"
28     if self.inChroot:
29     scriptRoot = chroot
30    
31     path = scriptRoot + "/tmp/sme-script"
32    
33     f = open(path, "w")
34     f.write(self.script)
35     f.close()
36     os.chmod(path, 0700)
37    
38     if self.logfile is not None:
39     messages = self.logfile
40     elif serial:
41     messages = "/tmp/sme-script.log"
42     else:
43     messages = "/dev/tty3"
44    
45     rc = iutil.execWithRedirect(self.interp,
46     [self.interp,"/tmp/sme-script"],
47     stdout = messages, stderr = messages,
48     root = scriptRoot)
49    
50     if rc != 0:
51     log("WARNING - Error code %s encountered running a sme script", rc)
52    
53     os.unlink(path)
54    
55     class InstallClass(BaseInstallClass):
56     id = "smeserver"
57     name = N_("New _SME Server Install")
58     pixmap = "smeserver.png"
59     description = N_("This option performs a new install of "
60     "SME Server. All attached hard drives "
61     "will be repartitioned and formated.")
62 slords 1.2
63 slords 1.1 sortPriority = 1
64    
65     parentClass = ( _("Install SME Server"), "smeserver.png" )
66    
67     def requiredDisplayMode(self):
68     return 't'
69    
70 slords 1.2 def createCmdlineDict(self):
71     cmdlineDict = {}
72     cmdline = open("/proc/cmdline", "r").read().strip()
73    
74     for i in cmdline.split():
75     try:
76     (key, val) = i.split("=", 1)
77     except:
78     key = i
79     val = True
80    
81     cmdlineDict[key] = val
82    
83     return cmdlineDict
84    
85 slords 1.6 def setSteps(self, dispatch):
86     self.anaconda = dispatch
87     self.cmdline = self.createCmdlineDict()
88 slords 1.2
89 slords 1.1 dispatch.setStepList(
90 slords 1.6 "betanag",
91 slords 1.1 "language",
92     "keyboard",
93     "findrootparts",
94     "installtype",
95     "partitionobjinit",
96     "autopartitionexecute",
97     "partitiondone",
98 slords 1.2 "bootloadersetup",
99 slords 1.1 "languagesupport",
100     "timezone",
101     "readcomps",
102     "selectlangpackages",
103     "checkdeps",
104     "dependencies",
105     "install",
106     "enablefilesystems",
107     "migratefilesystems",
108     "setuptime",
109     "preinstallconfig",
110     "installpackages",
111     "postinstallconfig",
112     "writeconfig",
113     "instbootloader",
114 slords 1.6 "writeksconfig",
115     "setfilecon",
116     "copylogs",
117 slords 1.1 "dopostaction",
118     "methodcomplete",
119     "complete"
120     )
121    
122 slords 1.2 # 'partition' can be used on the command line to force
123 slords 1.1 # verification of partitions. useful in some cases...
124 slords 1.6 dispatch.skipStep("partition", skip = (1,0)[self.cmdline.has_key("partition")])
125 slords 1.1
126     def setDefaultPartitioning(self, partitions, clear = CLEARPART_TYPE_LINUX, doClear = 1):
127 slords 1.6 diskset = self.anaconda.id.diskset
128 slords 1.1
129 slords 1.4 if self.cmdline.has_key("exclude"):
130 slords 1.6 alldrives = filter(lambda x:not (partedUtils.hasProtectedPartitions(x, self.anaconda) or
131     x in self.cmdline["exclude"].split(",")), diskset.driveList())
132 slords 1.4 else:
133 slords 1.6 alldrives = filter(lambda x:not partedUtils.hasProtectedPartitions(x, self.anaconda), diskset.disks.keys())
134 slords 1.4
135 slords 1.2 if self.cmdline.has_key("drives"):
136 slords 1.4 if self.cmdline["drives"] == "all":
137 slords 1.6 drives = alldrives
138 slords 1.4 else:
139 slords 1.6 drives = filter(lambda x:x in self.cmdline["drives"].split(","), alldrives)
140 slords 1.2 else:
141 slords 1.6 drives = filter(lambda x:not isys.driveUsesModule(x, ["usb-storage", "ub", "sbp2"]), alldrives)
142 slords 1.1
143 slords 1.2 if self.cmdline.has_key("spares"):
144 slords 1.4 if self.cmdline["spares"] == "none":
145     spares = 0
146     else:
147     try:
148     spares = max(0,min(int(self.cmdline["spares"]),len(drives)-2))
149     except:
150     spares = (len(drives)+4)/7
151 slords 1.2 else:
152     spares = (len(drives)+4)/7
153 slords 1.1
154 slords 1.2 if self.cmdline.has_key("raid") and self.cmdline["raid"] in ["none","0","1","5","6"]:
155     if self.cmdline["raid"] == "none":
156     level = 0
157     else:
158     level = int(self.cmdline["raid"])
159     if level == 0:
160     del drives[1:]
161     spares = 0
162     if level == 6 and len(drives)-spares < 4:
163     level = 5
164     if level == 5 and len(drives)-spares < 3:
165     level = 1
166     if level == 1:
167     if spares > 1 and not self.cmdline.has_key("spares"):
168     spares = 1
169     del drives[2+spares:]
170 slords 1.6 elif len(drives) > 1 and len(drives) == len(filter(lambda x:x.startswith('mapper/'), alldrives)):
171     level = -1
172     del drives[1:]
173     spares = 0
174 slords 1.2 else:
175     if len(drives) - spares >= 6:
176     level = 6
177     elif len(drives) - spares >= 3:
178     level = 5
179     else:
180     level = 1
181 slords 1.1
182 slords 1.2 if len(drives) >= 1:
183     log("Using the following drives: %s" % drives)
184 slords 1.6 excluded = filter(lambda x:x not in drives, diskset.disks.keys())
185     if excluded:
186     log("Excluding the following drives: %s" % excluded)
187     skipped = filter(lambda x:x not in diskset.disks.keys(), diskset.driveList())
188     if skipped:
189     log("Skipping the following drives: %s" % skipped)
190 slords 1.2 if level >= 1:
191     log("Installing using RAID%s" % level)
192     log("Using %s spare drives" % spares)
193 slords 1.6 elif level < 0:
194     log("Detected BIOS raid (skipping raid)")
195 slords 1.1 else:
196 slords 1.2 log("Installing without using RAID")
197    
198     (swapMin, swapMax) = iutil.swapSuggestion()
199     if level >= 1:
200 slords 1.1 raid1 = []
201     raid2 = []
202     raid3 = []
203 slords 1.2 uniqueID = 100
204 slords 1.1
205 slords 1.2 for drive in drives:
206     request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
207     drive=[drive], size=100, primary=1, format=1)
208     request.uniqueID = uniqueID
209     raid1.append(uniqueID)
210     partitions.autoPartitionRequests.append(request)
211 slords 1.1
212 slords 1.2 if not self.cmdline.has_key("nolvm"):
213 slords 1.5 if not self.cmdline.has_key("multipart"):
214     request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
215     size=(swapMin+1536)/(len(drives)-spares-max(0,level-4)),
216     drive=[drive], primary=1, grow=1, format=1)
217     else:
218     request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
219     size=(swapMin+5120)/(len(drives)-spares-max(0,level-4)),
220     drive=[drive], primary=1, grow=1, format=1)
221 slords 1.2 request.uniqueID = uniqueID + 50
222     raid2.append(uniqueID + 50)
223     partitions.autoPartitionRequests.append(request)
224 slords 1.1 else:
225 slords 1.2 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
226     drive=[drive], size=swapMin/(len(drives)-spares-max(0,level-4))+10, grow=1,
227     maxSizeMB=swapMax/(len(drives)-spares-max(0,level-4)), format=1, primary=1)
228     request.uniqueID = uniqueID + 30
229     raid2.append(uniqueID + 30)
230     partitions.autoPartitionRequests.append(request)
231 slords 1.1
232 slords 1.2 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
233 slords 1.5 size=1536/(len(drives)-spares-max(0,level-4)),
234 slords 1.2 drive=[drive], grow=1, primary=1, format=1)
235     request.uniqueID = uniqueID + 60
236     raid3.append(uniqueID + 60)
237 slords 1.1 partitions.autoPartitionRequests.append(request)
238    
239 slords 1.2 uniqueID = uniqueID + 1
240 slords 1.1
241 slords 1.2 partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("ext3"),
242     mountpoint="/boot", raidmembers=raid1, raidlevel="RAID1", raidminor=1, format=1,
243     raidspares=0))
244    
245     if not self.cmdline.has_key("nolvm"):
246     request = partRequests.RaidRequestSpec(fileSystemTypeGet("physical volume (LVM)"),
247     raidmembers=raid2, raidlevel="RAID"+str(level), raidminor=2, format=1,
248     raidspares=spares)
249     request.uniqueID = 200
250 slords 1.1 partitions.autoPartitionRequests.append(request)
251 slords 1.2 else:
252     partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("swap"),
253     raidmembers=raid2, raidlevel="RAID"+str(level), raidminor=2, format=1, raidspares=spares))
254 slords 1.1
255 slords 1.2 partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("ext3"),
256 slords 1.3 mountpoint="/", raidmembers=raid3, raidlevel="RAID"+str(level), raidminor=3, format=1,
257 slords 1.2 raidspares=spares))
258    
259     else:
260     for drive in drives:
261     partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("ext3"),
262 slords 1.3 mountpoint="/boot", drive=[drive], size=100, primary=1, format=1))
263 slords 1.2
264     if not self.cmdline.has_key("nolvm"):
265 slords 1.5 if not self.cmdline.has_key("multipart"):
266     request = partRequests.PartitionSpec(fileSystemTypeGet("physical volume (LVM)"),
267     drive=[drive], size=swapMin+1536, grow=1, primary=1, format=1)
268     else:
269     request = partRequests.PartitionSpec(fileSystemTypeGet("physical volume (LVM)"),
270     drive=[drive], size=swapMin+5120, grow=1, primary=1, format=1)
271 slords 1.2 request.uniqueID = 200
272     partitions.autoPartitionRequests.append(request)
273     else:
274     partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("ext3"),
275 slords 1.5 mountpoint="/", drive=[drive], size=1536, grow=1, primary=1, format=1))
276 slords 1.1
277 slords 1.2 partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("swap"),
278     drive=[drive], size=swapMin, maxSizeMB=swapMax, grow=1, primary=1, format=1))
279 slords 1.1
280 slords 1.2 if not self.cmdline.has_key("nolvm"):
281     request = partRequests.VolumeGroupRequestSpec(vgname="main", physvols=[200], pesize=32768, format=1)
282 slords 1.1 request.uniqueID = 201
283     partitions.autoPartitionRequests.append(request)
284    
285 slords 1.2 if not self.cmdline.has_key("multipart"):
286     partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
287 slords 1.5 mountpoint="/", size=1536, volgroup=201, lvname="root", grow=1, format=1))
288 slords 1.1
289 slords 1.2 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("swap"),
290     size=swapMin, maxSizeMB=swapMax, volgroup=201, lvname="swap", grow=1, format=1))
291     else:
292     partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
293     mountpoint="/", size=2048, maxSizeMB=4096, volgroup=201, lvname="root", grow=1, format=1))
294 slords 1.1
295 slords 1.2 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
296     mountpoint="/var", size=1024, maxSizeMB=4096, volgroup=201, lvname="var", grow=1, format=1))
297 slords 1.1
298 slords 1.2 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
299     mountpoint="/home/e-smith/files", size=1024, maxSizeMB=8192, volgroup=201, lvname="files", grow=1, format=1))
300 slords 1.1
301 slords 1.2 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
302 slords 1.5 mountpoint="/tmp", size=1024, maxSizeMB=4096, volgroup=201, lvname="tmp", grow=1, format=1))
303 slords 1.1
304 slords 1.2 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("swap"),
305     size=swapMin, maxSizeMB=swapMax, volgroup=201, lvname="swap", grow=1, format=1))
306 slords 1.1
307 slords 1.2 partitions.autoClearPartType = CLEARPART_TYPE_ALL
308     partitions.autoClearPartDrives = drives
309 slords 1.1 else:
310 slords 1.2 log("Not useable drives found. Enabling manual partitioning.")
311 slords 1.6 BaseInstallClass.setDefaultPartitioning(self, partitions, clear = CLEARPART_TYPE_ALL, doClear = True)
312     self.anaconda.skipStep("partition", skip = 0)
313 slords 1.1
314     def setAsHeadless(self, dispatch, isHeadless = 0):
315     if isHeadless == 0:
316     pass
317     else:
318     dispatch.skipStep("handleX11pkgs", permanent = 1)
319     dispatch.skipStep("videocard", permanent = 1)
320     dispatch.skipStep("monitor", permanent = 1)
321     dispatch.skipStep("xcustom", permanent = 1)
322     dispatch.skipStep("writexconfig", permanent = 1)
323    
324     def setGroupSelection(self, grpset, intf):
325     grpset.unselectAll()
326     grpset.selectGroup("Base")
327    
328     def postAction(self, rootPath, serial, intf):
329     win = intf.waitWindow(_("Post Install Script"),
330     _("The post installation script is running..."))
331    
332     script = ( "/sbin/syslogd &\n"
333     "sleep 2\n"
334     "/sbin/e-smith/signal-event post-install\n" )
335     s = Script(script, interp="/bin/sh", inChroot=1)
336     log("%s", s)
337     s.run(rootPath, serial)
338     win.pop()
339    
340     def setInstallData(self, id, intf = None):
341     BaseInstallClass.setInstallData(self, id)
342     self.setAuthentication(id, useShadow=1, salt="md5")
343     self.setRootPassword(id, pw="ThisIsGoingToBeDisabledAnyway", isCrypted=0)
344     self.setZeroMbr(id, zeroMbr=1)
345     self.setClearParts(id, clear=CLEARPART_TYPE_ALL, initAll=1)
346     self.setBootloader(id, useLilo=0, location="mbr", linear=1)
347    
348     def __init__(self, expert):
349     BaseInstallClass.__init__(self, expert)

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed