46
32
cfg.CONF.register_opts(ML2_BROCADE, "ml2_brocade")
48
LOG = logging.getLogger(__name__)
51
class BrocadeSVIPlugin(router.L3RouterPlugin):
52
"""Brocade SVI service Plugin."""
55
"""Initialize Brocade Plugin
57
Specify switch address and db configuration.
59
super(BrocadeSVIPlugin, self).__init__()
64
def brocade_init(self):
65
"""Brocade specific initialization."""
66
LOG.debug("brocadeSVIPlugin::brocade_init()")
68
self._switch = {'address': cfg.CONF.ml2_brocade.address,
69
'username': cfg.CONF.ml2_brocade.username,
70
'password': cfg.CONF.ml2_brocade.password,
71
'rbridge_id': cfg.CONF.ml2_brocade.rbridge_id
73
self._driver = driver.NOSdriver()
74
LOG.info(_LI("rbridge id %s"), self._switch['rbridge_id'])
76
def create_router(self, context, router):
77
"""Creates a vrf on NOS device."""
78
LOG.debug("BrocadeSVIPlugin.create_router called: ")
79
with context.session.begin(subtransactions=True):
80
new_router = super(BrocadeSVIPlugin, self).create_router(context,
85
self._driver.create_router(switch['address'],
89
str(new_router['id']))
91
with excutils.save_and_reraise_exception():
92
with context.session.begin(subtransactions=True):
93
super(BrocadeSVIPlugin, self).delete_router(
97
LOG.debug("BrocadeSVIPlugin.create_router: "
98
"router created on VDX switch")
101
def delete_router(self, context, router_id):
102
"""Delete a vrf on NOS device."""
103
router = super(BrocadeSVIPlugin, self).get_router(context, router_id)
104
super(BrocadeSVIPlugin, self).delete_router(context, router_id)
106
switch = self._switch
107
self._driver.delete_router(switch['address'],
110
switch['rbridge_id'],
113
def add_router_interface(self, context, router_id, interface_info):
114
"""creates svi on NOS device and assigns ip addres to SVI."""
115
LOG.debug("BrocadeSVIPlugin.add_router_interface on VDX: "
116
"router_id=%(router_id)s "
117
"interface_info=%(interface_info)r",
118
{'router_id': router_id, 'interface_info': interface_info})
120
with context.session.begin(subtransactions=True):
122
info = super(BrocadeSVIPlugin, self).add_router_interface(
123
context, router_id, interface_info)
125
port = db.get_port(context.session, info["port_id"])
127
# shutting down neutron port to allow NOS to do Arp/Routing
128
port['admin_state_up'] = False
130
self._core_plugin.update_port(context, info["port_id"], port)
132
interface_info = info
133
subnet = self._core_plugin._get_subnet(context,
134
interface_info["subnet_id"])
135
cidr = subnet["cidr"]
136
net_addr, net_len = self.net_addr(cidr)
137
gateway_ip = subnet["gateway_ip"]
138
network_id = subnet['network_id']
139
bnet = brocade_db.get_network(context, network_id)
140
vlan_id = bnet['vlan']
141
gateway_ip_cidr = gateway_ip + '/' + str(net_len)
142
LOG.debug("Allocated cidr %(cidr)s from the pool, "
143
"network_id %(net_id)s "
145
"vlan %(vlan_id)d ", {'cidr': gateway_ip_cidr,
146
'net_id': network_id,
148
'vlan_id': int(vlan_id)})
149
port_filters = {'network_id': [network_id],
150
'device_owner': [DEVICE_OWNER_ROUTER_INTF]}
151
port_count = self._core_plugin.get_ports_count(context,
153
LOG.info(_LI("BrocadeSVIPlugin.add_router_interface ports_count "
157
# port count is checked against 2 since the current port is already
160
# This subnet is already part of some router
161
# (this is not supported in this version of brocade svi plugin)
162
msg = _("BrocadeSVIPlugin: adding redundant router interface "
168
switch = self._switch
169
self._driver.create_svi(switch['address'],
172
switch['rbridge_id'],
177
LOG.error(_LE("Failed to create Brocade resources to add router "
178
"interface. info=%(info)s, router_id=%(router_id)s"),
179
{"info": info, "router_id": router_id})
180
with excutils.save_and_reraise_exception():
181
with context.session.begin(subtransactions=True):
182
self.remove_router_interface(context, router_id,
186
def remove_router_interface(self, context, router_id, interface_info):
187
"""Deletes svi from NOS device."""
188
LOG.debug("BrocadeSVIPlugin.remove_router_interface called: "
189
"router_id=%(router_id)s "
190
"interface_info=%(interface_info)r",
191
{'router_id': router_id, 'interface_info': interface_info})
193
with context.session.begin(subtransactions=True):
194
info = super(BrocadeSVIPlugin, self).remove_router_interface(
195
context, router_id, interface_info)
197
subnet = self._core_plugin._get_subnet(context,
199
cidr = subnet['cidr']
200
net_addr, net_len = self.net_addr(cidr)
201
gateway_ip = subnet['gateway_ip']
202
network_id = subnet['network_id']
203
bnet = brocade_db.get_network(context, network_id)
204
vlan_id = bnet['vlan']
205
gateway_ip_cidr = gateway_ip + '/' + str(net_len)
206
LOG.debug("remove_router_interface removed cidr %(cidr)s"
208
" network_id %(net_id)s bnet %(bnet)s"
210
{'cidr': gateway_ip_cidr,
211
'net_id': network_id,
213
'vlan_id': int(vlan_id)})
214
switch = self._switch
215
self._driver.delete_svi(switch['address'],
218
switch['rbridge_id'],
223
with excutils.save_and_reraise_exception():
224
LOG.error(_LE("Fail remove of interface from brocade "
225
"router interface. info=%(info)s, "
226
"router_id=%(router_id)s"),
227
{"info": info, "router_id": router_id})
232
"""Get network address prefix and length from a given address."""
235
nw_addr, nw_len = addr.split('/')
237
return nw_addr, nw_len