/[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.5 - (show annotations) (download) (as text)
Mon Nov 30 23:46:26 2009 UTC (14 years, 11 months ago) by slords
Branch: MAIN
Changes since 1.4: +18 -9 lines
Content type: text/x-python
Lower requirements for minimum drive size

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 doPartition = False
73
74 parentClass = ( _("Install SME Server"), "smeserver.png" )
75
76 def requiredDisplayMode(self):
77 return 't'
78
79 def driveIsRemovable(self, device):
80 try:
81 removable = bool(int(open("/sys/block/%s/removable" % device).read()))
82 except:
83 removable = False
84
85 return removable
86
87 def setSteps(self, dispatch):
88 dispatch.setStepList(
89 "language",
90 "keyboard",
91 "findrootparts",
92 "betanag",
93 "installtype",
94 "partitionobjinit",
95 "autopartitionexecute",
96 "parttype",
97 "partition",
98 "partitiondone",
99 "bootloadersetup",
100 "timezone",
101 "reposetup",
102 "basepkgsel",
103 "postselection",
104 "confirminstall",
105 "install",
106 "enablefilesystems",
107 "migratefilesystems",
108 "setuptime",
109 "preinstallconfig",
110 "installpackages",
111 "postinstallconfig",
112 "writeconfig",
113 "instbootloader",
114 "dopostaction",
115 "writeksconfig",
116 "methodcomplete",
117 "copylogs",
118 "setfilecon",
119 "complete"
120 )
121
122 # 'partition' can be used on the command line to force
123 # verification of partitions. useful in some cases...
124 if self.doPartition or flags.cmdline.has_key("partition"):
125 if not self.doPartition:
126 dispatch.skipStep("parttype", skip = 1)
127 dispatch.skipStep("partition", skip = 0)
128 else:
129 dispatch.skipStep("parttype", skip = 1)
130 dispatch.skipStep("partition", skip = 1)
131
132 def setDefaultPartitioning(self, partitions, clear = CLEARPART_TYPE_LINUX, doClear = 1):
133 diskset = partedUtils.DiskSet()
134
135 if flags.cmdline.has_key("exclude"):
136 alldrives = filter(lambda x:not x in flags.cmdline["exclude"].split(","), diskset.driveList())
137 else:
138 alldrives = diskset.driveList()
139
140 if flags.cmdline.has_key("drives"):
141 if flags.cmdline["drives"] == "all":
142 drives = filter(lambda x:isys.mediaPresent(x), alldrives)
143 else:
144 drives = filter(lambda x:isys.mediaPresent(x) and
145 x in flags.cmdline["drives"].split(","), alldrives)
146 else:
147 drives = filter(lambda x:not self.driveIsRemovable(x) and
148 isys.mediaPresent(x) and
149 not isys.driveUsesModule(x, ["usb-storage", "ub", "sbp2"]), alldrives)
150
151 if flags.cmdline.has_key("spares"):
152 if flags.cmdline["spares"] == "none":
153 spares = 0
154 else:
155 try:
156 spares = max(0,min(int(flags.cmdline["spares"]),len(drives)-2))
157 except:
158 spares = (len(drives)+4)/7
159 else:
160 spares = (len(drives)+4)/7
161
162 if flags.cmdline.has_key("raid") and flags.cmdline["raid"] in ["none","0","1","5","6"]:
163 if flags.cmdline["raid"] == "none":
164 level = 0
165 else:
166 level = int(flags.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 flags.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 excluded = filter(lambda x:x not in drives, diskset.driveList())
188 log.info("Using the following drives: %s" % drives)
189 log.info("Excluding the following drives: %s" % excluded)
190 if level >= 1:
191 log.info("Installing using RAID%s" % level)
192 log.info("Using %s spare drives" % spares)
193 else:
194 log.warning("Installing without using RAID")
195
196 (swapMin, swapMax) = iutil.swapSuggestion()
197 if level >= 1:
198 raid1 = []
199 raid2 = []
200 raid3 = []
201 uniqueID = 100
202
203 for drive in drives:
204 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
205 drive=[drive], size=100, primary=1, format=1)
206 request.uniqueID = uniqueID
207 raid1.append(uniqueID)
208 partitions.autoPartitionRequests.append(request)
209
210 if not flags.cmdline.has_key("nolvm"):
211 if not flags.cmdline.has_key("multipart"):
212 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
213 size=(swapMin+1536)/(len(drives)-spares-max(0,level-4)),
214 drive=[drive], primary=1, grow=1, format=1)
215 else:
216 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
217 size=(swapMin+5120)/(len(drives)-spares-max(0,level-4)),
218 drive=[drive], primary=1, grow=1, format=1)
219 request.uniqueID = uniqueID + 50
220 raid2.append(uniqueID + 50)
221 partitions.autoPartitionRequests.append(request)
222 else:
223 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
224 drive=[drive], size=swapMin/(len(drives)-spares-max(0,level-4))+10, grow=1,
225 maxSizeMB=swapMax/(len(drives)-spares-max(0,level-4)), format=1, primary=1)
226 request.uniqueID = uniqueID + 30
227 raid2.append(uniqueID + 30)
228 partitions.autoPartitionRequests.append(request)
229
230 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
231 size=1536/(len(drives)-spares-max(0,level-4)),
232 drive=[drive], grow=1, primary=1, format=1)
233 request.uniqueID = uniqueID + 60
234 raid3.append(uniqueID + 60)
235 partitions.autoPartitionRequests.append(request)
236
237 uniqueID = uniqueID + 1
238
239 partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("ext3"),
240 mountpoint="/boot", raidmembers=raid1, raidlevel="RAID1", raidminor=1, format=1,
241 raidspares=0))
242
243 if not flags.cmdline.has_key("nolvm"):
244 request = partRequests.RaidRequestSpec(fileSystemTypeGet("physical volume (LVM)"),
245 raidmembers=raid2, raidlevel="RAID"+str(level), raidminor=2, format=1,
246 raidspares=spares)
247 request.uniqueID = 200
248 partitions.autoPartitionRequests.append(request)
249 else:
250 partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("swap"),
251 raidmembers=raid2, raidlevel="RAID"+str(level), raidminor=2, format=1, raidspares=spares))
252
253 partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("ext3"),
254 mountpoint="/", raidmembers=raid3, raidlevel="RAID"+str(level), raidminor=3, format=1,
255 raidspares=spares))
256
257 else:
258 for drive in drives:
259 partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("ext3"),
260 mountpoint="/boot", drive=[drive], size=100, primary=1, format=1))
261
262 if not flags.cmdline.has_key("nolvm"):
263 if not flags.cmdline.has_key("multipart"):
264 request = partRequests.PartitionSpec(fileSystemTypeGet("physical volume (LVM)"),
265 drive=[drive], size=swapMin+1536, grow=1, primary=1, format=1)
266 else:
267 request = partRequests.PartitionSpec(fileSystemTypeGet("physical volume (LVM)"),
268 drive=[drive], size=swapMin+5120, grow=1, primary=1, format=1)
269 request.uniqueID = 200
270 partitions.autoPartitionRequests.append(request)
271 else:
272 partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("ext3"),
273 mountpoint="/", drive=[drive], size=1536, grow=1, primary=1, format=1))
274
275 partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("swap"),
276 drive=[drive], size=swapMin, maxSizeMB=swapMax, grow=1, primary=1, format=1))
277
278 if not flags.cmdline.has_key("nolvm"):
279 request = partRequests.VolumeGroupRequestSpec(vgname="main", physvols=[200], pesize=32768, format=1)
280 request.uniqueID = 201
281 partitions.autoPartitionRequests.append(request)
282
283 if not flags.cmdline.has_key("multipart"):
284 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
285 mountpoint="/", size=1536, volgroup=201, lvname="root", grow=1, format=1))
286
287 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("swap"),
288 size=swapMin, maxSizeMB=swapMax, volgroup=201, lvname="swap", grow=1, format=1))
289 else:
290 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
291 mountpoint="/", size=2048, maxSizeMB=4096, volgroup=201, lvname="root", grow=1, format=1))
292
293 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
294 mountpoint="/var", size=1024, maxSizeMB=4096, volgroup=201, lvname="var", grow=1, format=1))
295
296 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
297 mountpoint="/home/e-smith/files", size=1024, maxSizeMB=8192, volgroup=201, lvname="files", grow=1, format=1))
298
299 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
300 mountpoint="/tmp", size=1024, maxSizeMB=4096, volgroup=201, lvname="tmp", grow=1, format=1))
301
302 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("swap"),
303 size=swapMin, maxSizeMB=swapMax, volgroup=201, lvname="swap", grow=1, format=1))
304
305 partitions.autoClearPartType = CLEARPART_TYPE_ALL
306 partitions.autoClearPartDrives = drives
307 self.doPartition = False
308 else:
309 log.warning("Not useable drives found. Enabling manual partitioning.")
310 self.doPartition = True
311 BaseInstallClass.setDefaultPartitioning(self, partitions, clear, doClear)
312
313 def setAsHeadless(self, dispatch, isHeadless = 0):
314 if isHeadless == 0:
315 pass
316 else:
317 dispatch.skipStep("handleX11pkgs", permanent = 1)
318 dispatch.skipStep("videocard", permanent = 1)
319 dispatch.skipStep("monitor", permanent = 1)
320 dispatch.skipStep("xcustom", permanent = 1)
321 dispatch.skipStep("writexconfig", permanent = 1)
322
323 def postAction(self, anaconda, serial):
324 win = anaconda.intf.waitWindow(_("Post Install Script"),
325 _("The post installation script is running..."))
326
327 script = ( "#!/bin/sh\nmkdir -p /var/lib/dhcp; /sbin/syslogd ; sleep 2; /sbin/e-smith/signal-event post-install\n" )
328 s = Script(script, interp="/bin/sh", inChroot=1)
329 log.info("%s", s)
330 s.run(anaconda.rootPath, serial)
331 win.pop()
332
333 def setInstallData(self, anaconda):
334 BaseInstallClass.setInstallData(self, anaconda)
335 self.setDefaultPartitioning(anaconda.id.partitions, CLEARPART_TYPE_ALL)
336 self.setSELinux(anaconda.id, SELINUX_DISABLED)
337
338 def setGroupSelection(self, anaconda):
339 BaseInstallClass.__init__(self, anaconda.backend)
340 anaconda.backend.selectGroup("Base")
341 anaconda.backend.selectGroup("Core")
342 anaconda.backend.selectGroup("Extras")
343 anaconda.backend.selectGroup("SME Server")
344
345 def __init__(self, expert):
346 BaseInstallClass.__init__(self, expert)
347 self.repopaths = { "base": "%s" %(productPath,) }
348 self.forceTextMode = 1

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