/[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.1 - (hide annotations) (download) (as text)
Sat Jun 6 23:51:54 2009 UTC (15 years, 6 months ago) by slords
Branch: MAIN
Content type: text/x-python
Split trees

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

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