2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2007, 2009 Red Hat, Inc.
6 # This copyrighted material is made available to anyone wishing to use, modify,
7 # copy, or redistribute it subject to the terms and conditions of the GNU
8 # General Public License v.2. This program is distributed in the hope that it
9 # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
10 # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 # See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # this program; if not, write to the Free Software Foundation, Inc., 51
15 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat
16 # trademarks that are incorporated in the source code or documentation are not
17 # subject to the GNU General Public License and may only be used or replicated
18 # with the express permission of Red Hat, Inc.
20 from pykickstart.base import *
21 from pykickstart.errors import *
22 from pykickstart.options import *
25 _ = lambda x: gettext.ldgettext("pykickstart", x)
27 class FC3_Method(KickstartCommand):
28 removedKeywords = KickstartCommand.removedKeywords
29 removedAttrs = KickstartCommand.removedAttrs
31 def __init__(self, writePriority=0, *args, **kwargs):
32 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
33 self.method = kwargs.get("method", "")
35 # Set all these attributes so calls to this command's __call__
36 # method can set them. However we don't want to provide them as
37 # arguments to __init__ because method is special.
45 retval = KickstartCommand.__str__(self)
47 if self.method == "cdrom":
48 retval += "# Use CDROM installation media\ncdrom\n"
49 elif self.method == "harddrive":
50 msg = "# Use hard drive installation media\nharddrive --dir=%s" % self.dir
52 if self.biospart is not None:
53 retval += msg + " --biospart=%s\n" % self.biospart
55 retval += msg + " --partition=%s\n" % self.partition
56 elif self.method == "nfs":
57 retval += "# Use NFS installation media\nnfs --server=%s --dir=%s\n" % (self.server, self.dir)
58 elif self.method == "url":
59 retval += "# Use network installation\nurl --url=\"%s\"\n" % self.url
66 # method = "cdrom" falls through to the return
67 if self.currentCmd == "harddrive":
68 op.add_option("--biospart", dest="biospart")
69 op.add_option("--partition", dest="partition")
70 op.add_option("--dir", dest="dir", required=1)
71 elif self.currentCmd == "nfs":
72 op.add_option("--server", dest="server", required=1)
73 op.add_option("--dir", dest="dir", required=1)
74 elif self.currentCmd == "url":
75 op.add_option("--url", dest="url", required=1)
79 def parse(self, args):
80 self.method = self.currentCmd
82 op = self._getParser()
83 (opts, extra) = op.parse_args(args=args, lineno=self.lineno)
84 self._setToSelf(op, opts)
86 if self.currentCmd == "harddrive":
87 if self.biospart is None and self.partition is None or \
88 self.biospart is not None and self.partition is not None:
89 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("One of biospart or partition options must be specified."))
93 class FC6_Method(FC3_Method):
94 removedKeywords = FC3_Method.removedKeywords
95 removedAttrs = FC3_Method.removedAttrs
97 def __init__(self, writePriority=0, *args, **kwargs):
98 FC3_Method.__init__(self, writePriority, *args, **kwargs)
100 # Same reason for this attribute as the comment in FC3_Method.
104 retval = KickstartCommand.__str__(self)
106 if self.method == "cdrom":
107 retval += "# Use CDROM installation media\ncdrom\n"
108 elif self.method == "harddrive":
109 msg = "# Use hard drive installation media\nharddrive --dir=%s" % self.dir
111 if self.biospart is not None:
112 retval += msg + " --biospart=%s\n" % self.biospart
114 retval += msg + " --partition=%s\n" % self.partition
115 elif self.method == "nfs":
116 retval += "# Use NFS installation media\nnfs --server=%s --dir=%s" % (self.server, self.dir)
117 if self.opts is not None:
118 retval += " --opts=\"%s\"" % self.opts
120 elif self.method == "url":
121 retval += "# Use network installation\nurl --url=\"%s\"\n" % self.url
125 def _getParser(self):
126 op = FC3_Method._getParser(self)
128 if self.currentCmd == "nfs":
129 op.add_option("--opts", dest="opts")
133 class F13_Method(FC6_Method):
134 removedKeywords = FC6_Method.removedKeywords
135 removedAttrs = FC6_Method.removedAttrs
137 def __init__(self, *args, **kwargs):
138 FC6_Method.__init__(self, *args, **kwargs)
140 # And same as all the other __init__ methods.
144 retval = FC6_Method.__str__(self)
146 if self.method == "url" and self.proxy:
147 retval = retval.strip()
148 retval += " --proxy=\"%s\"\n" % self.proxy
152 def _getParser(self):
153 op = FC6_Method._getParser(self)
155 if self.currentCmd == "url":
156 op.add_option("--proxy")
160 class F14_Method(F13_Method):
161 removedKeywords = F13_Method.removedKeywords
162 removedAttrs = F13_Method.removedAttrs
164 def __init__(self, *args, **kwargs):
165 F13_Method.__init__(self, *args, **kwargs)
167 self.noverifyssl = False
170 retval = F13_Method.__str__(self)
172 if self.method == "url" and self.noverifyssl:
173 retval = retval.strip()
174 retval += " --noverifyssl\n"
178 def _getParser(self):
179 op = F13_Method._getParser(self)
181 if self.currentCmd == "url":
182 op.add_option("--noverifyssl", action="store_true", default=False)
186 RHEL6_Method = F14_Method