2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2005, 2006 Red Hat, Inc.
6 # This software may be freely redistributed under the terms of the GNU
7 # general public license.
9 # You should have received a copy of the GNU General Public License
10 # along with this program; if not, write to the Free Software
11 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 from pykickstart
.constants
import *
16 from pykickstart
.errors
import *
17 from pykickstart
.options
import *
18 from pykickstart
.version
import *
20 from rhpl
.translate
import _
21 import rhpl
.translate
as translate
23 translate
.textdomain("pykickstart")
25 ### INHERIT FROM A PREVIOUS RELEASE
28 class FC6Handler(FC5Handler
):
32 class DmRaidData(BaseData
):
33 def __init__(self
, name
="", devices
=None, dmset
=None):
34 BaseData
.__init
__(self
)
40 self
.devices
= devices
44 retval
= "dmraid --name=%s" % self
.name
46 for dev
in self
.devices
:
47 retval
+= " --dev=\"%s\"" % dev
51 class IscsiData(BaseData
):
52 def __init__(self
, ipaddr
="", port
="", target
="", user
=None, password
=None):
53 BaseData
.__init
__(self
)
58 self
.password
= password
64 retval
+= " --target=%s" % self
.target
66 retval
+= " --ipaddr=%s" % self
.ipaddr
68 retval
+= " --port=%s" % self
.port
69 if self
.user
is not None:
70 retval
+= " --user=%s" % self
.user
71 if self
.password
is not None:
72 retval
+= " --password=%s" % self
.password
76 class MpPathData(BaseData
):
77 def __init__(self
, mpdev
="", device
="", rule
=""):
78 BaseData
.__init
__(self
)
84 return " --device=%s --rule=\"%s\"" % (self
.device
, self
.rule
)
86 class MultiPathData(BaseData
):
87 def __init__(self
, name
="", paths
=None):
88 BaseData
.__init
__(self
)
99 for path
in self
.paths
:
100 retval
+= "multipath --mpdev=%s %s\n" % (self
.name
, path
.__str
__())
104 class NetworkData(FC5Handler
.NetworkData
):
105 def __init__(self
, bootProto
="dhcp", dhcpclass
="", device
="", essid
="",
106 ethtool
="", gateway
="", hostname
="", ip
="", ipv4
=True,
107 ipv6
=True, mtu
="", nameserver
="", netmask
="", nodns
=False,
108 notksdevice
=False, onboot
=True, wepkey
=""):
109 FC5Handler
.NetworkData
.__init
__(self
, bootProto
=bootProto
,
110 dhcpclass
=dhcpclass
, device
=device
,
111 essid
=essid
, ethtool
=ethtool
,
112 gateway
=gateway
, hostname
=hostname
,
113 ip
=ip
, mtu
=mtu
, netmask
=netmask
,
114 nameserver
=nameserver
, nodns
=nodns
,
115 notksdevice
=notksdevice
,
116 onboot
=onboot
, wepkey
=wepkey
)
123 if self
.bootProto
!= "":
124 retval
+= " --bootproto=%s" % self
.bootProto
125 if self
.dhcpclass
!= "":
126 retval
+= " --dhcpclass=%s" % self
.dhcpclass
127 if self
.device
!= "":
128 retval
+= " --device=%s" % self
.device
130 retval
+= " --essid=\"%s\"" % self
.essid
131 if self
.ethtool
!= "":
132 retval
+= " --ethtool=\"%s\"" % self
.ethtool
133 if self
.gateway
!= "":
134 retval
+= " --gateway=%s" % self
.gateway
135 if self
.hostname
!= "":
136 retval
+= " --hostname=%s" % self
.hostname
138 retval
+= " --ip=%s" % self
.ip
140 retval
+= " --noipv4"
142 retval
+= " --noipv6"
144 retval
+= " --mtu=%s" % self
.mtu
145 if self
.nameserver
!= "":
146 retval
+= " --nameserver=%s" % self
.nameserver
147 if self
.netmask
!= "":
148 retval
+= " --netmask=%s" % self
.netmask
152 retval
+= " --notksdevice"
154 retval
+= " --onboot=on"
155 if self
.wepkey
!= "":
156 retval
+= " --wepkey=%s" % self
.wepkey
160 class RepoData(BaseData
):
161 def __init__(self
, baseurl
="", mirrorlist
="", name
=""):
162 BaseData
.__init
__(self
)
163 self
.baseurl
= baseurl
164 self
.mirrorlist
= mirrorlist
169 urlopt
= "--baseurl=%s" % self
.baseurl
170 elif self
.mirrorlist
:
171 urlopt
= "--mirrorlist=%s" % self
.mirrorlist
173 return "repo --name=%s %s\n" % (self
.name
, urlopt
)
175 class UserData(BaseData
):
176 def __init__(self
, groups
=None, homedir
="", isCrypted
=False, name
="",
177 password
="", shell
="", uid
=None):
178 BaseData
.__init
__(self
)
184 self
.homedir
= homedir
185 self
.isCrypted
= isCrypted
187 self
.password
= password
194 if len(self
.groups
) > 0:
195 retval
+= " --groups=%s" % string
.join(self
.groups
, ",")
197 retval
+= " --homedir=%s" % self
.homedir
199 retval
+= " --name=%s" % self
.name
201 retval
+= " --password=%s" % self
.password
203 retval
+= " --isCrypted"
205 retval
+= " --shell=%s" % self
.shell
207 retval
+= " --uid=%s" % self
.uid
215 class DmRaid(KickstartCommand
):
216 def __init__(self
, writePriority
=60, dmraids
=None):
217 KickstartCommand
.__init
__(self
, writePriority
)
222 self
.dmraids
= dmraids
226 for dm
in self
.dmraids
:
227 retval
+= dm
.__str
__()
231 def parse(self
, args
):
232 op
= KSOptionParser(lineno
=self
.lineno
)
233 op
.add_option("--name", dest
="name", action
="store", type="string",
235 op
.add_option("--dev", dest
="devices", action
="append", type="string",
238 dm
= self
.handler
.DmRaidData()
239 (opts
, extra
) = op
.parse_args(args
=args
)
240 dm
.name
= dm
.name
.split('/')[-1]
241 self
._setToObj
(op
, opts
, dm
)
244 def add(self
, newObj
):
245 self
.dmraids
.append(newObj
)
247 class Iscsi(KickstartCommand
):
248 def __init__(self
, writePriority
=70, iscsi
=None):
249 KickstartCommand
.__init
__(self
, writePriority
)
258 for iscsi
in self
.iscsi
:
259 retval
+= iscsi
.__str
__()
263 def parse(self
, args
):
264 op
= KSOptionParser(lineno
=self
.lineno
)
265 op
.add_option("--target", dest
="ipaddr", action
="store", type="string")
266 op
.add_option("--ipaddr", dest
="ipaddr", action
="store", type="string",
268 op
.add_option("--port", dest
="port", action
="store", type="string")
269 op
.add_option("--user", dest
="user", action
="store", type="string")
270 op
.add_option("--password", dest
="password", action
="store",
273 (opts
, extra
) = op
.parse_args(args
=args
)
276 mapping
= {"command": "scsi", "options": extra
}
277 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("Unexpected arguments to %(command)s command: %(options)s") % mapping
)
279 dd
= self
.handler
.IscsiData()
280 self
._setToObj
(op
, opts
, dd
)
283 def add(self
, newObj
):
284 self
.iscsi
.append(newObj
)
286 class IscsiName(KickstartCommand
):
287 def __init__(self
, writePriority
=71, iscsiname
=""):
288 KickstartCommand
.__init
__(self
, writePriority
)
289 self
.iscsiname
= iscsiname
292 if self
.iscsiname
!= "":
293 return "iscsiname %s" % self
.iscsiname
297 def parse(self
, args
):
299 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("Command %s only takes one argument") % "iscsiname")
300 self
.iscsiname
= args
[0]
302 class Logging(KickstartCommand
):
303 def __init__(self
, writePriority
=0, host
="", level
="info", port
=""):
304 KickstartCommand
.__init
__(self
, writePriority
)
310 retval
= "# Installation logging level\nlogging --level=%s" % self
.level
313 retval
+= " --host=%s" % self
.host
316 retval
+= " --port=%s" % self
.port
320 def parse(self
, args
):
321 op
= KSOptionParser(lineno
=self
.lineno
)
322 op
.add_option("--host")
323 op
.add_option("--level", type="choice",
324 choices
=["debug", "info", "warning", "error", "critical"])
325 op
.add_option("--port")
327 (opts
, extra
) = op
.parse_args(args
=args
)
328 self
._setToSelf
(op
, opts
)
330 class Method(FC5Handler
.Method
):
331 def __init__(self
, writePriority
=0, method
=""):
332 FC5Handler
.Method
.__init
__(self
, writePriority
, method
)
335 if self
.method
== "cdrom":
336 return "# Use CDROM installation media\ncdrom\n"
337 elif self
.method
== "harddrive":
338 msg
= "# Use hard drive installation media\nharddrive --dir=%s" % self
.dir
340 if hasattr(self
, "biospart"):
341 return msg
+ " --biospart=%s\n" % getattr(self
, "biospart")
343 return msg
+ " --partition=%s\n" % getattr(self
, "partition")
344 elif self
.method
== "nfs":
345 retval
= "# Use NFS installation media\nnfs --server=%s --dir=%s" % (self
.server
, self
.dir)
346 if hasattr(self
, "opts"):
347 retval
+= " --opts=\"%s\"" % self
.opts
350 elif self
.method
== "url":
351 return "# Use network installation\nurl --url=%s\n" % self
.url
355 def parse(self
, args
):
356 op
= KSOptionParser(lineno
=self
.lineno
)
358 self
.method
= self
.currentCmd
360 if self
.currentCmd
== "cdrom":
362 elif self
.currentCmd
== "harddrive":
363 op
.add_option("--biospart", dest
="biospart")
364 op
.add_option("--partition", dest
="partition")
365 op
.add_option("--dir", dest
="dir", required
=1)
366 elif self
.currentCmd
== "nfs":
367 op
.add_option("--server", dest
="server", required
=1)
368 op
.add_option("--dir", dest
="dir", required
=1)
369 op
.add_option("--opts", dest
="opts")
370 elif self
.currentCmd
== "url":
371 op
.add_option("--url", dest
="url", required
=1)
373 (opts
, extra
) = op
.parse_args(args
=args
)
375 if self
.currentCmd
== "harddrive":
376 if (getattr(opts
, "biospart") == None and getattr(opts
, "partition") == None) or \
377 (getattr(opts
, "biospart") != None and getattr(opts
, "partition") != None):
379 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("One of biospart or partition options must be specified."))
381 self
._setToSelf
(op
, opts
)
383 class Monitor(FC5Handler
.Monitor
):
384 def __init__(self
, writePriority
=0, hsync
="", monitor
="", probe
=True,
386 FC5Handler
.Monitor
.__init
__(self
, writePriority
, hsync
=hsync
,
387 monitor
=monitor
, vsync
=vsync
)
394 retval
+= " --hsync=%s" % self
.hsync
395 if self
.monitor
!= "":
396 retval
+= " --monitor=\"%s\"" % self
.monitor
398 retval
+= " --noprobe"
400 retval
+= " --vsync=%s" % self
.vsync
402 if retval
!= "monitor":
407 def parse(self
, args
):
408 op
= KSOptionParser(lineno
=self
.lineno
)
409 op
.add_option("--hsync", dest
="hsync")
410 op
.add_option("--monitor", dest
="monitor")
411 op
.add_option("--noprobe", dest
="probe", action
="store_false",
413 op
.add_option("--vsync", dest
="vsync")
415 (opts
, extra
) = op
.parse_args(args
=args
)
418 mapping
= {"cmd": "monitor", "options": extra
}
419 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("Unexpected arguments to %(cmd)s command: %(options)s") % mapping
)
421 self
._setToSelf
(op
, opts
)
423 class MultiPath(KickstartCommand
):
424 def __init__(self
, writePriority
=50, mpaths
=None):
425 KickstartCommand
.__init
__(self
, writePriority
)
434 for mpath
in self
.mpaths
:
435 retval
+= mpath
.__str
__()
439 def parse(self
, args
):
440 op
= KSOptionParser(lineno
=self
.lineno
)
441 op
.add_option("--name", dest
="name", action
="store", type="string",
443 op
.add_option("--device", dest
="device", action
="store", type="string",
445 op
.add_option("--rule", dest
="rule", action
="store", type="string",
448 (opts
, extra
) = op
.parse_args(args
=args
)
449 dd
= self
.handler
.MpPathData()
450 self
._setToObj
(op
, opts
, dd
)
451 dd
.mpdev
= dd
.mpdev
.split('/')[-1]
454 for x
in range(0, len(self
.mpaths
)):
455 mpath
= self
.mpaths
[x
]
456 for path
in mpath
.paths
:
457 if path
.device
== dd
.device
:
458 mapping
= {"device": path
.device
, "multipathdev": path
.mpdev
}
459 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("Device '%(device)s' is already used in multipath '%(multipathdev)s'") % mapping
)
460 if mpath
.name
== dd
.mpdev
:
464 mpath
= self
.handler
.MultiPathData()
467 mpath
= self
.mpaths
[x
]
469 mpath
.paths
.append(dd
)
471 def add(self
, newObj
):
472 self
.mpaths
.append(newObj
)
474 class Network(FC5Handler
.Network
):
475 def __init__(self
, writePriority
=0, network
=None):
476 FC5Handler
.Network
.__init
__(self
, writePriority
, network
)
478 def parse(self
, args
):
479 op
= KSOptionParser(lineno
=self
.lineno
)
480 op
.add_option("--bootproto", dest
="bootProto", default
="dhcp",
481 choices
=["dhcp", "bootp", "static"])
482 op
.add_option("--class", dest
="dhcpclass")
483 op
.add_option("--device", dest
="device")
484 op
.add_option("--essid", dest
="essid")
485 op
.add_option("--ethtool", dest
="ethtool")
486 op
.add_option("--gateway", dest
="gateway")
487 op
.add_option("--hostname", dest
="hostname")
488 op
.add_option("--ip", dest
="ip")
489 op
.add_option("--noipv4", dest
="ipv4", action
="store_false",
491 op
.add_option("--noipv6", dest
="ipv6", action
="store_false",
493 op
.add_option("--mtu", dest
="mtu")
494 op
.add_option("--nameserver", dest
="nameserver")
495 op
.add_option("--netmask", dest
="netmask")
496 op
.add_option("--nodns", dest
="nodns", action
="store_true",
498 op
.add_option("--notksdevice", dest
="notksdevice", action
="store_true",
500 op
.add_option("--onboot", dest
="onboot", action
="store",
502 op
.add_option("--wepkey", dest
="wepkey")
504 (opts
, extra
) = op
.parse_args(args
=args
)
505 nd
= self
.handler
.NetworkData()
506 self
._setToObj
(op
, opts
, nd
)
509 class Reboot(FC5Handler
.Reboot
):
510 def __init__(self
, writePriority
=0, action
=KS_WAIT
, eject
=False):
511 FC5Handler
.Reboot
.__init
__(self
, writePriority
, action
=action
)
517 if self
.action
== KS_REBOOT
:
518 retval
= "# Reboot after installation\nreboot\n"
519 elif self
.action
== KS_SHUTDOWN
:
520 retval
= "# Shutdown after installation\nshutdown\n"
527 def parse(self
, args
):
528 if self
.currentCmd
== "reboot":
529 self
.action
= KS_REBOOT
531 self
.action
= KS_SHUTDOWN
533 op
= KSOptionParser(lineno
=self
.lineno
)
534 op
.add_option("--eject", dest
="eject", action
="store_true",
537 (opts
, extra
) = op
.parse_args(args
=args
)
538 self
._setToSelf
(op
, opts
)
540 class Repo(KickstartCommand
):
541 def __init__(self
, writePriority
=0, repoList
=None):
542 KickstartCommand
.__init
__(self
, writePriority
)
547 self
.repoList
= repoList
551 for repo
in self
.repoList
:
552 retval
+= repo
.__str
__()
556 def parse(self
, args
):
557 op
= KSOptionParser(lineno
=self
.lineno
)
558 op
.add_option("--name", dest
="name", required
=1)
559 op
.add_option("--baseurl")
560 op
.add_option("--mirrorlist")
562 (opts
, extra
) = op
.parse_args(args
=args
)
564 # This is lame, but I can't think of a better way to make sure only
565 # one of these two is specified.
566 if opts
.baseurl
and opts
.mirrorlist
:
567 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("Only one of --baseurl and --mirrorlist may be specified for repo command."))
569 if not opts
.baseurl
and not opts
.mirrorlist
:
570 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("One of --baseurl or --mirrorlist must be specified for repo command."))
572 rd
= self
.handler
.RepoData()
573 self
._setToObj
(op
, opts
, rd
)
576 def add(self
, newObj
):
577 self
.repoList
.append(newObj
)
579 class Services(KickstartCommand
):
580 def __init__(self
, writePriority
=0, disabled
=None, enabled
=None):
581 KickstartCommand
.__init
__(self
, writePriority
)
586 self
.disabled
= disabled
591 self
.enabled
= enabled
596 if len(self
.disabled
) > 0:
597 retval
+= " --disabled=%s" % string
.join(self
.disabled
, ",")
598 if len(self
.enabled
) > 0:
599 retval
+= " --enabled=%s" % string
.join(self
.enabled
, ",")
602 return "# System services\nservices %s\n" % retval
606 def parse(self
, args
):
607 def services_cb (option
, opt_str
, value
, parser
):
608 for d
in value
.split(','):
609 parser
.values
.ensure_value(option
.dest
, []).append(d
)
611 op
= KSOptionParser(lineno
=self
.lineno
)
612 op
.add_option("--disabled", dest
="disabled", action
="callback",
613 callback
=services_cb
, nargs
=1, type="string")
614 op
.add_option("--enabled", dest
="enabled", action
="callback",
615 callback
=services_cb
, nargs
=1, type="string")
617 (opts
, extra
) = op
.parse_args(args
=args
)
618 self
._setToSelf
(op
, opts
)
620 class User(KickstartCommand
):
621 def __init__(self
, writePriority
=0, userList
=None):
622 KickstartCommand
.__init
__(self
, writePriority
)
627 self
.userList
= userList
631 for user
in self
.userList
:
632 retval
+= user
.__str
__()
636 def parse(self
, args
):
637 def groups_cb (option
, opt_str
, value
, parser
):
638 for d
in value
.split(','):
639 parser
.values
.ensure_value(option
.dest
, []).append(d
)
641 op
= KSOptionParser(lineno
=self
.lineno
)
642 op
.add_option("--groups", dest
="groups", action
="callback",
643 callback
=groups_cb
, nargs
=1, type="string")
644 op
.add_option("--homedir")
645 op
.add_option("--iscrypted", dest
="isCrypted", action
="store_true",
647 op
.add_option("--name", required
=1)
648 op
.add_option("--password")
649 op
.add_option("--shell")
650 op
.add_option("--uid", type="int")
652 ud
= self
.handler
.UserData()
653 (opts
, extra
) = op
.parse_args(args
=args
)
654 self
._setToObj
(op
, opts
, ud
)
657 def add(self
, newObj
):
658 self
.userList
.append(newObj
)
660 class Vnc(KickstartCommand
):
661 def __init__(self
, writePriority
=0, enabled
=False, password
="", host
="",
663 KickstartCommand
.__init
__(self
, writePriority
)
664 self
.enabled
= enabled
665 self
.password
= password
673 retval
= "vnc --enabled %s" % self
.host
676 retval
+= " --port=%s" % self
.port
677 if self
.password
!= "":
678 retval
+= " --password=%s" % self
.password
682 def parse(self
, args
):
683 def connect_cb (option
, opt_str
, value
, parser
):
684 cargs
= value
.split(":")
685 parser
.values
.ensure_value("host", cargs
[0])
688 parser
.values
.ensure_value("port", cargs
[1])
690 op
= KSOptionParser(lineno
=self
.lineno
)
691 op
.add_option("--connect", action
="callback", callback
=connect_cb
,
692 nargs
=1, type="string", deprecated
=1)
693 op
.add_option("--password", dest
="password")
694 op
.add_option("--host", dest
="host")
695 op
.add_option("--port", dest
="port")
699 (opts
, extra
) = op
.parse_args(args
=args
)
700 self
._setToSelf
(op
, opts
)
702 class XConfig(KickstartCommand
):
703 def __init__(self
, writePriority
=0, driver
="", defaultdesktop
="", depth
=0,
704 resolution
="", startX
=False, videoRam
=""):
705 KickstartCommand
.__init
__(self
, writePriority
)
707 self
.defaultdesktop
= defaultdesktop
709 self
.resolution
= resolution
711 self
.videoRam
= videoRam
716 if self
.driver
!= "":
717 retval
+= " --driver=%s" % self
.driver
718 if self
.defaultdesktop
!= "":
719 retval
+= " --defaultdesktop=%s" % self
.defaultdesktop
721 retval
+= " --depth=%d" % self
.depth
722 if self
.resolution
!= "":
723 retval
+= " --resolution=%s" % self
.resolution
725 retval
+= " --startxonboot"
726 if self
.videoRam
!= "":
727 retval
+= " --videoram=%s" % self
.videoRam
730 retval
= "# X Window System configuration information\nxconfig %s\n" % retval
734 def parse(self
, args
):
735 op
= KSOptionParser(lineno
=self
.lineno
)
736 op
.add_option("--card", deprecated
=1)
737 op
.add_option("--driver", dest
="driver")
738 op
.add_option("--defaultdesktop", dest
="defaultdesktop")
739 op
.add_option("--depth", dest
="depth", action
="store", type="int",
741 op
.add_option("--hsync", deprecated
=1)
742 op
.add_option("--monitor", deprecated
=1)
743 op
.add_option("--noprobe", deprecated
=1)
744 op
.add_option("--resolution", dest
="resolution")
745 op
.add_option("--startxonboot", dest
="startX", action
="store_true",
747 op
.add_option("--videoram", dest
="videoRam")
748 op
.add_option("--vsync", deprecated
=1)
750 (opts
, extra
) = op
.parse_args(args
=args
)
752 mapping
= {"command": "xconfig", "options": extra
}
753 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("Unexpected arguments to %(command)s command: %(options)s") % mapping
)
755 self
._setToSelf
(op
, opts
)
758 FC5Handler
.__init
__(self
)
761 self
.registerCommand(self
.DmRaid(), ["dmraid"])
762 self
.registerCommand(self
.Iscsi(), ["iscsi"])
763 self
.registerCommand(self
.IscsiName(), ["iscsiname"])
764 self
.registerCommand(self
.Logging(), ["logging"])
765 self
.overrideCommand(self
.Method())
766 self
.overrideCommand(self
.Monitor())
767 self
.registerCommand(self
.MultiPath(), ["multipath"])
768 self
.overrideCommand(self
.Network())
769 self
.overrideCommand(self
.Reboot())
770 self
.registerCommand(self
.Repo(), ["repo"])
771 self
.registerCommand(self
.Services(), ["services"])
772 self
.registerCommand(self
.User(), ["user"])
773 self
.overrideCommand(self
.Vnc())
774 self
.overrideCommand(self
.XConfig())