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

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

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


Revision 1.2 - (show annotations) (download) (as text)
Sun Jun 7 02:30:05 2009 UTC (15 years, 4 months ago) by slords
Branch: MAIN
Changes since 1.1: +161 -155 lines
Content type: text/x-python
Backport new raid/spare boot parameters from sme8 to sme7
Backport cmdline and mediaPresent routines from COS5 to sme7
Forward port driveIsRemovable routine from COS4 to sme8

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 str = ("(s: '%s' i: %s c: %d)") % \
17 (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
63 sortPriority = 1
64
65 cmdline = {}
66 doPartition = False
67
68 parentClass = ( _("Install SME Server"), "smeserver.png" )
69
70 def requiredDisplayMode(self):
71 return 't'
72
73 def createCmdlineDict(self):
74 cmdlineDict = {}
75 cmdline = open("/proc/cmdline", "r").read().strip()
76
77 for i in cmdline.split():
78 try:
79 (key, val) = i.split("=", 1)
80 except:
81 key = i
82 val = True
83
84 cmdlineDict[key] = val
85
86 return cmdlineDict
87
88 def mediaPresent(self, device):
89 try:
90 fd = os.open("/dev/%s" % device, os.O_RDONLY)
91 except OSError, (errno, strerror):
92 # error 123 = No medium found
93 if errno == 123:
94 return False
95 else:
96 return True
97 else:
98 os.close(fd)
99 return True
100
101 def setSteps(self, dispatch):
102 dispatch.setStepList(
103 "language",
104 "keyboard",
105 "findrootparts",
106 "betanag",
107 "installtype",
108 "partitionobjinit",
109 "autopartitionexecute",
110 "partition",
111 "partitiondone",
112 "bootloadersetup",
113 "languagesupport",
114 "timezone",
115 "readcomps",
116 "selectlangpackages",
117 "checkdeps",
118 "dependencies",
119 "install",
120 "enablefilesystems",
121 "migratefilesystems",
122 "setuptime",
123 "preinstallconfig",
124 "installpackages",
125 "postinstallconfig",
126 "writeconfig",
127 "instbootloader",
128 "dopostaction",
129 "writeksconfig",
130 "methodcomplete",
131 "copylogs",
132 "setfilecon",
133 "complete"
134 )
135
136
137 # 'partition' can be used on the command line to force
138 # verification of partitions. useful in some cases...
139 if self.doPartition or self.cmdline.has_key("partition"):
140 dispatch.skipStep("partition", skip = 0)
141 else:
142 dispatch.skipStep("partition", skip = 1)
143
144 def setDefaultPartitioning(self, partitions, clear = CLEARPART_TYPE_LINUX, doClear = 1):
145 self.cmdline = self.createCmdlineDict()
146 diskset = partedUtils.DiskSet()
147
148 alldrives = diskset.driveList()
149 if self.cmdline.has_key("drives"):
150 drives = filter(lambda x:self.mediaPresent(x) and
151 x in self.cmdline["drives"].split(","), alldrives)
152 else:
153 drives = filter(lambda x:not isys.driveIsRemovable(x) and
154 self.mediaPresent(x) and
155 not isys.driveUsesModule(x, ["usb-storage", "ub", "sbp2"]), alldrives)
156
157 if self.cmdline.has_key("spares"):
158 spares = max(0,min(int(self.cmdline["spares"]),len(drives)-2))
159 else:
160 spares = (len(drives)+4)/7
161
162 if self.cmdline.has_key("raid") and self.cmdline["raid"] in ["none","0","1","5","6"]:
163 if self.cmdline["raid"] == "none":
164 level = 0
165 else:
166 level = int(self.cmdline["raid"])
167 if level == 0:
168 del drives[1:]
169 spares = 0
170 if level == 6 and len(drives)-spares < 4:
171 level = 5
172 if level == 5 and len(drives)-spares < 3:
173 level = 1
174 if level == 1:
175 if spares > 1 and not self.cmdline.has_key("spares"):
176 spares = 1
177 del drives[2+spares:]
178 else:
179 if len(drives) - spares >= 6:
180 level = 6
181 elif len(drives) - spares >= 3:
182 level = 5
183 else:
184 level = 1
185
186 if len(drives) >= 1:
187 log("Using the following drives: %s" % drives)
188 if level >= 1:
189 log("Installing using RAID%s" % level)
190 log("Using %s spare drives" % spares)
191 else:
192 log("Installing without using RAID")
193
194 (swapMin, swapMax) = iutil.swapSuggestion()
195 if level >= 1:
196 raid1 = []
197 raid2 = []
198 raid3 = []
199 uniqueID = 100
200
201 for drive in drives:
202 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
203 drive=[drive], size=100, primary=1, format=1)
204 request.uniqueID = uniqueID
205 raid1.append(uniqueID)
206 partitions.autoPartitionRequests.append(request)
207
208 if not self.cmdline.has_key("nolvm"):
209 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
210 size=(swapMin+4096)/(len(drives)-spares-max(0,level-4)),
211 drive=[drive], primary=1, grow=1, format=1)
212 request.uniqueID = uniqueID + 50
213 raid2.append(uniqueID + 50)
214 partitions.autoPartitionRequests.append(request)
215 else:
216 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
217 drive=[drive], size=swapMin/(len(drives)-spares-max(0,level-4))+10, grow=1,
218 maxSizeMB=swapMax/(len(drives)-spares-max(0,level-4)), format=1, primary=1)
219 request.uniqueID = uniqueID + 30
220 raid2.append(uniqueID + 30)
221 partitions.autoPartitionRequests.append(request)
222
223 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
224 size=1500/(len(drives)-spares-max(0,level-4)),
225 drive=[drive], grow=1, primary=1, format=1)
226 request.uniqueID = uniqueID + 60
227 raid3.append(uniqueID + 60)
228 partitions.autoPartitionRequests.append(request)
229
230 uniqueID = uniqueID + 1
231
232 partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("ext3"),
233 mountpoint="/boot", raidmembers=raid1, raidlevel="RAID1", raidminor=1, format=1,
234 raidspares=0))
235
236 if not self.cmdline.has_key("nolvm"):
237 request = partRequests.RaidRequestSpec(fileSystemTypeGet("physical volume (LVM)"),
238 raidmembers=raid2, raidlevel="RAID"+str(level), raidminor=2, format=1,
239 raidspares=spares)
240 request.uniqueID = 200
241 partitions.autoPartitionRequests.append(request)
242 else:
243 partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("swap"),
244 raidmembers=raid2, raidlevel="RAID"+str(level), raidminor=2, format=1, raidspares=spares))
245
246 partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("ext3"),
247 mountpoint="/", raidmembers=raid3, raidlevel="RAID"+str(level), raidminor=3, format=1,
248 raidspares=spares))
249
250 else:
251 for drive in drives:
252 partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("ext3"),
253 mountpoint="/boot", drive=[drive], size=100, primary=1, format=1))
254
255 if not self.cmdline.has_key("nolvm"):
256 request = partRequests.PartitionSpec(fileSystemTypeGet("physical volume (LVM)"),
257 drive=[drive], size=swapMin+4096, grow=1, primary=1, format=1)
258 request.uniqueID = 200
259 partitions.autoPartitionRequests.append(request)
260 else:
261 partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("ext3"),
262 mountpoint="/", drive=[drive], size=4096, grow=1, primary=1, format=1))
263
264 partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("swap"),
265 drive=[drive], size=swapMin, maxSizeMB=swapMax, grow=1, primary=1, format=1))
266
267 if not self.cmdline.has_key("nolvm"):
268 request = partRequests.VolumeGroupRequestSpec(vgname="main", physvols=[200], pesize=32768, format=1)
269 request.uniqueID = 201
270 partitions.autoPartitionRequests.append(request)
271
272 if not self.cmdline.has_key("multipart"):
273 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
274 mountpoint="/", size=1300, volgroup=201, lvname="root", grow=1, format=1))
275
276 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("swap"),
277 size=swapMin, maxSizeMB=swapMax, volgroup=201, lvname="swap", grow=1, format=1))
278 else:
279 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
280 mountpoint="/", size=2048, maxSizeMB=4096, volgroup=201, lvname="root", grow=1, format=1))
281
282 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
283 mountpoint="/var", size=1024, maxSizeMB=4096, volgroup=201, lvname="var", grow=1, format=1))
284
285 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
286 mountpoint="/home/e-smith/files", size=1024, maxSizeMB=8192, volgroup=201, lvname="files", grow=1, format=1))
287
288 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
289 mountpoint="/tmp", size=512, maxSizeMB=4096, volgroup=201, lvname="tmp", grow=1, format=1))
290
291 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("swap"),
292 size=swapMin, maxSizeMB=swapMax, volgroup=201, lvname="swap", grow=1, format=1))
293
294 partitions.autoClearPartType = CLEARPART_TYPE_ALL
295 partitions.autoClearPartDrives = drives
296 self.doPartition = False
297 else:
298 log("Not useable drives found. Enabling manual partitioning.")
299 self.doPartition = True
300 BaseInstallClass.setDefaultPartitioning(self, partitions, clear, doClear)
301
302 def setAsHeadless(self, dispatch, isHeadless = 0):
303 if isHeadless == 0:
304 pass
305 else:
306 dispatch.skipStep("handleX11pkgs", permanent = 1)
307 dispatch.skipStep("videocard", permanent = 1)
308 dispatch.skipStep("monitor", permanent = 1)
309 dispatch.skipStep("xcustom", permanent = 1)
310 dispatch.skipStep("writexconfig", permanent = 1)
311
312 def setGroupSelection(self, grpset, intf):
313 grpset.unselectAll()
314 grpset.selectGroup("Base")
315
316 def postAction(self, rootPath, serial, intf):
317 win = intf.waitWindow(_("Post Install Script"),
318 _("The post installation script is running..."))
319
320 script = ( "/sbin/syslogd &\n"
321 "sleep 2\n"
322 "/sbin/e-smith/signal-event post-install\n" )
323 s = Script(script, interp="/bin/sh", inChroot=1)
324 log("%s", s)
325 s.run(rootPath, serial)
326 win.pop()
327
328 def setInstallData(self, id, intf = None):
329 BaseInstallClass.setInstallData(self, id)
330 self.setAuthentication(id, useShadow=1, salt="md5")
331 self.setRootPassword(id, pw="ThisIsGoingToBeDisabledAnyway", isCrypted=0)
332 self.setZeroMbr(id, zeroMbr=1)
333 self.setClearParts(id, clear=CLEARPART_TYPE_ALL, initAll=1)
334 self.setDefaultPartitioning(id.partitions, doClear=0)
335 self.setBootloader(id, useLilo=0, location="mbr", linear=1)
336
337 def __init__(self, expert):
338 BaseInstallClass.__init__(self, expert)

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