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

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

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


Revision 1.4 - (hide annotations) (download) (as text)
Wed Jun 10 14:22:18 2009 UTC (15 years, 3 months ago) by slords
Branch: MAIN
Changes since 1.3: +19 -4 lines
Content type: text/x-python
Fixes

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     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 slords 1.3
71 slords 1.1 sortPriority = 1
72     doPartition = False
73    
74     parentClass = ( _("Install SME Server"), "smeserver.png" )
75    
76     def requiredDisplayMode(self):
77     return 't'
78    
79 slords 1.2 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 slords 1.1 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 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     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 slords 1.4 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 slords 1.1 if flags.cmdline.has_key("drives"):
141 slords 1.4 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 slords 1.1 else:
147 slords 1.2 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 slords 1.1
151     if flags.cmdline.has_key("spares"):
152 slords 1.4 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 slords 1.1 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 slords 1.2 if len(drives) >= 1:
187 slords 1.4 excluded = filter(lambda x:x not in drives, diskset.driveList())
188 slords 1.2 log.info("Using the following drives: %s" % drives)
189 slords 1.4 log.info("Excluding the following drives: %s" % excluded)
190 slords 1.2 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 slords 1.1
196 slords 1.2 (swapMin, swapMax) = iutil.swapSuggestion()
197 slords 1.1 if level >= 1:
198     raid1 = []
199     raid2 = []
200     raid3 = []
201     uniqueID = 100
202    
203     for drive in drives:
204 slords 1.2 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
205 slords 1.1 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 slords 1.2 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
212 slords 1.1 size=(swapMin+4096)/(len(drives)-spares-max(0,level-4)),
213     drive=[drive], primary=1, grow=1, format=1)
214     request.uniqueID = uniqueID + 50
215     raid2.append(uniqueID + 50)
216     partitions.autoPartitionRequests.append(request)
217     else:
218 slords 1.2 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
219 slords 1.1 drive=[drive], size=swapMin/(len(drives)-spares-max(0,level-4))+10, grow=1,
220     maxSizeMB=swapMax/(len(drives)-spares-max(0,level-4)), format=1, primary=1)
221     request.uniqueID = uniqueID + 30
222     raid2.append(uniqueID + 30)
223     partitions.autoPartitionRequests.append(request)
224    
225 slords 1.2 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
226     size=1500/(len(drives)-spares-max(0,level-4)),
227 slords 1.1 drive=[drive], grow=1, primary=1, format=1)
228     request.uniqueID = uniqueID + 60
229     raid3.append(uniqueID + 60)
230     partitions.autoPartitionRequests.append(request)
231    
232     uniqueID = uniqueID + 1
233    
234 slords 1.2 partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("ext3"),
235 slords 1.1 mountpoint="/boot", raidmembers=raid1, raidlevel="RAID1", raidminor=1, format=1,
236     raidspares=0))
237    
238     if not flags.cmdline.has_key("nolvm"):
239 slords 1.2 request = partRequests.RaidRequestSpec(fileSystemTypeGet("physical volume (LVM)"),
240     raidmembers=raid2, raidlevel="RAID"+str(level), raidminor=2, format=1,
241 slords 1.1 raidspares=spares)
242     request.uniqueID = 200
243     partitions.autoPartitionRequests.append(request)
244     else:
245 slords 1.2 partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("swap"),
246 slords 1.1 raidmembers=raid2, raidlevel="RAID"+str(level), raidminor=2, format=1, raidspares=spares))
247    
248     partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("ext3"),
249 slords 1.2 mountpoint="/", raidmembers=raid3, raidlevel="RAID"+str(level), raidminor=3, format=1,
250 slords 1.1 raidspares=spares))
251    
252     else:
253     for drive in drives:
254 slords 1.2 partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("ext3"),
255 slords 1.1 mountpoint="/boot", drive=[drive], size=100, primary=1, format=1))
256    
257     if not flags.cmdline.has_key("nolvm"):
258     request = partRequests.PartitionSpec(fileSystemTypeGet("physical volume (LVM)"),
259     drive=[drive], size=swapMin+4096, grow=1, primary=1, format=1)
260     request.uniqueID = 200
261     partitions.autoPartitionRequests.append(request)
262     else:
263     partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("ext3"),
264     mountpoint="/", drive=[drive], size=4096, 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("ext3"),
276 slords 1.3 mountpoint="/", size=1300, volgroup=201, lvname="root", grow=1, format=1))
277 slords 1.1
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("ext3"),
282     mountpoint="/", size=2048, maxSizeMB=4096, volgroup=201, lvname="root", grow=1, format=1))
283    
284     partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
285     mountpoint="/var", size=1024, maxSizeMB=4096, volgroup=201, lvname="var", grow=1, format=1))
286    
287 slords 1.2 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
288 slords 1.1 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("ext3"),
291     mountpoint="/tmp", size=512, 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 slords 1.2 partitions.autoClearPartType = CLEARPART_TYPE_ALL
297 slords 1.1 partitions.autoClearPartDrives = drives
298     self.doPartition = False
299     else:
300     log.warning("Not useable drives found. Enabling manual partitioning.")
301     self.doPartition = True
302     BaseInstallClass.setDefaultPartitioning(self, partitions, clear, doClear)
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.setDefaultPartitioning(anaconda.id.partitions, CLEARPART_TYPE_ALL)
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