summaryrefslogtreecommitdiffstats
path: root/storage/fcoe.py
blob: 46c5bcb9c1f894e3c10aa468470483efdb110382 (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
#
# fcoe.py - fcoe class
#
# 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 os
import iutil
import logging
import time
log = logging.getLogger("anaconda")

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

_fcoe_module_loaded = False

def has_fcoe():
    global _fcoe_module_loaded
    if not _fcoe_module_loaded:
        iutil.execWithRedirect("modprobe", [ "fcoe" ],
                               stdout = "/dev/tty5", stderr="/dev/tty5",
                               searchPath = 1)
        _fcoe_module_loaded = True

    return os.access("/sys/module/fcoe", os.X_OK)

class fcoe(object):
    def __init__(self):
        self.started = False
        self.nics = []

    def _stabilize(self, intf = None):
        if intf:
            w = intf.waitWindow(_("Connecting to FCoE SAN"),
                                _("Connecting to FCoE SAN"))

        # I have no clue how long we need to wait, this ought to do the trick
        time.sleep(10)
        iutil.execWithRedirect("udevadm", [ "settle" ],
                               stdout = "/dev/tty5", stderr="/dev/tty5",
                               searchPath = 1)
        if intf:
            w.pop()

    def startup(self, intf = None):
        if self.started:
            return

        if not has_fcoe():
            return

        # Place holder for adding autodetection of FCoE setups based on
        # firmware tables (like iBFT for iSCSI)

        self.started = True

    def addSan(self, nic, intf=None):
        if not has_fcoe():
            raise IOError, _("FCoE not available")

        log.info("Activating FCoE SAN attached to %s" % nic)

        f = open("/sys/module/fcoe/parameters/create", "w")
        f.write(nic)
        f.close()

        self._stabilize(intf)
        self.nics.append(nic)

    def writeKS(self, f):
        # fixme plenty (including add ks support for fcoe in general)
        return

    def write(self, instPath, anaconda):
        # erm, do we need todo anything here ?
        return

# vim:tw=78:ts=4:et:sw=4