Validate network interface name when parsing the kickstart (#1081982)
[pykickstart.git] / pykickstart / commands / vnc.py
blobeedfdc68af565bd3658a337722407f4d4c98dc98
2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2005, 2006, 2007 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 *
24 import gettext
25 _ = lambda x: gettext.ldgettext("pykickstart", x)
27 class FC3_Vnc(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.op = self._getParser()
35 self.enabled = kwargs.get("enabled", False)
36 self.password = kwargs.get("password", "")
37 self.connect = kwargs.get("connect", "")
39 def __str__(self):
40 retval = KickstartCommand.__str__(self)
42 if not self.enabled:
43 return retval
45 retval += "vnc"
47 if self.connect != "":
48 retval += " --connect=%s" % self.connect
49 if self.password != "":
50 retval += " --password=%s" % self.password
52 return retval + "\n"
54 def _getParser(self):
55 op = KSOptionParser()
56 op.add_option("--connect")
57 op.add_option("--password", dest="password")
58 return op
60 def parse(self, args):
61 self.enabled = True
62 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
63 self._setToSelf(self.op, opts)
64 return self
66 class FC6_Vnc(FC3_Vnc):
67 removedKeywords = FC3_Vnc.removedKeywords + ["connect"]
68 removedAttrs = FC3_Vnc.removedAttrs + ["connect"]
70 def __init__(self, writePriority=0, host="", port="", *args, **kwargs):
71 FC3_Vnc.__init__(self, writePriority, *args, **kwargs)
72 self.deleteRemovedAttrs()
74 self.host = kwargs.get("host", "")
75 self.port = kwargs.get("port", "")
77 def __str__(self):
78 retval = KickstartCommand.__str__(self)
80 if not self.enabled:
81 return retval
83 retval += "vnc"
85 if self.host != "":
86 retval += " --host=%s" % self.host
88 if self.port != "":
89 retval += " --port=%s" % self.port
90 if self.password != "":
91 retval += " --password=%s" % self.password
93 return retval + "\n"
95 def _getParser(self):
96 def connect_cb (option, opt_str, value, parser):
97 cargs = value.split(":")
98 parser.values.ensure_value("host", cargs[0])
100 if len(cargs) > 1:
101 parser.values.ensure_value("port", cargs[1])
103 op = FC3_Vnc._getParser(self)
104 op.add_option("--connect", action="callback", callback=connect_cb,
105 nargs=1, type="string")
106 op.add_option("--host", dest="host")
107 op.add_option("--port", dest="port")
108 return op
110 class F9_Vnc(FC6_Vnc):
111 removedKeywords = FC6_Vnc.removedKeywords
112 removedAttrs = FC6_Vnc.removedAttrs
114 def _getParser(self):
115 op = FC6_Vnc._getParser(self)
116 op.remove_option("--connect")
117 return op
119 class RHEL7_Vnc(F9_Vnc):
120 def parse(self, args):
121 F9_Vnc.parse(self, args)
123 if self.password and not 5 < len(self.password) < 9:
124 raise KickstartValueError(formatErrorMsg(self.lineno,
125 msg=_("VNC password must be six to eight characters long")))
127 return self