summaryrefslogtreecommitdiffstats
path: root/iw/advanced_storage.py
blob: 902d8ac4a4122fb71f75489ccd07c3ab72f21876 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#
# Copyright (C) 2009  Red Hat, Inc.  All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import gettext
_ = lambda x: gettext.ldgettext("anaconda", x)

# UI methods for supporting adding advanced storage devices.
import gobject
import gtk
import gtk.glade
import gui
import iutil
import network
import storage.fcoe
import storage.iscsi
from netconfig_dialog import NetworkConfigurator

def addFcoeDrive(anaconda):
    (dxml, dialog) = gui.getGladeWidget("fcoe-config.glade", "fcoeDialog")
    combo = dxml.get_widget("fcoeNicCombo")
    dcb_cb = dxml.get_widget("dcbCheckbutton")

    # Populate the combo
    cell = gtk.CellRendererText()
    combo.pack_start(cell, True)
    combo.set_attributes(cell, text = 0)
    cell.set_property("wrap-width", 525)
    combo.set_size_request(480, -1)
    store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
    combo.set_model(store)

    netdevs = anaconda.network.available()
    keys = netdevs.keys()
    keys.sort()
    selected_interface = None
    for dev in keys:
        # Skip NICs which are connected (iow in use for a net install)
        if dev in network.getActiveNetDevs():
            continue

        i = store.append(None)
        desc = netdevs[dev].get("DESC")
        if desc:
            desc = "%s - %s" %(dev, desc)
        else:
            desc = "%s" %(dev,)

        mac = netdevs[dev].get("HWADDR")
        if mac:
            desc = "%s - %s" %(desc, mac)

        if selected_interface is None:
            selected_interface = i

        store[i] = (desc, dev)

    if selected_interface:
        combo.set_active_iter(selected_interface)
    else:
        combo.set_active(0)

    # Show the dialog
    gui.addFrame(dialog)
    dialog.show_all()
    sg = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
    sg.add_widget(dxml.get_widget("fcoeNicCombo"))

    while True:
        rc = dialog.run()

        if rc in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT]:
            break

        iter = combo.get_active_iter()
        if iter is None:
            anaconda.intf.messageWindow(_("Error"),
                                        _("You must select a NIC to use."),
                                        type="warning", custom_icon="error")
            continue

        try:
            anaconda.storage.fcoe.addSan(store.get_value(iter, 1),
                                         dcb=dcb_cb.get_active(),
                                         intf=anaconda.intf)
        except IOError as e:
            anaconda.intf.messageWindow(_("Error"), str(e))
            rc = gtk.RESPONSE_CANCEL

        break

    dialog.destroy()
    return rc

