/[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.3 - (hide annotations) (download) (as text)
Mon Jun 8 14:43:07 2009 UTC (15 years, 3 months ago) by slords
Branch: MAIN
Changes since 1.2: +2 -1 lines
Content type: text/x-python
Whitespace cleanup

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     alldrives = diskset.driveList()
136     if flags.cmdline.has_key("drives"):
137 slords 1.2 drives = filter(lambda x:isys.mediaPresent(x) and
138     x in flags.cmdline["drives"].split(","), alldrives)
139 slords 1.1 else:
140 slords 1.2 drives = filter(lambda x:not self.driveIsRemovable(x) and
141     isys.mediaPresent(x) and
142     not isys.driveUsesModule(x, ["usb-storage", "ub", "sbp2"]), alldrives)
143 slords 1.1
144     if flags.cmdline.has_key("spares"):
145     spares = max(0,min(int(flags.cmdline["spares"]),len(drives)-2))
146     else:
147     spares = (len(drives)+4)/7
148    
149     if flags.cmdline.has_key("raid") and flags.cmdline["raid"] in ["none","0","1","5","6"]:
150     if flags.cmdline["raid"] == "none":
151     level = 0
152     else:
153     level = int(flags.cmdline["raid"])
154     if level == 0:
155     del drives[1:]
156     spares = 0
157     if level == 6 and len(drives)-spares < 4:
158     level = 5
159     if level == 5 and len(drives)-spares < 3:
160     level = 1
161     if level == 1:
162     if spares > 1 and not flags.cmdline.has_key("spares"):
163     spares = 1
164     del drives[2+spares:]
165     else:
166     if len(drives) - spares >= 6:
167     level = 6
168     elif len(drives) - spares >= 3:
169     level = 5
170     else:
171     level = 1
172    
173 slords 1.2 if len(drives) >= 1:
174     log.info("Using the following drives: %s" % drives)
175     if level >= 1:
176     log.info("Installing using RAID%s" % level)
177     log.info("Using %s spare drives" % spares)
178     else:
179     log.warning("Installing without using RAID")
180 slords 1.1
181 slords 1.2 (swapMin, swapMax) = iutil.swapSuggestion()
182 slords 1.1 if level >= 1:
183     raid1 = []
184     raid2 = []
185     raid3 = []
186     uniqueID = 100
187    
188     for drive in drives:
189 slords 1.2 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
190 slords 1.1 drive=[drive], size=100, primary=1, format=1)
191     request.uniqueID = uniqueID
192     raid1.append(uniqueID)
193     partitions.autoPartitionRequests.append(request)
194    
195     if not flags.cmdline.has_key("nolvm"):
196 slords 1.2 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
197 slords 1.1 size=(swapMin+4096)/(len(drives)-spares-max(0,level-4)),
198     drive=[drive], primary=1, grow=1, format=1)
199     request.uniqueID = uniqueID + 50
200     raid2.append(uniqueID + 50)
201     partitions.autoPartitionRequests.append(request)
202     else:
203 slords 1.2 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
204 slords 1.1 drive=[drive], size=swapMin/(len(drives)-spares-max(0,level-4))+10, grow=1,
205     maxSizeMB=swapMax/(len(drives)-spares-max(0,level-4)), format=1, primary=1)
206     request.uniqueID = uniqueID + 30
207     raid2.append(uniqueID + 30)
208     partitions.autoPartitionRequests.append(request)
209    
210 slords 1.2 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
211     size=1500/(len(drives)-spares-max(0,level-4)),
212 slords 1.1 drive=[drive], grow=1, primary=1, format=1)
213     request.uniqueID = uniqueID + 60
214     raid3.append(uniqueID + 60)
215     partitions.autoPartitionRequests.append(request)
216    
217     uniqueID = uniqueID + 1
218    
219 slords 1.2 partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("ext3"),
220 slords 1.1 mountpoint="/boot", raidmembers=raid1, raidlevel="RAID1", raidminor=1, format=1,
221     raidspares=0))
222    
223     if not flags.cmdline.has_key("nolvm"):
224 slords 1.2 request = partRequests.RaidRequestSpec(fileSystemTypeGet("physical volume (LVM)"),
225     raidmembers=raid2, raidlevel="RAID"+str(level), raidminor=2, format=1,
226 slords 1.1 raidspares=spares)
227     request.uniqueID = 200
228     partitions.autoPartitionRequests.append(request)
229     else:
230 slords 1.2 partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("swap"),
231 slords 1.1 raidmembers=raid2, raidlevel="RAID"+str(level), raidminor=2, format=1, raidspares=spares))
232    
233     partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("ext3"),
234 slords 1.2 mountpoint="/", raidmembers=raid3, raidlevel="RAID"+str(level), raidminor=3, format=1,
235 slords 1.1 raidspares=spares))
236    
237     else:
238     for drive in drives:
239 slords 1.2 partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("ext3"),
240 slords 1.1 mountpoint="/boot", drive=[drive], size=100, primary=1, format=1))
241    
242     if not flags.cmdline.has_key("nolvm"):
243     request = partRequests.PartitionSpec(fileSystemTypeGet("physical volume (LVM)"),
244     drive=[drive], size=swapMin+4096, grow=1, primary=1, format=1)
245     request.uniqueID = 200
246     partitions.autoPartitionRequests.append(request)
247     else:
248     partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("ext3"),
249     mountpoint="/", drive=[drive], size=4096, grow=1, primary=1, format=1))
250    
251     partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("swap"),
252     drive=[drive], size=swapMin, maxSizeMB=swapMax, grow=1, primary=1, format=1))
253    
254     if not flags.cmdline.has_key("nolvm"):
255     request = partRequests.VolumeGroupRequestSpec(vgname="main", physvols=[200], pesize=32768, format=1)
256     request.uniqueID = 201
257     partitions.autoPartitionRequests.append(request)
258    
259     if not flags.cmdline.has_key("multipart"):
260     partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
261 slords 1.3 mountpoint="/", size=1300, volgroup=201, lvname="root", grow=1, format=1))
262 slords 1.1
263     partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("swap"),
264     size=swapMin, maxSizeMB=swapMax, volgroup=201, lvname="swap", grow=1, format=1))
265     else:
266     partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
267     mountpoint="/", size=2048, maxSizeMB=4096, volgroup=201, lvname="root", grow=1, format=1))
268    
269     partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
270     mountpoint="/var", size=1024, maxSizeMB=4096, volgroup=201, lvname="var", grow=1, format=1))
271    
272 slords 1.2 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
273 slords 1.1 mountpoint="/home/e-smith/files", size=1024, maxSizeMB=8192, volgroup=201, lvname="files", grow=1, format=1))
274    
275     partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
276     mountpoint="/tmp", size=512, maxSizeMB=4096, volgroup=201, lvname="tmp", 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    
281 slords 1.2 partitions.autoClearPartType = CLEARPART_TYPE_ALL
282 slords 1.1 partitions.autoClearPartDrives = drives
283     self.doPartition = False
284     else:
285     log.warning("Not useable drives found. Enabling manual partitioning.")
286     self.doPartition = True
287     BaseInstallClass.setDefaultPartitioning(self, partitions, clear, doClear)
288    
289     def setAsHeadless(self, dispatch, isHeadless = 0):
290     if isHeadless == 0:
291     pass
292     else:
293     dispatch.skipStep("handleX11pkgs", permanent = 1)
294     dispatch.skipStep("videocard", permanent = 1)
295     dispatch.skipStep("monitor", permanent = 1)
296     dispatch.skipStep("xcustom", permanent = 1)
297     dispatch.skipStep("writexconfig", permanent = 1)
298    
299     def postAction(self, anaconda, serial):
300     win = anaconda.intf.waitWindow(_("Post Install Script"),
301     _("The post installation script is running..."))
302    
303     script = ( "#!/bin/sh\nmkdir -p /var/lib/dhcp; /sbin/syslogd ; sleep 2; /sbin/e-smith/signal-event post-install\n" )
304     s = Script(script, interp="/bin/sh", inChroot=1)
305     log.info("%s", s)
306     s.run(anaconda.rootPath, serial)
307     win.pop()
308    
309     def setInstallData(self, anaconda):
310     BaseInstallClass.setInstallData(self, anaconda)
311     self.setDefaultPartitioning(anaconda.id.partitions, CLEARPART_TYPE_ALL)
312     self.setSELinux(anaconda.id, SELINUX_DISABLED)
313    
314     def setGroupSelection(self, anaconda):
315     BaseInstallClass.__init__(self, anaconda.backend)
316     anaconda.backend.selectGroup("Base")
317     anaconda.backend.selectGroup("Core")
318     anaconda.backend.selectGroup("Extras")
319     anaconda.backend.selectGroup("SME Server")
320    
321     def __init__(self, expert):
322     BaseInstallClass.__init__(self, expert)
323     self.repopaths = { "base": "%s" %(productPath,) }
324     self.forceTextMode = 1

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