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

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