def addIscsiDrive(anaconda):
    if not network.hasActiveNetDev():
        net = NetworkConfigurator(anaconda.network)
        ret = net.run()
        net.destroy()
        if ret != gtk.RESPONSE_OK:
            return ret

    (dxml, dialog) = gui.getGladeWidget("iscsi-config.glade", "iscsiDialog")
    gui.addFrame(dialog)
    dialog.show_all()
    sg = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
    for w in ["iscsiAddrEntry", "iscsiInitiatorEntry", "userEntry",
              "passEntry", "userinEntry", "passinEntry"]:
        sg.add_widget(dxml.get_widget(w))

    # get the initiator name if it exists and don't allow changing
    # once set
    e = dxml.get_widget("iscsiInitiatorEntry")
    e.set_text(anaconda.storage.iscsi.initiator)
    if anaconda.storage.iscsi.initiatorSet:
        e.set_sensitive(False)

    while True:
        rc = dialog.run()
        if rc in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT]:
            break

        initiator = e.get_text().strip()
        if len(initiator) == 0:
            anaconda.intf.messageWindow(_("Invalid Initiator Name"),
                                        _("You must provide an initiator name."))
            continue

        anaconda.storage.iscsi.initiator = initiator

        target = dxml.get_widget("iscsiAddrEntry").get_text().strip()
        user = dxml.get_widget("userEntry").get_text().strip()
        pw = dxml.get_widget("passEntry").get_text().strip()
        user_in = dxml.get_widget("userinEntry").get_text().strip()
        pw_in = dxml.get_widget("passinEntry").get_text().strip()

        try:
            count = len(target.split(":"))
            idx = target.rfind("]:")
            # Check for IPV6 [IPV6-ip]:port
            if idx != -1:
                ip = target[1:idx]
                port = target[idx+2:]
            # Check for IPV4 aaa.bbb.ccc.ddd:port
            elif count == 2:
                idx = target.rfind(":")
                ip = target[:idx]
                port = target[idx+1:]
            else:
                ip = target
                port = "3260"

            network.sanityCheckIPString(ip)
        except (network.IPMissing, network.IPError) as msg:
            anaconda.intf.messageWindow(_("Error with Data"), msg)
            continue

        try:
            anaconda.storage.iscsi.addTarget(ip, port, user, pw,
                                             user_in, pw_in,
                                             anaconda.intf)
        except ValueError as e:
            anaconda.intf.messageWindow(_("Error"), str(e))
            continue
        except IOError as e:
            anaconda.intf.messageWindow(_("Error"), str(e))
            rc = gtk.RESPONSE_CANCEL

        break

    dialog.destroy()
    return rc

def addZfcpDrive(anaconda):
    (dxml, dialog) = gui.getGladeWidget("zfcp-config.glade", "zfcpDialog")
    gui.addFrame(dialog)
    dialog.show_all()
    sg = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
    for w in ["devnumEntry", "wwpnEntry", "fcplunEntry"]:
        sg.add_widget(dxml.get_widget(w))

    while True:
        rc = dialog.run()
        if rc != gtk.RESPONSE_APPLY:
            break

        devnum = dxml.get_widget("devnumEntry").get_text().strip()
        wwpn = dxml.get_widget("wwpnEntry").get_text().strip()
        fcplun = dxml.get_widget("fcplunEntry").get_text().strip()

        try:
            anaconda.storage.zfcp.addFCP(devnum, wwpn, fcplun)
        except ValueError as e:
            anaconda.intf.messageWindow(_("Error"), str(e))
            continue

        break

    dialog.destroy()
    return rc

def addDrive(anaconda):
    (dxml, dialog) = gui.getGladeWidget("adddrive.glade", "addDriveDialog")
    gui.addFrame(dialog)
    dialog.show_all()
    if not iutil.isS390():
        dxml.get_widget("zfcpRadio").hide()
        dxml.get_widget("zfcpRadio").set_group(None)

    if not storage.iscsi.has_iscsi():
        dxml.get_widget("iscsiRadio").set_sensitive(False)
        dxml.get_widget("iscsiRadio").set_active(False)

    if not storage.fcoe.has_fcoe():
        dxml.get_widget("fcoeRadio").set_sensitive(False)
        dxml.get_widget("fcoeRadio").set_active(False)

    #figure out what advanced devices we have available and set sensible default
    group = dxml.get_widget("iscsiRadio").get_group()
    for button in group:
        if button is not None and button.get_property("sensitive"):
            button.set_active(True)
            break

    rc = dialog.run()
    dialog.hide()

    if rc in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT]:
        return False

    if dxml.get_widget("iscsiRadio").get_active() and storage.iscsi.has_iscsi():
        rc = addIscsiDrive(anaconda)
    elif dxml.get_widget("fcoeRadio").get_active() and storage.fcoe.has_fcoe():
        rc = addFcoeDrive(anaconda)
    elif dxml.get_widget("zfcpRadio") is not None and dxml.get_widget("zfcpRadio").get_active():
        rc = addZfcpDrive(anaconda)

    dialog.destroy()

    if rc in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT]:
        return False
    else:
        return True