/[smeserver]/cdrom.image/sme9/updates/storage/fcoe.py
ViewVC logotype

Annotation of /cdrom.image/sme9/updates/storage/fcoe.py

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (hide annotations) (download) (as text)
Sun Dec 22 04:27:51 2013 UTC (10 years, 10 months ago) by wellsi
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
Content type: text/x-python
FILE REMOVED
anaconda updates now handled via patches

1 charliebrady 1.1 #
2     # fcoe.py - fcoe class
3     #
4     # Copyright (C) 2009 Red Hat, Inc. All rights reserved.
5     #
6     # This program is free software; you can redistribute it and/or modify
7     # it under the terms of the GNU General Public License as published by
8     # the Free Software Foundation; either version 2 of the License, or
9     # (at your option) any later version.
10     #
11     # This program is distributed in the hope that it will be useful,
12     # but WITHOUT ANY WARRANTY; without even the implied warranty of
13     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     # GNU General Public License for more details.
15     #
16     # You should have received a copy of the GNU General Public License
17     # along with this program. If not, see <http://www.gnu.org/licenses/>.
18     #
19    
20     import os
21     import iutil
22     import isys
23     import logging
24     import time
25     from flags import flags
26     log = logging.getLogger("anaconda")
27    
28     import gettext
29     _ = lambda x: gettext.ldgettext("anaconda", x)
30    
31     _fcoe_module_loaded = False
32    
33     def has_fcoe():
34     global _fcoe_module_loaded
35     if not _fcoe_module_loaded:
36     iutil.execWithRedirect("modprobe", [ "fcoe" ],
37     stdout = "/dev/tty5", stderr="/dev/tty5")
38     _fcoe_module_loaded = True
39     if "bnx2x" in iutil.lsmod():
40     log.info("fcoe: loading bnx2fc")
41     iutil.execWithRedirect("modprobe", [ "bnx2fc" ],
42     stdout = "/dev/tty5", stderr="/dev/tty5")
43    
44     return os.access("/sys/module/fcoe", os.X_OK)
45    
46     class fcoe(object):
47     """ FCoE utility class.
48    
49     This class will automatically discover and connect to EDD configured
50     FCoE SAN's when the startup() method gets called. It can also be
51     used to manually configure FCoE SAN's through the addSan() method.
52    
53     As this class needs to make sure certain things like starting fcoe
54     daemons and connecting to firmware discovered SAN's only happens once
55     and as it keeps a global list of all FCoE devices it is
56     implemented as a Singleton.
57     """
58    
59     def __init__(self):
60     self.started = False
61     self.lldpadStarted = False
62     self.nics = []
63     self.ksnics = []
64    
65     # So that users can write fcoe() to get the singleton instance
66     def __call__(self):
67     return self
68    
69     def _stabilize(self, intf = None):
70     if intf:
71     w = intf.waitWindow(_("Connecting to FCoE SAN"),
72     _("Connecting to FCoE SAN"))
73    
74     # I have no clue how long we need to wait, this ought to do the trick
75     time.sleep(10)
76     iutil.execWithRedirect("udevadm", [ "settle" ],
77     stdout = "/dev/tty5", stderr="/dev/tty5")
78     if intf:
79     w.pop()
80    
81     def _startEDD(self, intf = None):
82     rc = iutil.execWithCapture("/usr/libexec/fcoe/fcoe_edd.sh", [ "-i" ],
83     stderr="/dev/tty5")
84     if not rc.startswith("NIC="):
85     log.info("No FCoE EDD info found: %s" % rc)
86     return
87    
88     (key, val) = rc.split("=", 1)
89     if val not in isys.getDeviceProperties():
90     log.error("Unknown FCoE NIC found in EDD: %s, ignoring" % val)
91     return
92    
93     log.info("FCoE NIC found in EDD: %s" % val)
94     self.addSan(val, dcb=True, auto_vlan=True, intf=intf)
95    
96     def startup(self, intf = None):
97     if self.started:
98     return
99    
100     if not has_fcoe():
101     return
102    
103     self._startEDD(intf)
104     self.started = True
105    
106     def _startLldpad(self):
107     if self.lldpadStarted:
108     return
109    
110     iutil.execWithRedirect("lldpad", [ "-d" ],
111     stdout = "/dev/tty5", stderr="/dev/tty5")
112     self.lldpadStarted = True
113    
114     def addSan(self, nic, dcb=False, auto_vlan=True, intf=None):
115     if not has_fcoe():
116     raise IOError, _("FCoE not available")
117    
118     log.info("Activating FCoE SAN attached to %s, dcb: %s autovlan: %s" %
119     (nic, dcb, auto_vlan))
120    
121     iutil.execWithRedirect("ip", [ "link", "set", nic, "up" ],
122     stdout = "/dev/tty5", stderr="/dev/tty5")
123    
124     if dcb:
125     self._startLldpad()
126     iutil.execWithRedirect("dcbtool", [ "sc", nic, "dcb", "on" ],
127     stdout = "/dev/tty5", stderr="/dev/tty5")
128     iutil.execWithRedirect("dcbtool", [ "sc", nic, "app:fcoe",
129     "e:1", "a:1", "w:1" ],
130     stdout = "/dev/tty5", stderr="/dev/tty5")
131     iutil.execWithRedirect("fipvlan", [ "-c", "-s", "-f",
132     "-fcoe", nic],
133     stdout = "/dev/tty5", stderr="/dev/tty5")
134     else:
135     if auto_vlan:
136     # certain network configrations require the VLAN layer module:
137     iutil.execWithRedirect("modprobe", ["8021q"],
138     stdout = "/dev/tty5", stderr="/dev/tty5")
139     iutil.execWithRedirect("fipvlan", ['-c', '-s', '-f',
140     "-fcoe", nic],
141     stdout = "/dev/tty5", stderr="/dev/tty5")
142     else:
143     f = open("/sys/module/libfcoe/parameters/create", "w")
144     f.write(nic)
145     f.close()
146    
147     self._stabilize(intf)
148     self.nics.append((nic, dcb, auto_vlan))
149    
150     def writeKS(self, f):
151     for nic, dcb, auto_vlan in self.nics:
152     if nic in self.ksnics:
153     line = "fcoe --nic %s" % nic
154     if dcb:
155     line += " --dcb"
156     if auto_vlan:
157     line += " --autovlan"
158     line += "\n"
159     f.write(line)
160    
161     def write(self, instPath, anaconda):
162     if not self.nics:
163     return
164    
165     if not os.path.isdir(instPath + "/etc/fcoe"):
166     os.makedirs(instPath + "/etc/fcoe", 0755)
167    
168     for nic, dcb, auto_vlan in self.nics:
169     fd = os.open(instPath + "/etc/fcoe/cfg-" + nic,
170     os.O_RDWR | os.O_CREAT)
171     os.write(fd, '# Created by anaconda\n')
172     os.write(fd, '# Enable/Disable FCoE service at the Ethernet port\n')
173     os.write(fd, 'FCOE_ENABLE="yes"\n')
174     os.write(fd, '# Indicate if DCB service is required at the Ethernet port\n')
175     if dcb:
176     os.write(fd, 'DCB_REQUIRED="yes"\n')
177     else:
178     os.write(fd, 'DCB_REQUIRED="no"\n')
179     os.write(fd, '# Indicate if VLAN discovery should be handled by fcoemon\n')
180     if auto_vlan:
181     os.write(fd, 'AUTO_VLAN="yes"\n')
182     else:
183     os.write(fd, 'AUTO_VLAN="no"\n')
184     os.close(fd)
185    
186     return
187    
188     # Create FCoE singleton
189     fcoe = fcoe()
190    
191     # vim:tw=78:ts=4:et:sw=4

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed