| 1 |
# Copyright (c) 2015 OpenStack Foundation |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 12 |
# implied. |
| 13 |
# See the License for the specific language governing permissions and |
| 14 |
# limitations under the License. |
| 15 |
from oslo_log import log as logging |
| 16 |
from oslo_utils import timeutils |
| 17 |
from sqlalchemy import asc |
| 18 |
from sqlalchemy.orm import exc |
| 19 |
|
| 20 |
from neutron_lib.db import api as db_api |
| 21 |
|
| 22 |
from networking_l2gw.db.l2gateway.ovsdb import models |
| 23 |
|
| 24 |
LOG = logging.getLogger(__name__) |
| 25 |
|
| 26 |
|
| 27 |
def add_vlan_binding(context, record_dict): |
| 28 |
"""Insert a vlan binding of a given physical port.""" |
| 29 |
session = context.session |
| 30 |
with db_api.CONTEXT_WRITER.using(context): |
| 31 |
binding = models.VlanBindings( |
| 32 |
port_uuid=record_dict['port_uuid'], |
| 33 |
vlan=record_dict['vlan'], |
| 34 |
logical_switch_uuid=record_dict['logical_switch_uuid'], |
| 35 |
ovsdb_identifier=record_dict['ovsdb_identifier']) |
| 36 |
session.add(binding) |
| 37 |
|
| 38 |
|
| 39 |
def delete_vlan_binding(context, record_dict): |
| 40 |
"""Delete vlan bindings of a given physical port.""" |
| 41 |
session = context.session |
| 42 |
with db_api.CONTEXT_WRITER.using(context): |
| 43 |
if (record_dict['vlan'] is not None and |
| 44 |
record_dict['logical_switch_uuid']): |
| 45 |
session.query(models.VlanBindings).filter_by( |
| 46 |
port_uuid=record_dict['port_uuid'], vlan=record_dict['vlan'], |
| 47 |
logical_switch_uuid=record_dict['logical_switch_uuid'], |
| 48 |
ovsdb_identifier=record_dict['ovsdb_identifier']).delete() |
| 49 |
|
| 50 |
|
| 51 |
def add_physical_locator(context, record_dict): |
| 52 |
"""Insert a new physical locator.""" |
| 53 |
session = context.session |
| 54 |
with db_api.CONTEXT_WRITER.using(context): |
| 55 |
locator = models.PhysicalLocators( |
| 56 |
uuid=record_dict['uuid'], |
| 57 |
dst_ip=record_dict['dst_ip'], |
| 58 |
ovsdb_identifier=record_dict['ovsdb_identifier']) |
| 59 |
session.add(locator) |
| 60 |
|
| 61 |
|
| 62 |
def delete_physical_locator(context, record_dict): |
| 63 |
"""Delete physical locator that matches the supplied uuid.""" |
| 64 |
session = context.session |
| 65 |
with db_api.CONTEXT_WRITER.using(context): |
| 66 |
if record_dict['uuid']: |
| 67 |
session.query(models.PhysicalLocators).filter_by( |
| 68 |
uuid=record_dict['uuid'], |
| 69 |
ovsdb_identifier=record_dict['ovsdb_identifier']).delete() |
| 70 |
|
| 71 |
|
| 72 |
def add_physical_switch(context, record_dict): |
| 73 |
"""Insert a new physical switch.""" |
| 74 |
session = context.session |
| 75 |
with db_api.CONTEXT_WRITER.using(context): |
| 76 |
physical_switch = models.PhysicalSwitches( |
| 77 |
uuid=record_dict['uuid'], |
| 78 |
name=record_dict['name'], |
| 79 |
tunnel_ip=record_dict['tunnel_ip'], |
| 80 |
ovsdb_identifier=record_dict['ovsdb_identifier'], |
| 81 |
switch_fault_status=record_dict['switch_fault_status']) |
| 82 |
session.add(physical_switch) |
| 83 |
|
| 84 |
|
| 85 |
def delete_physical_switch(context, record_dict): |
| 86 |
"""Delete physical switch that matches the supplied uuid.""" |
| 87 |
session = context.session |
| 88 |
with db_api.CONTEXT_WRITER.using(context): |
| 89 |
if record_dict['uuid']: |
| 90 |
session.query(models.PhysicalSwitches).filter_by( |
| 91 |
uuid=record_dict['uuid'], |
| 92 |
ovsdb_identifier=record_dict['ovsdb_identifier']).delete() |
| 93 |
|
| 94 |
|
| 95 |
def add_logical_switch(context, record_dict): |
| 96 |
"""Insert a new logical switch.""" |
| 97 |
session = context.session |
| 98 |
with db_api.CONTEXT_WRITER.using(context): |
| 99 |
logical_switch = models.LogicalSwitches( |
| 100 |
uuid=record_dict['uuid'], |
| 101 |
name=record_dict['name'], |
| 102 |
key=record_dict['key'], |
| 103 |
ovsdb_identifier=record_dict['ovsdb_identifier']) |
| 104 |
session.add(logical_switch) |
| 105 |
|
| 106 |
|
| 107 |
def delete_logical_switch(context, record_dict): |
| 108 |
"""delete logical switch that matches the supplied uuid.""" |
| 109 |
session = context.session |
| 110 |
with db_api.CONTEXT_WRITER.using(context): |
| 111 |
if record_dict['uuid']: |
| 112 |
session.query(models.LogicalSwitches).filter_by( |
| 113 |
uuid=record_dict['uuid'], |
| 114 |
ovsdb_identifier=record_dict['ovsdb_identifier']).delete() |
| 115 |
|
| 116 |
|
| 117 |
def add_physical_port(context, record_dict): |
| 118 |
"""Insert a new physical port.""" |
| 119 |
session = context.session |
| 120 |
with db_api.CONTEXT_WRITER.using(context): |
| 121 |
physical_port = models.PhysicalPorts( |
| 122 |
uuid=record_dict['uuid'], |
| 123 |
name=record_dict['name'], |
| 124 |
physical_switch_id=record_dict['physical_switch_id'], |
| 125 |
ovsdb_identifier=record_dict['ovsdb_identifier'], |
| 126 |
port_fault_status=record_dict['port_fault_status']) |
| 127 |
session.add(physical_port) |
| 128 |
|
| 129 |
|
| 130 |
def update_physical_ports_status(context, record_dict): |
| 131 |
"""Update physical port fault status.""" |
| 132 |
with db_api.CONTEXT_WRITER.using(context): |
| 133 |
(context.session.query(models.PhysicalPorts). |
| 134 |
filter(models.PhysicalPorts.uuid == record_dict['uuid']). |
| 135 |
update({'port_fault_status': record_dict['port_fault_status']}, |
| 136 |
synchronize_session=False)) |
| 137 |
|
| 138 |
|
| 139 |
def update_physical_switch_status(context, record_dict): |
| 140 |
"""Update physical switch fault status.""" |
| 141 |
with context.session.begin(): |
| 142 |
(context.session.query(models.PhysicalSwitches). |
| 143 |
filter(models.PhysicalSwitches.uuid == record_dict['uuid']). |
| 144 |
update({'switch_fault_status': record_dict['switch_fault_status']}, |
| 145 |
synchronize_session=False)) |
| 146 |
|
| 147 |
|
| 148 |
def delete_physical_port(context, record_dict): |
| 149 |
"""Delete physical port that matches the supplied uuid.""" |
| 150 |
session = context.session |
| 151 |
with db_api.CONTEXT_WRITER.using(context): |
| 152 |
if record_dict['uuid']: |
| 153 |
session.query(models.PhysicalPorts).filter_by( |
| 154 |
uuid=record_dict['uuid'], |
| 155 |
ovsdb_identifier=record_dict['ovsdb_identifier']).delete() |
| 156 |
|
| 157 |
|
| 158 |
def add_ucast_mac_local(context, record_dict): |
| 159 |
"""Insert a new ucast mac local.""" |
| 160 |
session = context.session |
| 161 |
with db_api.CONTEXT_WRITER.using(context): |
| 162 |
ucast_mac_local = models.UcastMacsLocals( |
| 163 |
uuid=record_dict['uuid'], |
| 164 |
mac=record_dict['mac'], |
| 165 |
logical_switch_id=record_dict['logical_switch_id'], |
| 166 |
physical_locator_id=record_dict['physical_locator_id'], |
| 167 |
ip_address=record_dict['ip_address'], |
| 168 |
ovsdb_identifier=record_dict['ovsdb_identifier']) |
| 169 |
session.add(ucast_mac_local) |
| 170 |
|
| 171 |
|
| 172 |
def delete_ucast_mac_local(context, record_dict): |
| 173 |
"""Delete ucast mac local that matches the supplied uuid.""" |
| 174 |
session = context.session |
| 175 |
with db_api.CONTEXT_WRITER.using(context): |
| 176 |
if record_dict['uuid']: |
| 177 |
session.query(models.UcastMacsLocals).filter_by( |
| 178 |
uuid=record_dict['uuid'], |
| 179 |
ovsdb_identifier=record_dict['ovsdb_identifier']).delete() |
| 180 |
|
| 181 |
|
| 182 |
def add_ucast_mac_remote(context, record_dict): |
| 183 |
"""Insert a new ucast mac remote.""" |
| 184 |
session = context.session |
| 185 |
with db_api.CONTEXT_WRITER.using(context): |
| 186 |
ucast_mac_remote = models.UcastMacsRemotes( |
| 187 |
uuid=record_dict['uuid'], |
| 188 |
mac=record_dict['mac'], |
| 189 |
logical_switch_id=record_dict['logical_switch_id'], |
| 190 |
physical_locator_id=record_dict['physical_locator_id'], |
| 191 |
ip_address=record_dict['ip_address'], |
| 192 |
ovsdb_identifier=record_dict['ovsdb_identifier']) |
| 193 |
session.add(ucast_mac_remote) |
| 194 |
|
| 195 |
|
| 196 |
def update_ucast_mac_remote(context, rec_dict): |
| 197 |
"""Update ucast mac remote.""" |
| 198 |
try: |
| 199 |
with db_api.CONTEXT_WRITER.using(context): |
| 200 |
(context.session.query(models.UcastMacsRemotes).filter_by( |
| 201 |
uuid=rec_dict['uuid'], |
| 202 |
ovsdb_identifier=rec_dict['ovsdb_identifier']).update( |
| 203 |
{'physical_locator_id': rec_dict['physical_locator_id'], |
| 204 |
'ip_address': rec_dict['ip_address']}, |
| 205 |
synchronize_session=False)) |
| 206 |
except exc.NoResultFound: |
| 207 |
LOG.debug('no Remote mac found for %s and %s', |
| 208 |
rec_dict['uuid'], |
| 209 |
rec_dict['ovsdb_identifier']) |
| 210 |
|
| 211 |
|
| 212 |
def delete_ucast_mac_remote(context, record_dict): |
| 213 |
"""Delete ucast mac remote that matches the supplied uuid.""" |
| 214 |
session = context.session |
| 215 |
with db_api.CONTEXT_WRITER.using(context): |
| 216 |
if record_dict['uuid']: |
| 217 |
session.query(models.UcastMacsRemotes).filter_by( |
| 218 |
uuid=record_dict['uuid'], |
| 219 |
ovsdb_identifier=record_dict['ovsdb_identifier']).delete() |
| 220 |
|
| 221 |
|
| 222 |
def get_physical_port(context, record_dict): |
| 223 |
"""Get physical port that matches the uuid and ovsdb_identifier.""" |
| 224 |
try: |
| 225 |
with db_api.CONTEXT_READER.using(context): |
| 226 |
query = context.session.query(models.PhysicalPorts) |
| 227 |
physical_port = query.filter_by( |
| 228 |
uuid=record_dict['uuid'], |
| 229 |
ovsdb_identifier=record_dict['ovsdb_identifier']).one() |
| 230 |
except exc.NoResultFound: |
| 231 |
LOG.debug('no physical port found for %s and %s', |
| 232 |
record_dict['uuid'], |
| 233 |
record_dict['ovsdb_identifier']) |
| 234 |
return |
| 235 |
return physical_port |
| 236 |
|
| 237 |
|
| 238 |
def get_logical_switch(context, record_dict): |
| 239 |
"""Get logical switch that matches the uuid and ovsdb_identifier.""" |
| 240 |
try: |
| 241 |
with db_api.CONTEXT_READER.using(context): |
| 242 |
query = context.session.query(models.LogicalSwitches) |
| 243 |
logical_switch = query.filter_by( |
| 244 |
uuid=record_dict['uuid'], |
| 245 |
ovsdb_identifier=record_dict['ovsdb_identifier']).one() |
| 246 |
except exc.NoResultFound: |
| 247 |
LOG.debug('no logical switch found for %s and %s', |
| 248 |
record_dict['uuid'], |
| 249 |
record_dict['ovsdb_identifier']) |
| 250 |
return |
| 251 |
return logical_switch |
| 252 |
|
| 253 |
|
| 254 |
def get_all_logical_switches_by_name(context, name): |
| 255 |
"""Get logical switch that matches the supplied name.""" |
| 256 |
with db_api.CONTEXT_READER.using(context): |
| 257 |
query = context.session.query(models.LogicalSwitches) |
| 258 |
return query.filter_by(name=name).all() |
| 259 |
|
| 260 |
|
| 261 |
def get_ucast_mac_remote(context, record_dict): |
| 262 |
"""Get ucast macs remote that matches the uuid and ovsdb_identifier.""" |
| 263 |
try: |
| 264 |
with db_api.CONTEXT_READER.using(context): |
| 265 |
query = context.session.query(models.UcastMacsRemotes) |
| 266 |
remote_mac = query.filter_by( |
| 267 |
uuid=record_dict['uuid'], |
| 268 |
ovsdb_identifier=record_dict['ovsdb_identifier']).one() |
| 269 |
except exc.NoResultFound: |
| 270 |
LOG.debug('no Remote mac found for %s and %s', |
| 271 |
record_dict['uuid'], |
| 272 |
record_dict['ovsdb_identifier']) |
| 273 |
return |
| 274 |
return remote_mac |
| 275 |
|
| 276 |
|
| 277 |
def get_ucast_mac_local(context, record_dict): |
| 278 |
"""Get ucast macs local that matches the uuid and ovsdb_identifier.""" |
| 279 |
try: |
| 280 |
with db_api.CONTEXT_READER.using(context): |
| 281 |
query = context.session.query(models.UcastMacsLocals) |
| 282 |
local_mac = query.filter_by( |
| 283 |
uuid=record_dict['uuid'], |
| 284 |
ovsdb_identifier=record_dict['ovsdb_identifier']).one() |
| 285 |
except exc.NoResultFound: |
| 286 |
LOG.debug('no Local mac found for %s and %s', |
| 287 |
record_dict['uuid'], |
| 288 |
record_dict['ovsdb_identifier']) |
| 289 |
return |
| 290 |
return local_mac |
| 291 |
|
| 292 |
|
| 293 |
def get_ucast_mac_remote_by_mac_and_ls(context, record_dict): |
| 294 |
"""Get ucast macs remote that matches the MAC address and |
| 295 |
|
| 296 |
ovsdb_identifier. |
| 297 |
""" |
| 298 |
try: |
| 299 |
with db_api.CONTEXT_READER.using(context): |
| 300 |
query = context.session.query(models.UcastMacsRemotes) |
| 301 |
remote_mac = query.filter_by( |
| 302 |
mac=record_dict['mac'], |
| 303 |
ovsdb_identifier=record_dict['ovsdb_identifier'], |
| 304 |
logical_switch_id=record_dict['logical_switch_uuid']).one() |
| 305 |
except exc.NoResultFound: |
| 306 |
LOG.debug('no Remote mac found for %s and %s', |
| 307 |
record_dict['mac'], |
| 308 |
record_dict['logical_switch_uuid']) |
| 309 |
return |
| 310 |
return remote_mac |
| 311 |
|
| 312 |
|
| 313 |
def get_physical_switch(context, record_dict): |
| 314 |
"""Get physical switch that matches the uuid and ovsdb_identifier.""" |
| 315 |
try: |
| 316 |
with db_api.CONTEXT_READER.using(context): |
| 317 |
query = context.session.query(models.PhysicalSwitches) |
| 318 |
physical_switch = query.filter_by( |
| 319 |
uuid=record_dict['uuid'], |
| 320 |
ovsdb_identifier=record_dict['ovsdb_identifier']).one() |
| 321 |
except exc.NoResultFound: |
| 322 |
LOG.debug('no physical switch found for %s and %s', |
| 323 |
record_dict['uuid'], |
| 324 |
record_dict['ovsdb_identifier']) |
| 325 |
return |
| 326 |
return physical_switch |
| 327 |
|
| 328 |
|
| 329 |
def get_physical_locator(context, record_dict): |
| 330 |
"""Get physical locator that matches the supplied uuid.""" |
| 331 |
try: |
| 332 |
with db_api.CONTEXT_READER.using(context): |
| 333 |
query = context.session.query(models.PhysicalLocators) |
| 334 |
physical_locator = query.filter_by( |
| 335 |
uuid=record_dict['uuid'], |
| 336 |
ovsdb_identifier=record_dict['ovsdb_identifier']).one() |
| 337 |
except exc.NoResultFound: |
| 338 |
LOG.debug('no physical locator found for %s and %s', |
| 339 |
record_dict['uuid'], |
| 340 |
record_dict['ovsdb_identifier']) |
| 341 |
return |
| 342 |
return physical_locator |
| 343 |
|
| 344 |
|
| 345 |
def get_physical_locator_by_dst_ip(context, record_dict): |
| 346 |
"""Get physical locator that matches the supplied destination IP.""" |
| 347 |
try: |
| 348 |
with db_api.CONTEXT_READER.using(context): |
| 349 |
query = context.session.query(models.PhysicalLocators) |
| 350 |
physical_locator = query.filter_by( |
| 351 |
dst_ip=record_dict['dst_ip'], |
| 352 |
ovsdb_identifier=record_dict['ovsdb_identifier']).one() |
| 353 |
except exc.NoResultFound: |
| 354 |
LOG.debug('no physical locator found for %s and %s', |
| 355 |
record_dict['dst_ip'], |
| 356 |
record_dict['ovsdb_identifier']) |
| 357 |
return |
| 358 |
return physical_locator |
| 359 |
|
| 360 |
|
| 361 |
def get_logical_switch_by_name(context, record_dict): |
| 362 |
"""Get logical switch that matches the supplied name.""" |
| 363 |
try: |
| 364 |
with db_api.CONTEXT_READER.using(context): |
| 365 |
query = context.session.query(models.LogicalSwitches) |
| 366 |
logical_switch = query.filter_by( |
| 367 |
name=record_dict['logical_switch_name'], |
| 368 |
ovsdb_identifier=record_dict['ovsdb_identifier']).one() |
| 369 |
except exc.NoResultFound: |
| 370 |
LOG.debug('no logical switch found for %s and %s', |
| 371 |
record_dict['logical_switch_name'], |
| 372 |
record_dict['ovsdb_identifier']) |
| 373 |
return |
| 374 |
return logical_switch |
| 375 |
|
| 376 |
|
| 377 |
def get_all_vlan_bindings_by_physical_port(context, record_dict): |
| 378 |
"""Get vlan bindings that matches the supplied physical port.""" |
| 379 |
with db_api.CONTEXT_READER.using(context): |
| 380 |
query = context.session.query(models.VlanBindings) |
| 381 |
return query.filter_by( |
| 382 |
port_uuid=record_dict['uuid'], |
| 383 |
ovsdb_identifier=record_dict['ovsdb_identifier']).all() |
| 384 |
|
| 385 |
|
| 386 |
def get_vlan_binding(context, record_dict): |
| 387 |
"""Get vlan bindings that matches the supplied physical port.""" |
| 388 |
try: |
| 389 |
with db_api.CONTEXT_READER.using(context): |
| 390 |
query = context.session.query(models.VlanBindings) |
| 391 |
vlan_binding = query.filter_by( |
| 392 |
port_uuid=record_dict['port_uuid'], |
| 393 |
vlan=record_dict['vlan'], |
| 394 |
logical_switch_uuid=record_dict['logical_switch_uuid'], |
| 395 |
ovsdb_identifier=record_dict['ovsdb_identifier']).one() |
| 396 |
except exc.NoResultFound: |
| 397 |
LOG.debug('no vlan binding found for %s and %s', |
| 398 |
record_dict['port_uuid'], |
| 399 |
record_dict['ovsdb_identifier']) |
| 400 |
return |
| 401 |
return vlan_binding |
| 402 |
|
| 403 |
|
| 404 |
def get_physical_switch_by_name(context, name): |
| 405 |
"""Get logical switch that matches the supplied name.""" |
| 406 |
with db_api.CONTEXT_READER.using(context): |
| 407 |
query = context.session.query(models.PhysicalSwitches) |
| 408 |
return query.filter_by(name=name).first() |
| 409 |
|
| 410 |
|
| 411 |
def get_physical_port_by_name_and_ps(context, record_dict): |
| 412 |
"""Get vlan bindings that matches the supplied physical port.""" |
| 413 |
try: |
| 414 |
with db_api.CONTEXT_READER.using(context): |
| 415 |
query = context.session.query(models.PhysicalPorts) |
| 416 |
physical_port = query.filter_by( |
| 417 |
name=record_dict['interface_name'], |
| 418 |
physical_switch_id=record_dict['physical_switch_id'], |
| 419 |
ovsdb_identifier=record_dict['ovsdb_identifier']).one() |
| 420 |
except exc.NoResultFound: |
| 421 |
LOG.debug('no physical port found for %s and %s', |
| 422 |
record_dict['physical_switch_id'], |
| 423 |
record_dict['interface_name']) |
| 424 |
return |
| 425 |
return physical_port |
| 426 |
|
| 427 |
|
| 428 |
def get_all_physical_switches_by_ovsdb_id(context, ovsdb_identifier): |
| 429 |
"""Get Physical Switches that match the supplied ovsdb identifier.""" |
| 430 |
with db_api.CONTEXT_READER.using(context): |
| 431 |
query = context.session.query(models.PhysicalSwitches) |
| 432 |
return query.filter_by( |
| 433 |
ovsdb_identifier=ovsdb_identifier).all() |
| 434 |
|
| 435 |
|
| 436 |
def get_all_logical_switches_by_ovsdb_id(context, ovsdb_identifier): |
| 437 |
"""Get logical Switches that match the supplied ovsdb identifier.""" |
| 438 |
with db_api.CONTEXT_READER.using(context): |
| 439 |
query = context.session.query(models.LogicalSwitches) |
| 440 |
return query.filter_by( |
| 441 |
ovsdb_identifier=ovsdb_identifier).all() |
| 442 |
|
| 443 |
|
| 444 |
def get_all_vlan_bindings_by_logical_switch(context, record_dict): |
| 445 |
"""Get Vlan bindings that match the supplied logical switch.""" |
| 446 |
with db_api.CONTEXT_READER.using(context): |
| 447 |
query = context.session.query(models.VlanBindings) |
| 448 |
return query.filter_by( |
| 449 |
logical_switch_uuid=record_dict['logical_switch_id'], |
| 450 |
ovsdb_identifier=record_dict['ovsdb_identifier']).all() |
| 451 |
|
| 452 |
|
| 453 |
def add_pending_ucast_mac_remote(context, operation, |
| 454 |
ovsdb_identifier, |
| 455 |
logical_switch_id, |
| 456 |
physical_locator, |
| 457 |
mac_remotes): |
| 458 |
"""Insert a pending ucast_mac_remote (insert/update/delete).""" |
| 459 |
session = context.session |
| 460 |
with db_api.CONTEXT_WRITER.using(context): |
| 461 |
for mac in mac_remotes: |
| 462 |
pending_mac = models.PendingUcastMacsRemote( |
| 463 |
uuid=mac.get('uuid', None), |
| 464 |
mac=mac['mac'], |
| 465 |
logical_switch_uuid=logical_switch_id, |
| 466 |
vm_ip=mac['ip_address'], |
| 467 |
ovsdb_identifier=ovsdb_identifier, |
| 468 |
operation=operation, |
| 469 |
timestamp=timeutils.utcnow()) |
| 470 |
if physical_locator: |
| 471 |
pending_mac['dst_ip'] = physical_locator.get('dst_ip', None) |
| 472 |
pending_mac['locator_uuid'] = physical_locator.get('uuid', |
| 473 |
None) |
| 474 |
session.add(pending_mac) |
| 475 |
|
| 476 |
|
| 477 |
def delete_pending_ucast_mac_remote(context, operation, |
| 478 |
ovsdb_identifier, |
| 479 |
logical_switch_id, |
| 480 |
mac_remote): |
| 481 |
"""Delete a pending ucast_mac_remote.""" |
| 482 |
session = context.session |
| 483 |
with db_api.CONTEXT_WRITER.using(context): |
| 484 |
if (mac_remote and logical_switch_id and |
| 485 |
ovsdb_identifier and operation): |
| 486 |
query = session.query(models.PendingUcastMacsRemote).filter_by( |
| 487 |
mac=mac_remote, |
| 488 |
ovsdb_identifier=ovsdb_identifier, |
| 489 |
logical_switch_uuid=logical_switch_id, |
| 490 |
operation=operation) |
| 491 |
row_count = query.count() |
| 492 |
query.delete() |
| 493 |
return row_count |
| 494 |
|
| 495 |
|
| 496 |
def get_pending_ucast_mac_remote(context, ovsdb_identifier, mac, |
| 497 |
logical_switch_uuid): |
| 498 |
"""Get pending mac that matches the supplied parameters.""" |
| 499 |
try: |
| 500 |
query = context.session.query(models.PendingUcastMacsRemote) |
| 501 |
pending_mac = query.filter_by( |
| 502 |
ovsdb_identifier=ovsdb_identifier, |
| 503 |
logical_switch_uuid=logical_switch_uuid, |
| 504 |
mac=mac).one() |
| 505 |
return pending_mac |
| 506 |
except exc.NoResultFound: |
| 507 |
return |
| 508 |
|
| 509 |
|
| 510 |
def get_all_pending_remote_macs_in_asc_order(context, ovsdb_identifier): |
| 511 |
"""Get all the pending remote macs in ascending order of timestamp.""" |
| 512 |
with db_api.CONTEXT_READER.using(context): |
| 513 |
session = context.session |
| 514 |
return session.query( |
| 515 |
models.PendingUcastMacsRemote).filter_by( |
| 516 |
ovsdb_identifier=ovsdb_identifier).order_by( |
| 517 |
asc(models.PendingUcastMacsRemote.timestamp)).all() |
| 518 |
|
| 519 |
|
| 520 |
def get_all_ucast_mac_remote_by_ls(context, record_dict): |
| 521 |
"""Get ucast macs remote that matches ls_id and ovsdb_identifier.""" |
| 522 |
with db_api.CONTEXT_READER.using(context): |
| 523 |
session = context.session |
| 524 |
return session.query(models.UcastMacsRemotes).filter_by( |
| 525 |
ovsdb_identifier=record_dict['ovsdb_identifier'], |
| 526 |
logical_switch_id=record_dict['logical_switch_id']).all() |
| 527 |
|
| 528 |
|
| 529 |
def delete_all_physical_locators_by_ovsdb_identifier(context, |
| 530 |
ovsdb_identifier): |
| 531 |
"""Delete all physical locators based on ovsdb identifier.""" |
| 532 |
session = context.session |
| 533 |
with db_api.CONTEXT_WRITER.using(context): |
| 534 |
session.query(models.PhysicalLocators).filter_by( |
| 535 |
ovsdb_identifier=ovsdb_identifier).delete() |
| 536 |
|
| 537 |
|
| 538 |
def delete_all_physical_switches_by_ovsdb_identifier(context, |
| 539 |
ovsdb_identifier): |
| 540 |
"""Delete all physical switches based on ovsdb identifier.""" |
| 541 |
session = context.session |
| 542 |
with db_api.CONTEXT_WRITER.using(context): |
| 543 |
session.query(models.PhysicalSwitches).filter_by( |
| 544 |
ovsdb_identifier=ovsdb_identifier).delete() |
| 545 |
|
| 546 |
|
| 547 |
def delete_all_physical_ports_by_ovsdb_identifier(context, |
| 548 |
ovsdb_identifier): |
| 549 |
"""Delete all physical ports based on ovsdb identifier.""" |
| 550 |
session = context.session |
| 551 |
with db_api.CONTEXT_WRITER.using(context): |
| 552 |
session.query(models.PhysicalPorts).filter_by( |
| 553 |
ovsdb_identifier=ovsdb_identifier).delete() |
| 554 |
|
| 555 |
|
| 556 |
def delete_all_logical_switches_by_ovsdb_identifier(context, |
| 557 |
ovsdb_identifier): |
| 558 |
"""Delete all physical switches based on ovsdb identifier.""" |
| 559 |
session = context.session |
| 560 |
with db_api.CONTEXT_WRITER.using(context): |
| 561 |
session.query(models.LogicalSwitches).filter_by( |
| 562 |
ovsdb_identifier=ovsdb_identifier).delete() |
| 563 |
|
| 564 |
|
| 565 |
def delete_all_ucast_macs_locals_by_ovsdb_identifier(context, |
| 566 |
ovsdb_identifier): |
| 567 |
"""Delete all ucast mac locals based on ovsdb identifier.""" |
| 568 |
session = context.session |
| 569 |
with db_api.CONTEXT_WRITER.using(context): |
| 570 |
session.query(models.UcastMacsLocals).filter_by( |
| 571 |
ovsdb_identifier=ovsdb_identifier).delete() |
| 572 |
|
| 573 |
|
| 574 |
def delete_all_ucast_macs_remotes_by_ovsdb_identifier(context, |
| 575 |
ovsdb_identifier): |
| 576 |
"""Delete all ucast mac remotes based on ovsdb identifier.""" |
| 577 |
session = context.session |
| 578 |
with db_api.CONTEXT_WRITER.using(context): |
| 579 |
session.query(models.UcastMacsRemotes).filter_by( |
| 580 |
ovsdb_identifier=ovsdb_identifier).delete() |
| 581 |
|
| 582 |
|
| 583 |
def delete_all_vlan_bindings_by_ovsdb_identifier(context, |
| 584 |
ovsdb_identifier): |
| 585 |
"""Delete all vlan bindings based on ovsdb identifier.""" |
| 586 |
session = context.session |
| 587 |
with db_api.CONTEXT_WRITER.using(context): |
| 588 |
session.query(models.VlanBindings).filter_by( |
| 589 |
ovsdb_identifier=ovsdb_identifier).delete() |