| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
from oslo_config import cfg |
| 21 |
from oslo_log import log as logging |
| 22 |
|
| 23 |
from os_vif import exception as osv_exception |
| 24 |
from os_vif.internal.ip.api import ip as ip_lib |
| 25 |
from os_vif import objects |
| 26 |
from os_vif import plugin |
| 27 |
|
| 28 |
from vif_plug_ovs import constants |
| 29 |
from vif_plug_ovs import exception |
| 30 |
from vif_plug_ovs import linux_net |
| 31 |
from vif_plug_ovs.ovsdb import api as ovsdb_api |
| 32 |
from vif_plug_ovs.ovsdb import ovsdb_lib |
| 33 |
|
| 34 |
LOG = logging.getLogger(__name__) |
| 35 |
|
| 36 |
|
| 37 |
def is_trunk_bridge(bridge_name): |
| 38 |
return bridge_name.startswith(constants.TRUNK_BR_PREFIX) |
| 39 |
|
| 40 |
|
| 41 |
class OvsPlugin(plugin.PluginBase): |
| 42 |
"""An OVS plugin that can setup VIFs in many ways |
| 43 |
|
| 44 |
The OVS plugin supports several different VIF types, VIFBridge |
| 45 |
and VIFOpenVSwitch, and will choose the appropriate plugging |
| 46 |
action depending on the type of VIF config it receives. |
| 47 |
|
| 48 |
If given a VIFBridge, then it will create connect the VM via |
| 49 |
a regular Linux bridge device to allow security group rules to |
| 50 |
be applied to VM traffic. |
| 51 |
""" |
| 52 |
|
| 53 |
NIC_NAME_LEN = 14 |
| 54 |
|
| 55 |
CONFIG_OPTS = ( |
| 56 |
cfg.IntOpt('network_device_mtu', |
| 57 |
default=1500, |
| 58 |
help='MTU setting for network interface.', |
| 59 |
deprecated_group="DEFAULT"), |
| 60 |
cfg.IntOpt('ovs_vsctl_timeout', |
| 61 |
default=120, |
| 62 |
help='Amount of time, in seconds, that ovs_vsctl should ' |
| 63 |
'wait for a response from the database. 0 is to wait ' |
| 64 |
'forever.', |
| 65 |
deprecated_group="DEFAULT"), |
| 66 |
cfg.StrOpt('ovsdb_connection', |
| 67 |
default='tcp:127.0.0.1:6640', |
| 68 |
help='The connection string for the OVSDB backend. ' |
| 69 |
'When executing commands using the native or vsctl ' |
| 70 |
'ovsdb interface drivers this config option defines ' |
| 71 |
'the ovsdb endpoint used.'), |
| 72 |
cfg.StrOpt('ovsdb_interface', |
| 73 |
choices=list(ovsdb_api.interface_map), |
| 74 |
default='native', |
| 75 |
deprecated_for_removal=True, |
| 76 |
deprecated_since='2.2.0', |
| 77 |
deprecated_reason=""" |
| 78 |
os-vif has supported ovsdb access via python bindings |
| 79 |
since Stein (1.15.0), starting in Victoria (2.2.0) the |
| 80 |
ovs-vsctl driver is now deprecated for removal and |
| 81 |
in future releases it will be be removed. |
| 82 |
""", |
| 83 |
help='The interface for interacting with the OVSDB'), |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
cfg.BoolOpt('isolate_vif', default=False, |
| 98 |
help='Controls if VIF should be isolated when plugged ' |
| 99 |
'to the ovs bridge. This should only be set to True ' |
| 100 |
'when using the neutron ovs ml2 agent.'), |
| 101 |
cfg.BoolOpt('per_port_bridge', default=False, |
| 102 |
help='Controls if VIF should be plugged into a per-port ' |
| 103 |
'bridge. This is experimental and controls the plugging ' |
| 104 |
'behavior when not using hybrid-plug.' |
| 105 |
'This is only used on linux and should be set to false ' |
| 106 |
'in all other cases such as ironic smartnic ports.'), |
| 107 |
cfg.StrOpt('default_qos_type', |
| 108 |
choices=[ |
| 109 |
'linux-htb', 'linux-hfsc', 'linux-sfq', 'linux-codel', |
| 110 |
'linux-fq_codel', 'linux-noop' |
| 111 |
], |
| 112 |
default='linux-noop', |
| 113 |
help=""" |
| 114 |
The default qos type to apply to ovs ports. |
| 115 |
linux-noop is the default. ovs will not modify |
| 116 |
the qdisc on the port if linux-noop is specified. |
| 117 |
This allows operators to manage QOS out of band |
| 118 |
of OVS. For more information see the ovs man pages |
| 119 |
https://manpages.debian.org/testing/openvswitch-common/ovs-vswitchd.conf.db.5.en.html#type~4 |
| 120 |
|
| 121 |
Note: This will only be set when a port is first created |
| 122 |
on the ovs bridge to ensure that the qos type can be |
| 123 |
managed via neutron if required for bandwidth limiting |
| 124 |
and other use-cases. |
| 125 |
"""), |
| 126 |
) |
| 127 |
|
| 128 |
def __init__(self, config): |
| 129 |
super(OvsPlugin, self).__init__(config) |
| 130 |
self.ovsdb = ovsdb_lib.BaseOVS(self.config) |
| 131 |
|
| 132 |
@staticmethod |
| 133 |
def gen_port_name(prefix, vif_id, max_length=NIC_NAME_LEN): |
| 134 |
return ("%s%s" % (prefix, vif_id))[:max_length] |
| 135 |
|
| 136 |
@staticmethod |
| 137 |
def get_veth_pair_names(vif): |
| 138 |
return (OvsPlugin.gen_port_name("qvb", vif.id), |
| 139 |
OvsPlugin.gen_port_name("qvo", vif.id)) |
| 140 |
|
| 141 |
def describe(self): |
| 142 |
pp_ovs = objects.host_info.HostPortProfileInfo( |
| 143 |
profile_object_name=objects.vif.VIFPortProfileOpenVSwitch.__name__, |
| 144 |
min_version="1.0", |
| 145 |
max_version="1.0", |
| 146 |
) |
| 147 |
pp_ovs_representor = objects.host_info.HostPortProfileInfo( |
| 148 |
profile_object_name=objects.vif.VIFPortProfileOVSRepresentor.__name__, |
| 149 |
min_version="1.0", |
| 150 |
max_version="1.0", |
| 151 |
) |
| 152 |
return objects.host_info.HostPluginInfo( |
| 153 |
plugin_name=constants.PLUGIN_NAME, |
| 154 |
vif_info=[ |
| 155 |
objects.host_info.HostVIFInfo( |
| 156 |
vif_object_name=objects.vif.VIFBridge.__name__, |
| 157 |
min_version="1.0", |
| 158 |
max_version="1.0", |
| 159 |
supported_port_profiles=[pp_ovs]), |
| 160 |
objects.host_info.HostVIFInfo( |
| 161 |
vif_object_name=objects.vif.VIFOpenVSwitch.__name__, |
| 162 |
min_version="1.0", |
| 163 |
max_version="1.0", |
| 164 |
supported_port_profiles=[pp_ovs]), |
| 165 |
objects.host_info.HostVIFInfo( |
| 166 |
vif_object_name=objects.vif.VIFVHostUser.__name__, |
| 167 |
min_version="1.0", |
| 168 |
max_version="1.0", |
| 169 |
supported_port_profiles=[pp_ovs, pp_ovs_representor]), |
| 170 |
objects.host_info.HostVIFInfo( |
| 171 |
vif_object_name=objects.vif.VIFHostDevice.__name__, |
| 172 |
min_version="1.0", |
| 173 |
max_version="1.0", |
| 174 |
supported_port_profiles=[pp_ovs, pp_ovs_representor]), |
| 175 |
]) |
| 176 |
|
| 177 |
def _get_mtu(self, vif): |
| 178 |
if vif.network and vif.network.mtu: |
| 179 |
return vif.network.mtu |
| 180 |
return self.config.network_device_mtu |
| 181 |
|
| 182 |
def supports_tc_qdisc(self, vif) -> bool: |
| 183 |
if self._get_vif_datapath_type(vif) != constants.OVS_DATAPATH_SYSTEM: |
| 184 |
return False |
| 185 |
return True |
| 186 |
|
| 187 |
def _isolate_vif(self, vif_name, bridge): |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
return (self.config.isolate_vif and |
| 192 |
not self.ovsdb.port_exists(vif_name, bridge)) |
| 193 |
|
| 194 |
def _create_vif_port(self, vif, vif_name, instance_info, **kwargs): |
| 195 |
mtu = self._get_mtu(vif) |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
bridge = kwargs.pop('bridge', vif.network.bridge) |
| 209 |
|
| 210 |
if (self._isolate_vif(vif_name, bridge) and |
| 211 |
not is_trunk_bridge(bridge)): |
| 212 |
kwargs['tag'] = constants.DEAD_VLAN |
| 213 |
kwargs['vlan_mode'] = 'trunk' |
| 214 |
kwargs['trunks'] = constants.DEAD_VLAN |
| 215 |
qos_type = self._get_qos_type(vif) |
| 216 |
if qos_type is not None: |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
if not self.ovsdb.port_exists(vif_name, bridge): |
| 227 |
kwargs['qos_type'] = qos_type |
| 228 |
self.ovsdb.create_ovs_vif_port( |
| 229 |
bridge, |
| 230 |
vif_name, |
| 231 |
vif.port_profile.interface_id, |
| 232 |
vif.address, instance_info.uuid, |
| 233 |
mtu=mtu, |
| 234 |
**kwargs) |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
profile = vif.port_profile |
| 239 |
create_tap = ( |
| 240 |
isinstance(profile, objects.vif.VIFPortProfileOpenVSwitch) and |
| 241 |
'create_tap' in profile.fields and |
| 242 |
'create_tap' in profile and |
| 243 |
profile.create_tap |
| 244 |
) |
| 245 |
|
| 246 |
if create_tap: |
| 247 |
|
| 248 |
if not isinstance(vif, objects.vif.VIFOpenVSwitch): |
| 249 |
raise exception.TapCreationNotSupported( |
| 250 |
vif_type=vif.__class__.__name__) |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
multiqueue = ('multiqueue' in profile.fields and |
| 256 |
'multiqueue' in profile and |
| 257 |
profile.multiqueue) |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
if not ip_lib.exists(vif_name): |
| 262 |
linux_net.create_tap( |
| 263 |
vif_name, mtu, vif.address, multiqueue=multiqueue) |
| 264 |
|
| 265 |
def _update_vif_port(self, vif, vif_name): |
| 266 |
mtu = self._get_mtu(vif) |
| 267 |
self.ovsdb.update_ovs_vif_port(vif_name, mtu) |
| 268 |
|
| 269 |
def _delete_tap_if_required(self, vif, vif_name): |
| 270 |
"""Delete tap device if it was created via create_tap flag. |
| 271 |
|
| 272 |
:param vif: VIF object |
| 273 |
:param vif_name: Name of the tap device |
| 274 |
""" |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
profile = getattr(vif, 'port_profile', None) |
| 279 |
create_tap = ( |
| 280 |
profile is not None and |
| 281 |
isinstance(profile, objects.vif.VIFPortProfileOpenVSwitch) and |
| 282 |
isinstance(vif, objects.vif.VIFOpenVSwitch) and |
| 283 |
'create_tap' in profile.fields and |
| 284 |
'create_tap' in profile and |
| 285 |
profile.create_tap |
| 286 |
) |
| 287 |
|
| 288 |
if create_tap and ip_lib.exists(vif_name): |
| 289 |
linux_net.delete_net_dev(vif_name) |
| 290 |
|
| 291 |
@staticmethod |
| 292 |
def _get_vif_datapath_type(vif, datapath=constants.OVS_DATAPATH_SYSTEM): |
| 293 |
profile = vif.port_profile |
| 294 |
if 'datapath_type' not in profile or not profile.datapath_type: |
| 295 |
return datapath |
| 296 |
return profile.datapath_type |
| 297 |
|
| 298 |
def _plug_vhostuser(self, vif, instance_info): |
| 299 |
vif_name = OvsPlugin.gen_port_name( |
| 300 |
constants.OVS_VHOSTUSER_PREFIX, vif.id) |
| 301 |
args = {} |
| 302 |
args['datapath_type'] = self._get_vif_datapath_type(vif, |
| 303 |
datapath=constants.OVS_DATAPATH_NETDEV) |
| 304 |
if vif.mode == "client": |
| 305 |
args['interface_type'] = \ |
| 306 |
constants.OVS_VHOSTUSER_INTERFACE_TYPE |
| 307 |
else: |
| 308 |
args['interface_type'] = \ |
| 309 |
constants.OVS_VHOSTUSER_CLIENT_INTERFACE_TYPE |
| 310 |
args['vhost_server_path'] = vif.path |
| 311 |
|
| 312 |
self._create_vif_port( |
| 313 |
vif, vif_name, instance_info, **args) |
| 314 |
|
| 315 |
def _plug_bridge(self, vif, instance_info): |
| 316 |
"""Plug using hybrid strategy |
| 317 |
|
| 318 |
Create a per-VIF linux bridge, then link that bridge to the OVS |
| 319 |
integration bridge via a veth device, setting up the other end |
| 320 |
of the veth device just like a normal OVS port. Then boot the |
| 321 |
VIF on the linux bridge using standard libvirt mechanisms. |
| 322 |
""" |
| 323 |
|
| 324 |
v1_name, v2_name = self.get_veth_pair_names(vif) |
| 325 |
|
| 326 |
linux_net.ensure_bridge(vif.bridge_name) |
| 327 |
|
| 328 |
mtu = self._get_mtu(vif) |
| 329 |
if not ip_lib.exists(v2_name): |
| 330 |
linux_net.create_veth_pair(v1_name, v2_name, mtu) |
| 331 |
linux_net.add_bridge_port(vif.bridge_name, v1_name) |
| 332 |
self.ovsdb.ensure_ovs_bridge(vif.network.bridge, |
| 333 |
self._get_vif_datapath_type(vif)) |
| 334 |
self._create_vif_port(vif, v2_name, instance_info) |
| 335 |
else: |
| 336 |
linux_net.update_veth_pair(v1_name, v2_name, mtu) |
| 337 |
self._update_vif_port(vif, v2_name) |
| 338 |
|
| 339 |
def _plug_port_bridge(self, vif, instance_info): |
| 340 |
"""Create a per-VIF OVS bridge and patch pair.""" |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
port_bridge_name = self.gen_port_name('pb', vif.id) |
| 345 |
port_bridge_patch = self.gen_port_name('pbp', vif.id, max_length=64) |
| 346 |
int_bridge_name = vif.network.bridge |
| 347 |
int_bridge_patch = self.gen_port_name('ibp', vif.id, max_length=64) |
| 348 |
|
| 349 |
self.ovsdb.ensure_ovs_bridge( |
| 350 |
int_bridge_name, self._get_vif_datapath_type(vif)) |
| 351 |
self.ovsdb.ensure_ovs_bridge( |
| 352 |
port_bridge_name, self._get_vif_datapath_type(vif)) |
| 353 |
self._create_vif_port( |
| 354 |
vif, vif.vif_name, instance_info, bridge=port_bridge_name, |
| 355 |
set_ids=False |
| 356 |
) |
| 357 |
tag = (constants.DEAD_VLAN |
| 358 |
if self._isolate_vif(int_bridge_patch, int_bridge_name) |
| 359 |
else None) |
| 360 |
iface_id = vif.id |
| 361 |
mac = vif.address |
| 362 |
instance_id = instance_info.uuid |
| 363 |
LOG.debug( |
| 364 |
'creating patch port pair \n' |
| 365 |
f'{port_bridge_name}: ({port_bridge_patch}) -> ' |
| 366 |
f'{int_bridge_name}: ({int_bridge_patch})' |
| 367 |
) |
| 368 |
self.ovsdb.create_patch_port_pair( |
| 369 |
port_bridge_name, port_bridge_patch, int_bridge_name, |
| 370 |
int_bridge_patch, iface_id, mac, instance_id, tag=tag) |
| 371 |
|
| 372 |
def _plug_vif_generic(self, vif, instance_info): |
| 373 |
"""Create a per-VIF OVS port.""" |
| 374 |
self.ovsdb.ensure_ovs_bridge(vif.network.bridge, |
| 375 |
self._get_vif_datapath_type(vif)) |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
if ("create_port" in vif.port_profile and |
| 395 |
vif.port_profile.create_port): |
| 396 |
self._create_vif_port(vif, vif.vif_name, instance_info) |
| 397 |
|
| 398 |
def _plug_vf(self, vif, instance_info): |
| 399 |
datapath = self._get_vif_datapath_type(vif) |
| 400 |
self.ovsdb.ensure_ovs_bridge(vif.network.bridge, datapath) |
| 401 |
pci_slot = vif.dev_address |
| 402 |
vf_num = linux_net.get_vf_num_by_pci_address(pci_slot) |
| 403 |
args = [] |
| 404 |
kwargs = {} |
| 405 |
if datapath == constants.OVS_DATAPATH_SYSTEM: |
| 406 |
pf_ifname = linux_net.get_ifname_by_pci_address( |
| 407 |
pci_slot, pf_interface=True, switchdev=True) |
| 408 |
representor = linux_net.get_representor_port(pf_ifname, vf_num) |
| 409 |
linux_net.set_interface_state(representor, 'up') |
| 410 |
args = [vif, representor, instance_info] |
| 411 |
else: |
| 412 |
representor = linux_net.get_dpdk_representor_port_name( |
| 413 |
vif.id) |
| 414 |
pf_pci = linux_net.get_pf_pci_from_vf(pci_slot) |
| 415 |
args = [vif, representor, instance_info] |
| 416 |
kwargs = {'interface_type': constants.OVS_DPDK_INTERFACE_TYPE, |
| 417 |
'pf_pci': pf_pci, |
| 418 |
'vf_num': vf_num} |
| 419 |
self._create_vif_port(*args, **kwargs) |
| 420 |
|
| 421 |
def plug(self, vif, instance_info): |
| 422 |
if not hasattr(vif, "port_profile"): |
| 423 |
raise exception.MissingPortProfile() |
| 424 |
if not isinstance(vif.port_profile, |
| 425 |
objects.vif.VIFPortProfileOpenVSwitch): |
| 426 |
raise exception.WrongPortProfile( |
| 427 |
profile=vif.port_profile.__class__.__name__) |
| 428 |
|
| 429 |
if isinstance(vif, objects.vif.VIFOpenVSwitch): |
| 430 |
if self.config.per_port_bridge: |
| 431 |
self._plug_port_bridge(vif, instance_info) |
| 432 |
else: |
| 433 |
self._plug_vif_generic(vif, instance_info) |
| 434 |
elif isinstance(vif, objects.vif.VIFBridge): |
| 435 |
self._plug_bridge(vif, instance_info) |
| 436 |
elif isinstance(vif, objects.vif.VIFVHostUser): |
| 437 |
self._plug_vhostuser(vif, instance_info) |
| 438 |
elif isinstance(vif, objects.vif.VIFHostDevice): |
| 439 |
self._plug_vf(vif, instance_info) |
| 440 |
else: |
| 441 |
|
| 442 |
raise osv_exception.PlugException( |
| 443 |
vif=vif, |
| 444 |
err="This vif type is not supported by this plugin") |
| 445 |
|
| 446 |
def _delete_bridge_if_trunk(self, vif): |
| 447 |
if is_trunk_bridge(vif.network.bridge): |
| 448 |
self.ovsdb.delete_ovs_bridge(vif.network.bridge) |
| 449 |
|
| 450 |
def _unplug_vhostuser(self, vif, instance_info): |
| 451 |
self.ovsdb.delete_ovs_vif_port(vif.network.bridge, |
| 452 |
OvsPlugin.gen_port_name( |
| 453 |
constants.OVS_VHOSTUSER_PREFIX, |
| 454 |
vif.id)) |
| 455 |
self._delete_bridge_if_trunk(vif) |
| 456 |
|
| 457 |
def _unplug_bridge(self, vif, instance_info, linux_bridge_name): |
| 458 |
"""UnPlug using hybrid strategy |
| 459 |
|
| 460 |
Unhook port from OVS, unhook port from bridge, delete |
| 461 |
bridge, and delete both veth devices. |
| 462 |
""" |
| 463 |
|
| 464 |
v1_name, v2_name = self.get_veth_pair_names(vif) |
| 465 |
|
| 466 |
linux_net.delete_bridge(linux_bridge_name, v1_name) |
| 467 |
|
| 468 |
qos_type = self._get_qos_type(vif) |
| 469 |
self.ovsdb.delete_ovs_vif_port( |
| 470 |
vif.network.bridge, v2_name, qos_type=qos_type |
| 471 |
) |
| 472 |
self._delete_bridge_if_trunk(vif) |
| 473 |
|
| 474 |
def _get_qos_type(self, vif): |
| 475 |
qos_type = None |
| 476 |
if self.supports_tc_qdisc(vif): |
| 477 |
qos_type = self.config.default_qos_type |
| 478 |
return qos_type |
| 479 |
|
| 480 |
def _unplug_port_bridge(self, vif, instance_info): |
| 481 |
"""Create a per-VIF OVS bridge and patch pair.""" |
| 482 |
|
| 483 |
self._delete_tap_if_required(vif, vif.vif_name) |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
port_bridge_name = self.gen_port_name('pb', vif.id) |
| 488 |
port_bridge_patch = self.gen_port_name('pbp', vif.id, max_length=64) |
| 489 |
int_bridge_patch = self.gen_port_name('ibp', vif.id, max_length=64) |
| 490 |
self.ovsdb.delete_ovs_vif_port(vif.network.bridge, int_bridge_patch) |
| 491 |
self.ovsdb.delete_ovs_vif_port(port_bridge_name, port_bridge_patch) |
| 492 |
qos_type = self._get_qos_type(vif) |
| 493 |
self.ovsdb.delete_ovs_vif_port( |
| 494 |
port_bridge_name, vif.vif_name, qos_type=qos_type |
| 495 |
) |
| 496 |
self.ovsdb.delete_ovs_bridge(port_bridge_name) |
| 497 |
self._delete_bridge_if_trunk(vif) |
| 498 |
|
| 499 |
def _unplug_vif_generic(self, vif, instance_info): |
| 500 |
"""Remove port from OVS.""" |
| 501 |
|
| 502 |
self._delete_tap_if_required(vif, vif.vif_name) |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
qos_type = self._get_qos_type(vif) |
| 508 |
self.ovsdb.delete_ovs_vif_port( |
| 509 |
vif.network.bridge, vif.vif_name, qos_type=qos_type |
| 510 |
) |
| 511 |
self._delete_bridge_if_trunk(vif) |
| 512 |
|
| 513 |
def _unplug_vf(self, vif): |
| 514 |
"""Remove port from OVS.""" |
| 515 |
datapath = self._get_vif_datapath_type(vif) |
| 516 |
if datapath == constants.OVS_DATAPATH_SYSTEM: |
| 517 |
pci_slot = vif.dev_address |
| 518 |
pf_ifname = linux_net.get_ifname_by_pci_address( |
| 519 |
pci_slot, pf_interface=True, switchdev=True) |
| 520 |
vf_num = linux_net.get_vf_num_by_pci_address(pci_slot) |
| 521 |
representor = linux_net.get_representor_port(pf_ifname, vf_num) |
| 522 |
else: |
| 523 |
representor = linux_net.get_dpdk_representor_port_name( |
| 524 |
vif.id) |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
qos_type = self._get_qos_type(vif) |
| 530 |
self.ovsdb.delete_ovs_vif_port( |
| 531 |
vif.network.bridge, representor, delete_netdev=False, |
| 532 |
qos_type=qos_type |
| 533 |
) |
| 534 |
if datapath == constants.OVS_DATAPATH_SYSTEM: |
| 535 |
linux_net.set_interface_state(representor, 'down') |
| 536 |
self._delete_bridge_if_trunk(vif) |
| 537 |
|
| 538 |
def unplug(self, vif, instance_info): |
| 539 |
if not hasattr(vif, "port_profile"): |
| 540 |
raise exception.MissingPortProfile() |
| 541 |
if not isinstance(vif.port_profile, |
| 542 |
objects.vif.VIFPortProfileOpenVSwitch): |
| 543 |
raise exception.WrongPortProfile( |
| 544 |
profile=vif.port_profile.__class__.__name__) |
| 545 |
if isinstance(vif, objects.vif.VIFOpenVSwitch): |
| 546 |
if self.config.per_port_bridge: |
| 547 |
self._unplug_port_bridge(vif, instance_info) |
| 548 |
else: |
| 549 |
linux_bridge_name = self.gen_port_name('qbr', vif.id) |
| 550 |
if ip_lib.exists(linux_bridge_name): |
| 551 |
self._unplug_bridge(vif, instance_info, linux_bridge_name) |
| 552 |
else: |
| 553 |
self._unplug_vif_generic(vif, instance_info) |
| 554 |
elif isinstance(vif, objects.vif.VIFBridge): |
| 555 |
self._unplug_bridge(vif, instance_info, vif.bridge_name) |
| 556 |
elif isinstance(vif, objects.vif.VIFVHostUser): |
| 557 |
self._unplug_vhostuser(vif, instance_info) |
| 558 |
elif isinstance(vif, objects.vif.VIFHostDevice): |
| 559 |
self._unplug_vf(vif) |
| 560 |
else: |
| 561 |
|
| 562 |
raise osv_exception.UnplugException( |
| 563 |
vif=vif, |
| 564 |
err="This vif type is not supported by this plugin") |