move pykickstart -> imgcreate.pykickstart
[pykickstart/EL-5.git] / pykickstart / commands / iscsi.py
blobe4edc74568afff5a3b69b845c61d9dcc9511d535
2 # Chris Lumens <clumens@redhat.com>
3 # Peter Jones <pjones@redhat.com>
5 # Copyright 2005, 2006, 2007 Red Hat, Inc.
7 # This copyrighted material is made available to anyone wishing to use, modify,
8 # copy, or redistribute it subject to the terms and conditions of the GNU
9 # General Public License v.2. This program is distributed in the hope that it
10 # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
11 # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 # See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc., 51
16 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat
17 # trademarks that are incorporated in the source code or documentation are not
18 # subject to the GNU General Public License and may only be used or replicated
19 # with the express permission of Red Hat, Inc.
21 from imgcreate.pykickstart.base import *
22 from imgcreate.pykickstart.errors import *
23 from imgcreate.pykickstart.options import *
25 import gettext
26 _ = lambda x: gettext.ldgettext("pykickstart", x)
28 class FC6_IscsiData(BaseData):
29 def __init__(self, ipaddr="", port="", target="", user=None, password=None):
30 BaseData.__init__(self)
31 self.ipaddr = ipaddr
32 self.port = port
33 self.target = target
34 self.user = user
35 self.password = password
37 def _getArgsAsStr(self):
38 retval = ""
40 if self.target != "":
41 retval += " --target=%s" % self.target
42 if self.ipaddr != "":
43 retval += " --ipaddr=%s" % self.ipaddr
44 if self.port != "":
45 retval += " --port=%s" % self.port
46 if self.user is not None:
47 retval += " --user=%s" % self.user
48 if self.password is not None:
49 retval += " --password=%s" % self.password
51 return retval
53 def __str__(self):
54 return "iscsi%s\n" % self._getArgsAsStr()
56 class F10_IscsiData(FC6_IscsiData):
57 def __init__(self, ipaddr="", port="", target="", user=None, password=None,
58 user_in=None, password_in=None):
59 FC6_IscsiData.__init__(self, ipaddr=ipaddr, port=port, user=user,
60 password=password)
61 self.user_in = user_in
62 self.password_in = password_in
64 def _getArgsAsStr(self):
65 retval = FC6_IscsiData._getArgsAsStr(self)
67 if self.user_in is not None:
68 retval += " --reverse-user=%s" % self.user_in
69 if self.password_in is not None:
70 retval += " --reverse-password=%s" % self.password_in
72 return retval
74 class FC6_Iscsi(KickstartCommand):
75 def __init__(self, writePriority=71, iscsi=None):
76 KickstartCommand.__init__(self, writePriority)
77 self.op = self._getParser()
79 if iscsi == None:
80 iscsi = []
82 self.iscsi = iscsi
84 def __str__(self):
85 retval = ""
86 for iscsi in self.iscsi:
87 retval += iscsi.__str__()
89 return retval
91 def _getParser(self):
92 op = KSOptionParser(lineno=self.lineno)
93 op.add_option("--target", dest="target", action="store", type="string")
94 op.add_option("--ipaddr", dest="ipaddr", action="store", type="string",
95 required=1)
96 op.add_option("--port", dest="port", action="store", type="string")
97 op.add_option("--user", dest="user", action="store", type="string")
98 op.add_option("--password", dest="password", action="store",
99 type="string")
100 return op
102 def parse(self, args):
103 (opts, extra) = self.op.parse_args(args=args)
105 if len(extra) != 0:
106 mapping = {"command": "scsi", "options": extra}
107 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Unexpected arguments to %(command)s command: %(options)s") % mapping)
109 dd = self.handler.IscsiData()
110 self._setToObj(self.op, opts, dd)
111 self.add(dd)
113 def add(self, newObj):
114 self.iscsi.append(newObj)
116 class F10_Iscsi(FC6_Iscsi):
117 def __init__(self, writePriority=71, iscsi=None):
118 FC6_Iscsi.__init__(self, writePriority, iscsi)
120 def _getParser(self):
121 op = FC6_Iscsi._getParser(self)
122 op.add_option("--reverse-user", dest="user_in", action="store",
123 type="string")
124 op.add_option("--reverse-password", dest="password_in", action="store",
125 type="string")
126 return op