Debian Codegraph @

os_vif/objects/vif.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 from debtcollector import removals
14
15 from oslo_utils import versionutils
16 from oslo_versionedobjects import base
17 from oslo_versionedobjects import fields
18
19 from os_vif.objects import base as osv_base
20 from os_vif.objects import fields as osv_fields
21
22
23 @base.VersionedObjectRegistry.register
24 class VIFBase(osv_base.VersionedObject, base.ComparableVersionedObject):
25 """Represents a virtual network interface.
26
27 The base VIF defines fields that are common to all types of VIF and
28 provides an association to the network the VIF is plugged into. It should
29 not be instantiated itself - use a subclass instead.
30 """
31
32 # Version 1.0: Initial release
33 VERSION = '1.0'
34
35 fields = {
36 #: Unique identifier of the VIF port.
37 'id': fields.UUIDField(),
38
39 #: The guest MAC address.
40 'address': fields.MACAddressField(nullable=True),
41
42 #: The network to which the VIF is connected.
43 'network': fields.ObjectField('Network', nullable=True),
44
45 #: Name of the registered os_vif plugin.
46 'plugin': fields.StringField(),
47
48 #: Whether the VIF is initially online.
49 'active': fields.BooleanField(default=True),
50
51 #: Whether the host VIF should be preserved on unplug.
52 'preserve_on_delete': fields.BooleanField(default=False),
53
54 #: Whether the network service has provided traffic filtering.
55 'has_traffic_filtering': fields.BooleanField(default=False),
56
57 #: The virtual port profile metadata.
58 'port_profile': fields.ObjectField('VIFPortProfileBase',
59 subclasses=True)
60 }
61
62
63 @base.VersionedObjectRegistry.register
64 class VIFGeneric(VIFBase):
65 """A generic-style VIF.
66
67 Generic-style VIFs are unbound, floating TUN/TAP devices that should be
68 setup by the plugin, not the hypervisor. The way the TAP device is
69 connected to the host network stack is explicitly left undefined.
70
71 For libvirt drivers, this maps to type="ethernet" which just implies a bare
72 TAP device with all setup delegated to the plugin.
73 """
74
75 # Version 1.0: Initial release
76 VERSION = '1.0'
77
78 fields = {
79 #: Name of the device to create.
80 'vif_name': fields.StringField()
81 }
82
83
84 @base.VersionedObjectRegistry.register
85 class VIFBridge(VIFBase):
86 """A bridge-style VIF.
87
88 Bridge-style VIFs are bound to a Linux host bridge by the hypervisor. This
89 provides Ethernet layer bridging, typically to the LAN. Other devices may
90 be bound to the same L2 virtual bridge.
91
92 For libvirt drivers, this maps to type='bridge'.
93 """
94
95 # Version 1.0: Initial release
96 VERSION = '1.0'
97
98 fields = {
99 #: Name of the virtual device to create.
100 'vif_name': fields.StringField(),
101
102 #: Name of the physical device to connect to (e.g. ``br0``).
103 'bridge_name': fields.StringField(),
104 }
105
106
107 @base.VersionedObjectRegistry.register
108 class VIFOpenVSwitch(VIFBase):
109 """A bridge-style VIF specifically for use with OVS.
110
111 Open vSwitch VIFs are bound directly (or indirectly) to an Open vSwitch
112 bridge by the hypervisor. Other devices may be bound to the same virtual
113 bridge.
114
115 For libvirt drivers, this also maps to type='bridge'.
116 """
117
118 # Version 1.0: Initial release
119 VERSION = '1.0'
120
121 fields = {
122 #: Name of the virtual device to create.
123 'vif_name': fields.StringField(),
124
125 #: Name of the physical device to connect to (e.g. ``br0``).
126 'bridge_name': fields.StringField(),
127 }
128
129
130 @base.VersionedObjectRegistry.register
131 class VIFDirect(VIFBase):
132 """A direct-style VIF.
133
134 Despite the confusing name, direct-style VIFs utilize macvtap which is a
135 device driver that inserts a software layer between a guest and an SR-IOV
136 Virtual Function (VF). Contrast this with
137 :class:`~os_vif.objects.vif.VIFHostDevice`, which allows the guest to
138 directly connect to the VF.
139
140 The connection to the device may operate in one of a number of different
141 modes, :term:`VEPA` (either :term:`802.1Qbg` or :term:`802.1Qbh`),
142 passthrough (exclusive assignment of the host NIC) or bridge (ethernet
143 layer bridging of traffic). The passthrough mode would be used when there
144 is a network device which needs to have a MAC address or VLAN
145 configuration. For passthrough of network devices without MAC/VLAN
146 configuration, :class:`~os_vif.objects.vif.VIFHostDevice` should be used
147 instead.
148
149 For libvirt drivers, this maps to type='direct'
150 """
151
152 # Version 1.0: Initial release
153 VERSION = '1.0'
154
155 fields = {
156 #: Name of the device to create.
157 'vif_name': fields.StringField(),
158
159 #: The PCI address of the host device.
160 'dev_address': fields.PCIAddressField(),
161
162 #: Port connection mode.
163 'mode': osv_fields.VIFDirectModeField(),
164
165 #: The VLAN device name to use.
166 'vlan_name': fields.StringField(),
167 }
168
169
170 @base.VersionedObjectRegistry.register
171 class VIFVHostUser(VIFBase):
172 """A vhostuser-style VIF.
173
174 vhostuser-style VIFs utilize a :term:`userspace vhost <vhost-user>`
175 backend, which allows traffic to traverse between the guest and a host
176 userspace application (commonly a virtual switch), bypassing the kernel
177 network stack. Contrast this with :class:`~os_vif.objects.vif.VIFBridge`,
178 where all packets must be handled by the hypervisor.
179
180 For libvirt drivers, this maps to type='vhostuser'
181 """
182
183 # Version 1.0: Initial release
184 # Version 1.1: Added 'vif_name'
185 VERSION = '1.1'
186
187 fields = {
188 #: Name of the vhostuser port to create.
189 'vif_name': fields.StringField(),
190
191 #: UNIX socket path.
192 'path': fields.StringField(),
193
194 #: UNIX socket access permissions.
195 'mode': osv_fields.VIFVHostUserModeField(),
196 }
197
198 def obj_make_compatible(self, primitive, target_version):
199 target_version = versionutils.convert_version_to_tuple(target_version)
200 if target_version < (1, 1) and 'vif_name' in primitive:
201 del primitive['vif_name']
202 super(VIFVHostUser, self).obj_make_compatible(primitive, '1.0')
203
204
205 @base.VersionedObjectRegistry.register
206 class VIFHostDevice(VIFBase):
207 """A hostdev-style VIF.
208
209 Hostdev-style VIFs provide a guest with direct access to an :term:`SR-IOV`
210 :term:`Virtual Function` (VF) or an entire :term:`Physical Function` (PF).
211 Contrast this with :class:`~ovs_vif.objects.vif.VIFDirect`, which includes
212 a software layer between the interface and the guest.
213
214 For libvirt drivers, this maps to type='hostdev'
215 """
216
217 # Version 1.0: Initial release
218 VERSION = '1.0'
219
220 fields = {
221 #: The type of the host device.
222 #:
223 #: Valid values are ``ethernet`` and ``generic``.
224 #:
225 #: - ``ethernet`` is ``<interface type='hostdev'>``
226 #: - ``generic`` is ``<hostdev mode='subsystem' type='pci'>``
227 'dev_type': osv_fields.VIFHostDeviceDevTypeField(),
228
229 #: The PCI address of the host device.
230 'dev_address': fields.PCIAddressField(),
231 }
232
233
234 @base.VersionedObjectRegistry.register
235 class VIFNestedDPDK(VIFBase):
236 """A nested DPDK-style VIF.
237
238 Nested DPDK-style VIFs are used by Kuryr-Kubernetes to provide accelerated
239 DPDK datapath for nested Kubernetes pods running inside the VM. The port
240 is first attached to the virtual machine, bound to the userspace driver
241 (e.g. ``uio_pci_generic``, ``igb_uio`` or ``vfio-pci``) and then consumed
242 by Kubernetes pod via the kuryr-kubernetes CNI plugin.
243
244 This does not apply to libvirt drivers.
245 """
246
247 # Version 1.0: Initial release
248 VERSION = '1.0'
249
250 fields = {
251 #: PCI address of the device.
252 'pci_address': fields.StringField(),
253
254 #: Name of the driver the device was previously bound to; it makes
255 #: the controller driver agnostic (virtio, SR-IOV, etc.).
256 'dev_driver': fields.StringField(),
257 }
258
259
260 @base.VersionedObjectRegistry.register
261 class DatapathOffloadBase(osv_base.VersionedObject,
262 base.ComparableVersionedObject):
263 """Base class for all types of datapath offload."""
264
265 # Version 1.0: Initial release
266 VERSION = '1.0'
267
268
269 @base.VersionedObjectRegistry.register
270 class DatapathOffloadRepresentor(DatapathOffloadBase):
271 """Offload type for VF Representors conforming to the switchdev model.
272
273 This datapath offloads provides the metadata required to associate a VIF
274 with a :term:`VF` representor conforming to the `switchdev`_ kernel model.
275 If ``representor_name`` is specified, it indicates a desire to rename the
276 representor to the given name on plugging.
277
278 .. _switchdev: https://netdevconf.org/1.2/session.html?or-gerlitz
279 """
280
281 # Version 1.0: Initial release
282 VERSION = '1.0'
283
284 fields = {
285 #: Name to set on the representor (if set).
286 'representor_name': fields.StringField(nullable=True),
287
288 #: The PCI address of the Virtual Function.
289 'representor_address': fields.StringField(nullable=True),
290 }
291
292
293 @base.VersionedObjectRegistry.register
294 class VIFPortProfileBase(osv_base.VersionedObject,
295 base.ComparableVersionedObject):
296 """Base class for all types of port profile.
297
298 The base profile defines fields that are common to all types of profile. It
299 should not be instantiated itself - use a subclass instead.
300 """
301
302 # Version 1.0: Initial release
303 # Version 1.1: Added 'datapath_offload'
304 VERSION = '1.1'
305
306 fields = {
307 #: Datapath offload type of the port.
308 'datapath_offload': fields.ObjectField('DatapathOffloadBase',
309 nullable=True,
310 subclasses=True),
311 }
312
313 obj_relationships = {
314 'datapath_offload': (('1.1', '1.0'),),
315 }
316
317
318 @base.VersionedObjectRegistry.register
319 class VIFPortProfileOpenVSwitch(VIFPortProfileBase):
320 """Port profile info for Open vSwitch networks.
321
322 This profile provides the metadata required to associate a VIF with an Open
323 vSwitch interface.
324 """
325
326 # Version 1.0: Initial release
327 # Version 1.1: Added 'datapath_type'
328 # Version 1.2: VIFPortProfileBase updated to 1.1 from 1.0
329 # Version 1.3: Added 'create_port'
330 # Version 1.4: Added 'create_tap' and 'multiqueue'
331 VERSION = '1.4'
332
333 fields = {
334 #: A UUID to uniquely identify the interface. If omitted one will be
335 #: generated automatically.
336 'interface_id': fields.UUIDField(),
337
338 #: The OpenVSwitch port profile for the interface.
339 'profile_id': fields.StringField(),
340
341 #: Datapath type of the bridge.
342 'datapath_type': fields.StringField(nullable=True),
343
344 #: Whether the os-vif plugin should add the port to the bridge.
345 'create_port': fields.BooleanField(default=False),
346
347 #: Whether the os-vif plugin should create the TAP device.
348 'create_tap': fields.BooleanField(default=False),
349
350 #: Whether to enable multiqueue on the TAP device.
351 'multiqueue': fields.BooleanField(default=False),
352 }
353
354 def obj_make_compatible(self, primitive, target_version):
355 target_version = versionutils.convert_version_to_tuple(target_version)
356 if target_version < (1, 4):
357 if 'create_tap' in primitive:
358 del primitive['create_tap']
359 if 'multiqueue' in primitive:
360 del primitive['multiqueue']
361 if target_version < (1, 3) and 'create_port' in primitive:
362 del primitive['create_port']
363 if target_version < (1, 1) and 'datapath_type' in primitive:
364 del primitive['datapath_type']
365 if target_version < (1, 2):
366 super(VIFPortProfileOpenVSwitch, self).obj_make_compatible(
367 primitive, '1.0')
368 else:
369 super(VIFPortProfileOpenVSwitch, self).obj_make_compatible(
370 primitive, '1.1')
371
372
373 @base.VersionedObjectRegistry.register
374 class VIFPortProfileFPOpenVSwitch(VIFPortProfileOpenVSwitch):
375 """Port profile info for Open vSwitch networks using fast path.
376
377 This profile provides the metadata required to associate a :term:`fast
378 path <Fast Path>` VIF with an :term:`Open vSwitch` port.
379 """
380
381 # Version 1.0: Initial release
382 # Version 1.1: VIFPortProfileOpenVSwitch updated to 1.1 from 1.0
383 # Version 1.2: VIFPortProfileOpenVSwitch updated to 1.2 from 1.1
384 # Version 1.3: VIFPortProfileOpenVSwitch updated to 1.3 from 1.2
385 # Version 1.4: VIFPortProfileOpenVSwitch updated to 1.4 from 1.3
386 VERSION = '1.4'
387
388 fields = {
389 #: Name of the bridge (managed by fast path) to connect to.
390 'bridge_name': fields.StringField(),
391
392 #: Whether the OpenVSwitch network is using hybrid plug.
393 'hybrid_plug': fields.BooleanField(default=False),
394 }
395
396 def obj_make_compatible(self, primitive, target_version):
397 target_version = versionutils.convert_version_to_tuple(target_version)
398 if target_version < (1, 1):
399 super(VIFPortProfileFPOpenVSwitch, self).obj_make_compatible(
400 primitive, '1.0')
401 elif target_version < (1, 2):
402 super(VIFPortProfileFPOpenVSwitch, self).obj_make_compatible(
403 primitive, '1.1')
404 elif target_version < (1, 3):
405 super(VIFPortProfileFPOpenVSwitch, self).obj_make_compatible(
406 primitive, '1.2')
407 elif target_version < (1, 4):
408 super(VIFPortProfileFPOpenVSwitch, self).obj_make_compatible(
409 primitive, '1.3')
410 else:
411 super(VIFPortProfileFPOpenVSwitch, self).obj_make_compatible(
412 primitive, '1.4')
413
414
415 @removals.removed_class("VIFPortProfileOVSRepresentor",
416 category=PendingDeprecationWarning)
417 @base.VersionedObjectRegistry.register
418 class VIFPortProfileOVSRepresentor(VIFPortProfileOpenVSwitch):
419 """Port profile info for OpenVSwitch networks using a representor.
420
421 This profile provides the metadata required to associate a VIF with a
422 :term:`VF` representor and :term:`Open vSwitch` port. If `representor_name`
423 is specified, it indicates a desire to rename the representor to the given
424 name on plugging.
425
426 .. note::
427
428 This port profile is provided for backwards compatibility only.
429
430 This interface has been superceded by the one provided by the
431 :class:`DatapathOffloadRepresentor` class, which is now a field element
432 of the :class:`VIFPortProfileBase` class. The ``datapath_offload``
433 field in port profiles should be used instead.
434 """
435
436 # Version 1.0: Initial release
437 # Version 1.1: VIFPortProfileOpenVSwitch updated to 1.1 from 1.0
438 # Version 1.2: VIFPortProfileOpenVSwitch updated to 1.2 from 1.1
439 # Version 1.3: VIFPortProfileOpenVSwitch updated to 1.3 from 1.2
440 # Version 1.4: VIFPortProfileOpenVSwitch updated to 1.4 from 1.3
441 VERSION = '1.4'
442
443 fields = {
444 #: Name to set on the representor (if set).
445 'representor_name': fields.StringField(nullable=True),
446
447 #: The PCI address of the Virtual Function.
448 'representor_address': fields.PCIAddressField(nullable=True),
449 }
450
451 def obj_make_compatible(self, primitive, target_version):
452 target_version = versionutils.convert_version_to_tuple(target_version)
453 if target_version < (1, 1):
454 super(VIFPortProfileOVSRepresentor, self).obj_make_compatible(
455 primitive, '1.0')
456 elif target_version < (1, 2):
457 super(VIFPortProfileOVSRepresentor, self).obj_make_compatible(
458 primitive, '1.1')
459 elif target_version < (1, 3):
460 super(VIFPortProfileOVSRepresentor, self).obj_make_compatible(
461 primitive, '1.2')
462 elif target_version < (1, 4):
463 super(VIFPortProfileOVSRepresentor, self).obj_make_compatible(
464 primitive, '1.3')
465 else:
466 super(VIFPortProfileOVSRepresentor, self).obj_make_compatible(
467 primitive, '1.4')
468
469
470 @base.VersionedObjectRegistry.register
471 class VIFPortProfileFPBridge(VIFPortProfileBase):
472 """Port profile info for Linux Bridge networks using fast path.
473
474 This profile provides the metadata required to associate a :term:`fast
475 path <Fast Path>` VIF with a :term:`Linux Bridge` port.
476 """
477
478 # Version 1.0: Initial release
479 # Version 1.1: VIFPortProfileBase updated to 1.1 from 1.0
480 VERSION = '1.1'
481
482 fields = {
483 #: Name of the bridge (managed by fast path) to connect to.
484 'bridge_name': fields.StringField(),
485 }
486
487 def obj_make_compatible(self, primitive, target_version):
488 target_version = versionutils.convert_version_to_tuple(target_version)
489 if target_version < (1, 1):
490 super(VIFPortProfileFPBridge, self).obj_make_compatible(
491 primitive, '1.0')
492 else:
493 super(VIFPortProfileFPBridge, self).obj_make_compatible(
494 primitive, '1.1')
495
496
497 @base.VersionedObjectRegistry.register
498 class VIFPortProfileFPTap(VIFPortProfileBase):
499 """Port profile info for Calico networks using fast path.
500
501 This profile provides the metadata required to associate a :term:`fast
502 path <Fast Path>` VIF with a :term:`Calico` port.
503 """
504
505 # Version 1.0: Initial release
506 # Version 1.1: VIFPortProfileBase updated to 1.1 from 1.0
507 VERSION = '1.1'
508
509 fields = {
510 #: The MAC address of the host vhostuser port.
511 'mac_address': fields.MACAddressField(nullable=True),
512 }
513
514 def obj_make_compatible(self, primitive, target_version):
515 target_version = versionutils.convert_version_to_tuple(target_version)
516 if target_version < (1, 1):
517 super(VIFPortProfileFPTap, self).obj_make_compatible(
518 primitive, '1.0')
519 else:
520 super(VIFPortProfileFPTap, self).obj_make_compatible(
521 primitive, '1.1')
522
523
524 @base.VersionedObjectRegistry.register
525 class VIFPortProfile8021Qbg(VIFPortProfileBase):
526 """Port profile info for VEPA 802.1qbg networks.
527
528 This profile provides the metadata required to associate a VIF with a VEPA
529 host device supporting the :term:`802.1Qbg` spec.
530 """
531
532 # Version 1.0: Initial release
533 # Version 1.1: VIFPortProfileBase updated to 1.1 from 1.0
534 VERSION = '1.1'
535
536 fields = {
537 # TODO(stephenfin): Apparently the value 0 is reserved for manager_id,
538 # so should we set 'minimum=1'?
539 # https://libvirt.org/formatdomain.html#elementsNICS
540
541 #: The VSI Manager ID identifies the database containing the VSI type
542 #: and instance definitions.
543 'manager_id': fields.IntegerField(),
544
545 #: The VSI Type ID identifies a VSI type characterizing the network
546 #: access. VSI types are typically managed by network administrator.
547 'type_id': fields.IntegerField(),
548
549 #: The VSI Type Version allows multiple versions of a VSI Type.
550 'type_id_version': fields.IntegerField(),
551
552 #: The VSI Instance ID Identifier is generated when a VSI instance
553 #: (i.e. a virtual interface of a virtual machine) is created. This is
554 #: a globally unique identifier.
555 'instance_id': fields.UUIDField(),
556 }
557
558 def obj_make_compatible(self, primitive, target_version):
559 target_version = versionutils.convert_version_to_tuple(target_version)
560 if target_version < (1, 1):
561 super(VIFPortProfile8021Qbg, self).obj_make_compatible(
562 primitive, '1.0')
563 else:
564 super(VIFPortProfile8021Qbg, self).obj_make_compatible(
565 primitive, '1.1')
566
567
568 @base.VersionedObjectRegistry.register
569 class VIFPortProfile8021Qbh(VIFPortProfileBase):
570 """Port profile info for VEPA 802.1qbh networks.
571
572 This profile provides the metadata required to associate a VIF with a VEPA
573 host device supporting the :term:`802.1Qbh` spec.
574 """
575
576 # Version 1.0: Initial release
577 # Version 1.1: VIFPortProfileBase updated to 1.1 from 1.0
578 VERSION = '1.1'
579
580 fields = {
581 #: The name of the port profile that is to be applied to this
582 #: interface. This name is resolved by the port profile database into
583 #: the network parameters from the port profile, and those network
584 #: parameters will be applied to this interface.
585 'profile_id': fields.StringField()
586 }
587
588 def obj_make_compatible(self, primitive, target_version):
589 target_version = versionutils.convert_version_to_tuple(target_version)
590 if target_version < (1, 1):
591 super(VIFPortProfile8021Qbh, self).obj_make_compatible(
592 primitive, '1.0')
593 else:
594 super(VIFPortProfile8021Qbh, self).obj_make_compatible(
595 primitive, '1.1')
596
597
598 @base.VersionedObjectRegistry.register
599 class VIFPortProfileK8sDPDK(VIFPortProfileBase):
600 """Port profile info for Kuryr-Kubernetes DPDK ports.
601
602 This profile provides the metadata required to associate nested DPDK VIF
603 with a Kubernetes pod.
604 """
605
606 # Version 1.0: Initial release
607 # Version 1.1: VIFPortProfileBase updated to 1.1 from 1.0
608 VERSION = '1.1'
609
610 fields = {
611 #: Specify whether this vif requires L3 setup.
612 'l3_setup': fields.BooleanField(),
613
614 #: String containing URL representing object in Kubernetes v1 API.
615 'selflink': fields.StringField(),
616
617 #: String used in Kubernetes v1 API to identify the server's internal
618 #: version of this object.
619 'resourceversion': fields.StringField()
620 }
621
622 def obj_make_compatible(self, primitive, target_version):
623 target_version = versionutils.convert_version_to_tuple(target_version)
624 if target_version < (1, 1):
625 super(VIFPortProfileK8sDPDK, self).obj_make_compatible(
626 primitive, '1.0')
627 else:
628 super(VIFPortProfileK8sDPDK, self).obj_make_compatible(
629 primitive, '1.1')