/[smeserver]/cdrom.image/sme8/updates/installclasses/smeinstallclass.py
ViewVC logotype

Contents of /cdrom.image/sme8/updates/installclasses/smeinstallclass.py

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


Revision 1.7 - (show annotations) (download) (as text)
Thu Oct 28 18:23:03 2010 UTC (14 years, 1 month ago) by slords
Branch: MAIN
Changes since 1.6: +7 -7 lines
Content type: text/x-python
Use ext4 for filesystems

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

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