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
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
39 self
.discover_options
= []
41 def _parseArguments(self
, string
):
43 raise KickstartParseError(formatErrorMsg(self
.lineno
, msg
=_(
44 "The realm command 'join' should only be specified once")))
45 args
= shlex
.split(string
)
47 raise KickstartValueError(formatErrorMsg(self
.lineno
, msg
=_(
48 "Missing realm command arguments")))
53 raise KickstartValueError(formatErrorMsg(self
.lineno
, msg
=_(
54 "Unsupported realm '%s' command" % command
)))
56 def _parseJoin(self
, args
):
58 # We only support these args
59 opts
, remaining
= getopt
.getopt(args
, "", ("client-software=",
61 "membership-software=",
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]
77 # Build a discovery command
78 self
.discover_options
= []
79 supported_discover_options
= ("--client-software",
81 "--membership-software")
83 if o
in supported_discover_options
:
84 self
.discover_options
.append("%s=%s" % (o
, a
))
86 def _getCommandsAsStrings(self
):
89 args
= [pipes
.quote(arg
) for arg
in self
.join_args
]
90 commands
.append("realm join " + " ".join(args
))
94 retval
= KickstartCommand
.__str
__(self
)
96 commands
= self
._getCommandsAsStrings
()
98 retval
+= "# Realm or domain membership\n"
99 retval
+= "\n".join(commands
)
104 def parse(self
, args
):
105 self
._parseArguments
(self
.currentLine
[len(self
.currentCmd
):].strip())