Add new RHEL7 logvol objects to master
[pykickstart.git] / pykickstart / commands / realm.py
blobc75ae10c70ac1542a4c93e99f982918d5da749e6
2 # Stef Walter <stefw@redhat.com>
4 # Copyright 2013 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.
21 from pykickstart.base import KickstartCommand
22 from pykickstart.errors import KickstartParseError, KickstartValueError, formatErrorMsg
24 import getopt
25 import pipes
26 import shlex
28 import gettext
29 _ = lambda x: gettext.ldgettext("pykickstart", x)
31 class F19_Realm(KickstartCommand):
32 removedKeywords = KickstartCommand.removedKeywords
33 removedAttrs = KickstartCommand.removedAttrs
35 def __init__(self, writePriority=0, *args, **kwargs):
36 KickstartCommand.__init__(self, *args, **kwargs)
37 self.join_realm = None
38 self.join_args = []
39 self.discover_options = []
41 def _parseArguments(self, string):
42 if self.join_realm:
43 raise KickstartParseError(formatErrorMsg(self.lineno, msg=_(
44 "The realm command 'join' should only be specified once")))
45 args = shlex.split(string)
46 if not args:
47 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_(
48 "Missing realm command arguments")))
49 command = args.pop(0)
50 if command == "join":
51 self._parseJoin(args)
52 else:
53 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_(
54 "Unsupported realm '%s' command" % command)))
56 def _parseJoin(self, args):
57 try:
58 # We only support these args
59 opts, remaining = getopt.getopt(args, "", ("client-software=",
60 "server-software=",
61 "membership-software=",
62 "one-time-password=",
63 "no-password",
64 "computer-ou="))
65 except getopt.GetoptError, ex:
66 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_(
67 "Invalid realm arguments: %s") % ex))
69 if len(remaining) != 1:
70 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_(
71 "Specify only one realm to join")))
73 # Parse successful, just use this as the join command
74 self.join_realm = remaining[0]
75 self.join_args = args
77 # Build a discovery command
78 self.discover_options = []
79 supported_discover_options = ("--client-software",
80 "--server-software",
81 "--membership-software")
82 for (o, a) in opts:
83 if o in supported_discover_options:
84 self.discover_options.append("%s=%s" % (o, a))
86 def _getCommandsAsStrings(self):
87 commands = []
88 if self.join_args:
89 args = [pipes.quote(arg) for arg in self.join_args]
90 commands.append("realm join " + " ".join(args))
91 return commands
93 def __str__(self):
94 retval = KickstartCommand.__str__(self)
96 commands = self._getCommandsAsStrings()
97 if commands:
98 retval += "# Realm or domain membership\n"
99 retval += "\n".join(commands)
100 retval += "\n"
102 return retval
104 def parse(self, args):
105 self._parseArguments(self.currentLine[len(self.currentCmd):].strip())
106 return self