30
30
from quantum.openstack.common import importutils
31
31
from quantum.plugins.cisco.common import cisco_constants as const
32
32
from quantum.plugins.cisco.common import cisco_credentials_v2 as cred
33
from quantum.plugins.cisco.common import cisco_exceptions as excep
33
from quantum.plugins.cisco.common import cisco_exceptions as cisco_exc
34
from quantum.plugins.cisco.common import config as conf
34
35
from quantum.plugins.cisco.db import network_db_v2 as cdb
35
36
from quantum.plugins.cisco.db import nexus_db_v2 as nxos_db
36
37
from quantum.plugins.cisco.l2device_plugin_base import L2DevicePluginBase
37
from quantum.plugins.cisco.nexus import cisco_nexus_configuration as conf
40
40
LOG = logging.getLogger(__name__)
43
43
class NexusPlugin(L2DevicePluginBase):
45
Nexus PLugIn Main Class
44
"""Nexus PlugIn Main Class."""
49
47
def __init__(self):
51
Extracts the configuration parameters from the configuration file
53
self._client = importutils.import_object(conf.NEXUS_DRIVER)
54
LOG.debug(_("Loaded driver %s"), conf.NEXUS_DRIVER)
55
self._nexus_switches = conf.NEXUS_DETAILS
48
"""Extract configuration parameters from the configuration file."""
49
self._client = importutils.import_object(conf.CISCO.nexus_driver)
50
LOG.debug(_("Loaded driver %s"), conf.CISCO.nexus_driver)
51
self._nexus_switches = conf.get_nexus_dictionary()
56
52
self.credentials = {}
58
54
def get_credential(self, nexus_ip):
77
73
def create_network(self, tenant_id, net_name, net_id, vlan_name, vlan_id,
80
Create a VLAN in the appropriate switch/port,
81
and configure the appropriate interfaces
77
Create a VLAN in the appropriate switch/port, and configure the
78
appropriate interfaces for this VLAN.
84
80
LOG.debug(_("NexusPlugin:create_network() called"))
85
81
# Grab the switch IP and port for this host
88
for switch in self._nexus_switches.keys():
89
for hostname in self._nexus_switches[switch].keys():
90
if str(hostname) == str(host):
92
port_id = self._nexus_switches[switch][hostname]['ports']
82
for switch_ip, attr in self._nexus_switches:
83
if str(attr) == str(host):
84
port_id = self._nexus_switches[switch_ip, attr]
87
raise cisco_exc.NexusComputeHostNotConfigured(host=host)
93
89
# Check if this network is already in the DB
94
binding = nxos_db.get_port_vlan_switch_binding(
95
port_id, vlan_id, switch_ip)
94
nxos_db.get_port_vlan_switch_binding(port_id, vlan_id, switch_ip)
95
except cisco_exc.NexusPortBindingNotFound:
97
96
_nexus_ip = switch_ip
98
97
_nexus_ports = (port_id,)
99
98
_nexus_ssh_port = \
100
self._nexus_switches[switch_ip]['ssh_port']['ssh_port']
99
self._nexus_switches[switch_ip, 'ssh_port']
101
100
_nexus_creds = self.get_credential(_nexus_ip)
102
101
_nexus_username = _nexus_creds['username']
103
102
_nexus_password = _nexus_creds['password']
104
103
# Check for vlan/switch binding
105
vbinding = nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
105
nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
106
except cisco_exc.NexusPortBindingNotFound:
107
107
# Create vlan and trunk vlan on the port
108
108
self._client.create_vlan(
109
109
vlan_name, str(vlan_id), _nexus_ip,
110
110
_nexus_username, _nexus_password,
111
111
_nexus_ports, _nexus_ssh_port, vlan_id)
113
114
# Only trunk vlan on the port
114
115
man = self._client.nxos_connect(_nexus_ip,
118
119
self._client.enable_vlan_on_trunk_int(man,
122
nxos_db.add_nexusport_binding(port_id, str(vlan_id),
125
nxos_db.add_nexusport_binding(port_id, str(vlan_id),
127
except Exception as e:
129
# Add binding failed, roll back any vlan creation/enabling
131
self._client.delete_vlan(
132
str(vlan_id), _nexus_ip,
133
_nexus_username, _nexus_password,
134
_nexus_ports, _nexus_ssh_port)
136
self._client.disable_vlan_on_trunk_int(man,
140
# Raise the original exception
124
143
new_net_dict = {const.NET_ID: net_id,
125
144
const.NET_NAME: net_name,
126
145
const.NET_PORTS: {},
130
149
return new_net_dict
132
151
def delete_network(self, tenant_id, net_id, **kwargs):
134
154
Deletes the VLAN in all switches, and removes the VLAN configuration
135
from the relevant interfaces
155
from the relevant interfaces.
137
157
LOG.debug(_("NexusPlugin:delete_network() called"))
139
159
def get_network_details(self, tenant_id, net_id, **kwargs):
141
Returns the details of a particular network
160
"""Return the details of a particular network."""
143
161
LOG.debug(_("NexusPlugin:get_network_details() called"))
144
162
network = self._get_network(tenant_id, net_id)
147
165
def update_network(self, tenant_id, net_id, **kwargs):
149
Updates the properties of a particular
166
"""Update the properties of a particular Virtual Network."""
152
167
LOG.debug(_("NexusPlugin:update_network() called"))
154
169
def get_all_ports(self, tenant_id, net_id, **kwargs):
156
172
This is probably not applicable to the Nexus plugin.
157
173
Delete if not required.
159
175
LOG.debug(_("NexusPlugin:get_all_ports() called"))
161
177
def create_port(self, tenant_id, net_id, port_state, port_id, **kwargs):
163
180
This is probably not applicable to the Nexus plugin.
164
181
Delete if not required.
166
183
LOG.debug(_("NexusPlugin:create_port() called"))
168
185
def delete_port(self, device_id, vlan_id):
170
Delete port bindings from the database and scan
171
whether the network is still required on
172
the interfaces trunked
188
Delete port bindings from the database and scan whether the network
189
is still required on the interfaces trunked.
174
191
LOG.debug(_("NexusPlugin:delete_port() called"))
175
192
# Delete DB row for this port
176
row = nxos_db.get_nexusvm_binding(vlan_id, device_id)
178
nxos_db.remove_nexusport_binding(row['port_id'], row['vlan_id'],
181
# Check for any other bindings with the same vlan_id and switch_ip
182
bindings = nxos_db.get_nexusvlan_binding(
183
row['vlan_id'], row['switch_ip'])
194
row = nxos_db.get_nexusvm_binding(vlan_id, device_id)
195
except cisco_exc.NexusPortBindingNotFound:
198
nxos_db.remove_nexusport_binding(row['port_id'], row['vlan_id'],
201
# Check for any other bindings with the same vlan_id and switch_ip
203
nxos_db.get_nexusvlan_binding(row['vlan_id'], row['switch_ip'])
204
except cisco_exc.NexusPortBindingNotFound:
186
206
# Delete this vlan from this switch
187
207
_nexus_ip = row['switch_ip']
188
208
_nexus_ports = (row['port_id'],)
190
self._nexus_switches[_nexus_ip]['ssh_port']['ssh_port']
209
_nexus_ssh_port = (self._nexus_switches[_nexus_ip,
191
211
_nexus_creds = self.get_credential(_nexus_ip)
192
212
_nexus_username = _nexus_creds['username']
193
213
_nexus_password = _nexus_creds['password']
195
215
str(row['vlan_id']), _nexus_ip,
196
216
_nexus_username, _nexus_password,
197
217
_nexus_ports, _nexus_ssh_port)
218
except Exception as e:
219
# The delete vlan operation on the Nexus failed,
220
# so this delete_port request has failed. For
221
# consistency, roll back the Nexus database to what
222
# it was before this request.
224
nxos_db.add_nexusport_binding(row['port_id'],
229
# Raise the original exception
199
return row['instance_id']
232
return row['instance_id']
201
234
def update_port(self, tenant_id, net_id, port_id, port_state, **kwargs):
203
237
This is probably not applicable to the Nexus plugin.
204
238
Delete if not required.
206
240
LOG.debug(_("NexusPlugin:update_port() called"))
208
242
def get_port_details(self, tenant_id, net_id, port_id, **kwargs):
210
245
This is probably not applicable to the Nexus plugin.
211
246
Delete if not required.
215
250
def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id,
218
254
This is probably not applicable to the Nexus plugin.
219
255
Delete if not required.
221
257
LOG.debug(_("NexusPlugin:plug_interface() called"))
223
259
def unplug_interface(self, tenant_id, net_id, port_id, **kwargs):
225
262
This is probably not applicable to the Nexus plugin.
226
263
Delete if not required.
230
267
def _get_vlan_id_for_network(self, tenant_id, network_id, context,
231
268
base_plugin_ref):
233
Obtain the VLAN ID given the Network ID
269
"""Obtain the VLAN ID given the Network ID."""
235
270
vlan = cdb.get_vlan_binding(network_id)
236
271
return vlan.vlan_id
238
273
def _get_network(self, tenant_id, network_id, context, base_plugin_ref):
274
"""Get the Network ID."""
242
275
network = base_plugin_ref._get_network(context, network_id)
244
277
raise exc.NetworkNotFound(net_id=network_id)