Debian Codegraph @

neutron_lib/plugins/ml2/api.py

raw
1 # All rights reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # 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, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 import abc
16
17 from neutron_lib.api.definitions import portbindings
18
19
20 # The following keys are used in the segment dictionaries passed via
21 # the driver API.
22 ID = 'id'
23 NETWORK_TYPE = 'network_type'
24 PHYSICAL_NETWORK = 'physical_network'
25 SEGMENTATION_ID = 'segmentation_id'
26 MTU = 'mtu'
27 NETWORK_ID = 'network_id'
28
29 # The following keys are used in the binding level dictionaries
30 # available via the binding_levels and original_binding_levels
31 # PortContext properties.
32 BOUND_DRIVER = 'bound_driver'
33 BOUND_SEGMENT = 'bound_segment'
34
35
36 class MechanismDriver(metaclass=abc.ABCMeta):
37 """Define stable abstract interface for ML2 mechanism drivers.
38
39 A mechanism driver is called on the creation, update, and deletion
40 of networks and ports. For every event, there are two methods that
41 get called - one within the database transaction (method suffix of
42 _precommit), one right afterwards (method suffix of _postcommit).
43
44 Exceptions raised by methods called inside the transaction can
45 rollback, but should not make any blocking calls (for example,
46 REST requests to an outside controller). Methods called after
47 transaction commits can make blocking external calls, though these
48 will block the entire process. Exceptions raised in calls after
49 the transaction commits may cause the associated resource to be
50 deleted.
51
52 Because rollback outside of the transaction is not done in the
53 update network/port case, all data validation must be done within
54 methods that are part of the database transaction.
55 """
56
57 # Used in generating resource provider UUIDs for physical network
58 # interfaces. Each mechanism driver supporting Placement should have its
59 # own UUID v5 namespace (which is a UUID v1 in turn). When set to a
60 # concrete value use a uuid.UUID() object, not the string format.
61 # It will be used when hashing RP UUIDs from:
62 # (mech driver namespace, hostname, physical bridge/interface name)
63 # When needed generate new namespace UUIDs by:
64 # python -c 'import uuid ; print uuid.uuid1()'
65 # See also:
66 # https://tools.ietf.org/html/rfc4122
67 # https://stackoverflow.com/a/7816117
68 resource_provider_uuid5_namespace = None
69
70 @abc.abstractmethod
71 def initialize(self):
72 """Perform driver initialization.
73
74 Called after all drivers have been loaded and the database has
75 been initialized. No abstract methods defined below will be
76 called prior to this method being called.
77 """
78
79 def start_rpc_listeners(self):
80 """Start RPC listeners.
81
82 Create and start RPC listeners required by this driver. To be used in
83 cases where the driver has an agent that requires extra RPC methods to
84 acquire some data. It is preferred to initialize RPC listeners here
85 instead of in initialize() to support the split between RPC and API
86 workers. It works similar to NeutronPluginBaseV2.start_rpc_listeners().
87 """
88 return []
89
90 def create_network_precommit(self, context):
91 """Allocate resources for a new network.
92
93 :param context: NetworkContext instance describing the new
94 network.
95
96 Create a new network, allocating resources as necessary in the
97 database. Called inside transaction context on session. Call
98 cannot block. Raising an exception will result in a rollback
99 of the current transaction.
100 """
101 pass
102
103 def create_network_postcommit(self, context):
104 """Create a network.
105
106 :param context: NetworkContext instance describing the new
107 network.
108
109 Called after the transaction commits. Call can block, though
110 will block the entire process so care should be taken to not
111 drastically affect performance. Raising an exception will
112 cause the deletion of the resource.
113 """
114 pass
115
116 def update_network_precommit(self, context):
117 """Update resources of a network.
118
119 :param context: NetworkContext instance describing the new
120 state of the network, as well as the original state prior
121 to the update_network call.
122
123 Update values of a network, updating the associated resources
124 in the database. Called inside transaction context on session.
125 Raising an exception will result in rollback of the
126 transaction.
127
128 update_network_precommit is called for all changes to the
129 network state. It is up to the mechanism driver to ignore
130 state or state changes that it does not know or care about.
131 """
132 pass
133
134 def update_network_postcommit(self, context):
135 """Update a network.
136
137 :param context: NetworkContext instance describing the new
138 state of the network, as well as the original state prior
139 to the update_network call.
140
141 Called after the transaction commits. Call can block, though
142 will block the entire process so care should be taken to not
143 drastically affect performance. Raising an exception will
144 cause the deletion of the resource.
145
146 update_network_postcommit is called for all changes to the
147 network state. It is up to the mechanism driver to ignore
148 state or state changes that it does not know or care about.
149 """
150 pass
151
152 def delete_network_precommit(self, context):
153 """Delete resources for a network.
154
155 :param context: NetworkContext instance describing the current
156 state of the network, prior to the call to delete it.
157
158 Delete network resources previously allocated by this
159 mechanism driver for a network. Called inside transaction
160 context on session. Runtime errors are not expected, but
161 raising an exception will result in rollback of the
162 transaction.
163 """
164 pass
165
166 def delete_network_postcommit(self, context):
167 """Delete a network.
168
169 :param context: NetworkContext instance describing the current
170 state of the network, prior to the call to delete it.
171
172 Called after the transaction commits. Call can block, though
173 will block the entire process so care should be taken to not
174 drastically affect performance. Runtime errors are not
175 expected, and will not prevent the resource from being
176 deleted.
177 """
178 pass
179
180 def create_subnet_precommit(self, context):
181 """Allocate resources for a new subnet.
182
183 :param context: SubnetContext instance describing the new
184 subnet.
185
186 Create a new subnet, allocating resources as necessary in the
187 database. Called inside transaction context on session. Call
188 cannot block. Raising an exception will result in a rollback
189 of the current transaction.
190 """
191 pass
192
193 def create_subnet_postcommit(self, context):
194 """Create a subnet.
195
196 :param context: SubnetContext instance describing the new
197 subnet.
198
199 Called after the transaction commits. Call can block, though
200 will block the entire process so care should be taken to not
201 drastically affect performance. Raising an exception will
202 cause the deletion of the resource.
203 """
204 pass
205
206 def update_subnet_precommit(self, context):
207 """Update resources of a subnet.
208
209 :param context: SubnetContext instance describing the new
210 state of the subnet, as well as the original state prior
211 to the update_subnet call.
212
213 Update values of a subnet, updating the associated resources
214 in the database. Called inside transaction context on session.
215 Raising an exception will result in rollback of the
216 transaction.
217
218 update_subnet_precommit is called for all changes to the
219 subnet state. It is up to the mechanism driver to ignore
220 state or state changes that it does not know or care about.
221 """
222 pass
223
224 def update_subnet_postcommit(self, context):
225 """Update a subnet.
226
227 :param context: SubnetContext instance describing the new
228 state of the subnet, as well as the original state prior
229 to the update_subnet call.
230
231 Called after the transaction commits. Call can block, though
232 will block the entire process so care should be taken to not
233 drastically affect performance. Raising an exception will
234 cause the deletion of the resource.
235
236 update_subnet_postcommit is called for all changes to the
237 subnet state. It is up to the mechanism driver to ignore
238 state or state changes that it does not know or care about.
239 """
240 pass
241
242 def delete_subnet_precommit(self, context):
243 """Delete resources for a subnet.
244
245 :param context: SubnetContext instance describing the current
246 state of the subnet, prior to the call to delete it.
247
248 Delete subnet resources previously allocated by this
249 mechanism driver for a subnet. Called inside transaction
250 context on session. Runtime errors are not expected, but
251 raising an exception will result in rollback of the
252 transaction.
253 """
254 pass
255
256 def delete_subnet_postcommit(self, context):
257 """Delete a subnet.
258
259 :param context: SubnetContext instance describing the current
260 state of the subnet, prior to the call to delete it.
261
262 Called after the transaction commits. Call can block, though
263 will block the entire process so care should be taken to not
264 drastically affect performance. Runtime errors are not
265 expected, and will not prevent the resource from being
266 deleted.
267 """
268 pass
269
270 def create_port_precommit(self, context):
271 """Allocate resources for a new port.
272
273 :param context: PortContext instance describing the port.
274
275 Create a new port, allocating resources as necessary in the
276 database. Called inside transaction context on session. Call
277 cannot block. Raising an exception will result in a rollback
278 of the current transaction.
279 """
280 pass
281
282 def create_port_postcommit(self, context):
283 """Create a port.
284
285 :param context: PortContext instance describing the port.
286
287 Called after the transaction completes. Call can block, though
288 will block the entire process so care should be taken to not
289 drastically affect performance. Raising an exception will
290 result in the deletion of the resource.
291 """
292 pass
293
294 def update_port_precommit(self, context):
295 """Update resources of a port.
296
297 :param context: PortContext instance describing the new
298 state of the port, as well as the original state prior
299 to the update_port call.
300
301 Called inside transaction context on session to complete a
302 port update as defined by this mechanism driver. Raising an
303 exception will result in rollback of the transaction.
304
305 update_port_precommit is called for all changes to the port
306 state. It is up to the mechanism driver to ignore state or
307 state changes that it does not know or care about.
308 """
309 pass
310
311 def update_port_postcommit(self, context):
312 """Update a port.
313
314 :param context: PortContext instance describing the new
315 state of the port, as well as the original state prior
316 to the update_port call.
317
318 Called after the transaction completes. Call can block, though
319 will block the entire process so care should be taken to not
320 drastically affect performance. Raising an exception will
321 result in the deletion of the resource.
322
323 update_port_postcommit is called for all changes to the port
324 state. It is up to the mechanism driver to ignore state or
325 state changes that it does not know or care about.
326 """
327 pass
328
329 def delete_port_precommit(self, context):
330 """Delete resources of a port.
331
332 :param context: PortContext instance describing the current
333 state of the port, prior to the call to delete it.
334
335 Called inside transaction context on session. Runtime errors
336 are not expected, but raising an exception will result in
337 rollback of the transaction.
338 """
339 pass
340
341 def delete_port_postcommit(self, context):
342 """Delete a port.
343
344 :param context: PortContext instance describing the current
345 state of the port, prior to the call to delete it.
346
347 Called after the transaction completes. Call can block, though
348 will block the entire process so care should be taken to not
349 drastically affect performance. Runtime errors are not
350 expected, and will not prevent the resource from being
351 deleted.
352 """
353 pass
354
355 def bind_port(self, context):
356 """Attempt to bind a port.
357
358 :param context: PortContext instance describing the port
359
360 This method is called outside any transaction to attempt to
361 establish a port binding using this mechanism driver. Bindings
362 may be created at each of multiple levels of a hierarchical
363 network, and are established from the top level downward. At
364 each level, the mechanism driver determines whether it can
365 bind to any of the network segments in the
366 context.segments_to_bind property, based on the value of the
367 context.host property, any relevant port or network
368 attributes, and its own knowledge of the network topology. At
369 the top level, context.segments_to_bind contains the static
370 segments of the port's network. At each lower level of
371 binding, it contains static or dynamic segments supplied by
372 the driver that bound at the level above. If the driver is
373 able to complete the binding of the port to any segment in
374 context.segments_to_bind, it must call context.set_binding
375 with the binding details. If it can partially bind the port,
376 it must call context.continue_binding with the network
377 segments to be used to bind at the next lower level.
378
379 If the binding results are committed after bind_port returns,
380 they will be seen by all mechanism drivers as
381 update_port_precommit and update_port_postcommit calls. But if
382 some other thread or process concurrently binds or updates the
383 port, these binding results will not be committed, and
384 update_port_precommit and update_port_postcommit will not be
385 called on the mechanism drivers with these results. Because
386 binding results can be discarded rather than committed,
387 drivers should avoid making persistent state changes in
388 bind_port, or else must ensure that such state changes are
389 eventually cleaned up.
390
391 Implementing this method explicitly declares the mechanism
392 driver as having the intention to bind ports. This is inspected
393 by the QoS service to identify the available QoS rules you
394 can use with ports.
395 """
396 pass
397
398 @property
399 def _supports_port_binding(self):
400 return self.__class__.bind_port != MechanismDriver.bind_port
401
402 def check_vlan_transparency(self, context):
403 """Check if the network supports vlan transparency.
404
405 :param context: NetworkContext instance describing the network.
406
407 Check if the network supports vlan transparency or not.
408 """
409 pass
410
411 def check_vlan_qinq(self, context):
412 """Check if the network supports QinQ vlans.
413
414 :param context: NetworkContext instance describing the network.
415
416 Check if the network supports QinQ vlan (similar to vlan transparency
417 but this uses different ethertype, 0x8a88 for the outer tag) or not.
418 """
419 pass
420
421 def get_workers(self):
422 """Get any NeutronWorker instances that should have their own process
423
424 Any driver that needs to run processes separate from the API or RPC
425 workers, can return a sequence of NeutronWorker instances.
426 """
427 return ()
428
429 @classmethod
430 def is_host_filtering_supported(cls):
431 return (cls.filter_hosts_with_segment_access !=
432 MechanismDriver.filter_hosts_with_segment_access)
433
434 def filter_hosts_with_segment_access(
435 self, context, segments, candidate_hosts, agent_getter):
436 """Filter hosts with access to at least one segment.
437
438 :returns: a set with a subset of candidate_hosts.
439
440 A driver can overload this method to return a subset of candidate_hosts
441 with the ones with access to at least one segment.
442
443 Default implementation returns all hosts to disable filtering
444 (backward compatibility).
445 """
446 return candidate_hosts
447
448 def responsible_for_ports_allocation(self, context):
449 """Is responsible for a port's resource provider?
450
451 :param context: PortContext instance describing the port
452 :returns: True for responsible, False for not responsible
453
454 For ports having an allocation in Placement (as expressed
455 in the port's binding:profile.allocation) decide while
456 binding if this mechanism driver is responsible for the
457 physical network interface represented by the resource
458 provider in Placement. Find the resource provider UUID in
459 context.current['binding:profile']['allocation'].
460
461 Drivers wanting to support resource allocations for ports in
462 Placement (eg. wanting to guarantee some minimum bandwidth)
463 must implement this method.
464
465 Default implementation returns False (backward compatibility).
466 """
467 return False
468
469 @staticmethod
470 def provider_network_attribute_updates_supported():
471 """Returns the provider network attributes that can be updated
472
473 Possible values: neutron_lib.api.definitions.provider_net.ATTRIBUTES
474
475 :returns: (list) provider network attributes that can be updated in a
476 live network using this driver.
477 """
478 return []
479
480 def supported_extensions(self, extensions):
481 """Return the mechanism driver supported extensions
482
483 By default this method will return the same provided set, without any
484 filtering. In case any particular mechanism driver needs to filter out
485 any specific extension or supports only a reduced set of extensions,
486 this method should be override.
487
488 :param extensions: set of extensions supported by the instance that
489 created this mechanism driver.
490 :returns: a set of the extensions currently supported by this
491 mechanism driver
492 """
493 return extensions
494
495 @property
496 def connectivity(self):
497 """Return the mechanism driver connectivity type
498
499 The possible values are "l2", "l3" and "legacy" (default).
500
501 :returns: a string in ("l2", "l3", "legacy")
502 """
503 return portbindings.CONNECTIVITY_LEGACY
504
505
506 class _TypeDriverBase(metaclass=abc.ABCMeta):
507
508 @abc.abstractmethod
509 def get_type(self):
510 """Get driver's network type.
511
512 :returns: network_type value handled by this driver
513 """
514
515 @abc.abstractmethod
516 def initialize(self):
517 """Perform driver initialization.
518
519 Called after all drivers have been loaded and the database has
520 been initialized. No abstract methods defined below will be
521 called prior to this method being called.
522 """
523
524 @abc.abstractmethod
525 def is_partial_segment(self, segment):
526 """Return True if segment is a partially specified segment.
527
528 :param segment: segment dictionary
529 :returns: boolean
530 """
531
532 @abc.abstractmethod
533 def validate_provider_segment(self, segment):
534 """Validate attributes of a provider network segment.
535
536 :param segment: segment dictionary using keys defined above
537 :raises: neutron_lib.exceptions.InvalidInput if invalid
538
539 Called outside transaction context to validate the provider
540 attributes for a provider network segment. Raise InvalidInput
541 if:
542
543 - any required attribute is missing
544 - any prohibited or unrecognized attribute is present
545 - any attribute value is not valid
546
547 The network_type attribute is present in segment, but
548 need not be validated.
549 """
550
551 @abc.abstractmethod
552 def get_mtu(self, physical):
553 """Get driver's network MTU.
554
555 :returns: mtu maximum transmission unit
556
557 Returns the mtu for the network based on the config values and
558 the network type.
559 """
560
561
562 class TypeDriver(_TypeDriverBase, metaclass=abc.ABCMeta):
563 """Define abstract interface for ML2 type drivers.
564
565 ML2 type drivers each support a specific network_type for provider
566 and/or tenant network segments. Type drivers must implement this
567 abstract interface, which defines the API by which the plugin uses
568 the driver to manage the persistent type-specific resource
569 allocation state associated with network segments of that type.
570
571 Network segments are represented by segment dictionaries using the
572 NETWORK_TYPE, PHYSICAL_NETWORK, and SEGMENTATION_ID keys defined
573 above, corresponding to the provider attributes. Future revisions
574 of the TypeDriver API may add additional segment dictionary
575 keys. Attributes not applicable for a particular network_type may
576 either be excluded or stored as None.
577
578 TypeDriver passes session as argument for:
579 - reserve_provider_segment
580 - allocate_tenant_segment
581 - release_segment
582 - get_allocation
583 """
584
585 @abc.abstractmethod
586 def reserve_provider_segment(self, session, segment, filters=None):
587 """Reserve resource associated with a provider network segment.
588
589 :param session: database session
590 :param segment: segment dictionary
591 :param filters: a dictionary that is used as search criteria
592 :returns: segment dictionary
593
594 Called inside transaction context on session to reserve the
595 type-specific resource for a provider network segment. The
596 segment dictionary passed in was returned by a previous
597 validate_provider_segment() call.
598 """
599
600 @abc.abstractmethod
601 def allocate_tenant_segment(self, session, filters=None):
602 """Allocate resource for a new tenant network segment.
603
604 :param session: database session
605 :param filters: a dictionary that is used as search criteria
606 :returns: segment dictionary using keys defined above
607
608 Called inside transaction context on session to allocate a new
609 tenant network, typically from a type-specific resource
610 pool. If successful, return a segment dictionary describing
611 the segment. If tenant network segment cannot be allocated
612 (i.e. tenant networks not supported or resource pool is
613 exhausted), return None.
614 """
615
616 @abc.abstractmethod
617 def release_segment(self, session, segment):
618 """Release network segment.
619
620 :param session: database session
621 :param segment: segment dictionary using keys defined above
622
623 Called inside transaction context on session to release a
624 tenant or provider network's type-specific resource. Runtime
625 errors are not expected, but raising an exception will result
626 in rollback of the transaction.
627 """
628
629
630 class ML2TypeDriver(_TypeDriverBase, metaclass=abc.ABCMeta):
631 """Define abstract interface for ML2 type drivers.
632
633 ML2 type drivers each support a specific network_type for provider
634 and/or tenant network segments. Type drivers must implement this
635 abstract interface, which defines the API by which the plugin uses
636 the driver to manage the persistent type-specific resource
637 allocation state associated with network segments of that type.
638
639 Network segments are represented by segment dictionaries using the
640 NETWORK_TYPE, PHYSICAL_NETWORK, and SEGMENTATION_ID keys defined
641 above, corresponding to the provider attributes. Future revisions
642 of the TypeDriver API may add additional segment dictionary
643 keys. Attributes not applicable for a particular network_type may
644 either be excluded or stored as None.
645
646 ML2TypeDriver passes context as argument for:
647 - reserve_provider_segment
648 - allocate_tenant_segment
649 - release_segment
650 - get_allocation
651 """
652
653 @abc.abstractmethod
654 def reserve_provider_segment(self, context, segment, filters=None):
655 """Reserve resource associated with a provider network segment.
656
657 :param context: instance of neutron context with DB session
658 :param segment: segment dictionary
659 :param filters: a dictionary that is used as search criteria
660 :returns: segment dictionary
661
662 Called inside transaction context on session to reserve the
663 type-specific resource for a provider network segment. The
664 segment dictionary passed in was returned by a previous
665 validate_provider_segment() call.
666 """
667
668 @abc.abstractmethod
669 def allocate_tenant_segment(self, context, filters=None):
670 """Allocate resource for a new tenant network segment.
671
672 :param context: instance of neutron context with DB session
673 :param filters: a dictionary that is used as search criteria
674 :returns: segment dictionary using keys defined above
675
676 Called inside transaction context on session to allocate a new
677 tenant network, typically from a type-specific resource
678 pool. If successful, return a segment dictionary describing
679 the segment. If tenant network segment cannot be allocated
680 (i.e. tenant networks not supported or resource pool is
681 exhausted), return None.
682 """
683
684 @abc.abstractmethod
685 def release_segment(self, context, segment):
686 """Release network segment.
687
688 :param context: instance of neutron context with DB session
689 :param segment: segment dictionary using keys defined above
690
691 Called inside transaction context on session to release a
692 tenant or provider network's type-specific resource. Runtime
693 errors are not expected, but raising an exception will result
694 in rollback of the transaction.
695 """
696
697 @abc.abstractmethod
698 def initialize_network_segment_range_support(self):
699 """Perform driver network segment range initialization.
700
701 Called during the initialization of the ``network-segment-range``
702 service plugin if enabled, after all drivers have been loaded and the
703 database has been initialized. This reloads the `default`
704 network segment ranges when Neutron server starts/restarts.
705 """
706
707 @abc.abstractmethod
708 def update_network_segment_range_allocations(self):
709 """Update driver network segment range allocations.
710
711 This syncs the driver segment allocations when network segment ranges
712 have been created, updated or deleted.
713 """
714
715
716 class NetworkContext(metaclass=abc.ABCMeta):
717 """Context passed to MechanismDrivers for changes to network resources.
718
719 A NetworkContext instance wraps a network resource. It provides
720 helper methods for accessing other relevant information. Results
721 from expensive operations are cached so that other
722 MechanismDrivers can freely access the same information.
723 """
724
725 @property
726 @abc.abstractmethod
727 def current(self):
728 """Return the network in its current configuration.
729
730 Return the network, as defined by NeutronPluginBaseV2.
731 create_network and all extensions in the ml2 plugin, with
732 all its properties 'current' at the time the context was
733 established.
734 """
735
736 @property
737 @abc.abstractmethod
738 def original(self):
739 """Return the network in its original configuration.
740
741 Return the network, with all its properties set to their
742 original values prior to a call to update_network. Method is
743 only valid within calls to update_network_precommit and
744 update_network_postcommit.
745 """
746
747 @property
748 @abc.abstractmethod
749 def network_segments(self):
750 """Return the segments associated with this network resource."""
751
752
753 class SubnetContext(metaclass=abc.ABCMeta):
754 """Context passed to MechanismDrivers for changes to subnet resources.
755
756 A SubnetContext instance wraps a subnet resource. It provides
757 helper methods for accessing other relevant information. Results
758 from expensive operations are cached so that other
759 MechanismDrivers can freely access the same information.
760 """
761
762 @property
763 @abc.abstractmethod
764 def current(self):
765 """Return the subnet in its current configuration.
766
767 Return the subnet, as defined by NeutronPluginBaseV2.
768 create_subnet and all extensions in the ml2 plugin, with
769 all its properties 'current' at the time the context was
770 established.
771 """
772
773 @property
774 @abc.abstractmethod
775 def original(self):
776 """Return the subnet in its original configuration.
777
778 Return the subnet, with all its properties set to their
779 original values prior to a call to update_subnet. Method is
780 only valid within calls to update_subnet_precommit and
781 update_subnet_postcommit.
782 """
783
784
785 class PortContext(metaclass=abc.ABCMeta):
786 """Context passed to MechanismDrivers for changes to port resources.
787
788 A PortContext instance wraps a port resource. It provides helper
789 methods for accessing other relevant information. Results from
790 expensive operations are cached so that other MechanismDrivers can
791 freely access the same information.
792 """
793
794 @property
795 @abc.abstractmethod
796 def current(self):
797 """Return the port in its current configuration.
798
799 Return the port, as defined by NeutronPluginBaseV2.
800 create_port and all extensions in the ml2 plugin, with
801 all its properties 'current' at the time the context was
802 established.
803 """
804
805 @property
806 @abc.abstractmethod
807 def original(self):
808 """Return the port in its original configuration.
809
810 Return the port, with all its properties set to their
811 original values prior to a call to update_port. Method is
812 only valid within calls to update_port_precommit and
813 update_port_postcommit.
814 """
815
816 @property
817 @abc.abstractmethod
818 def status(self):
819 """Return the status of the current port."""
820
821 @property
822 @abc.abstractmethod
823 def original_status(self):
824 """Return the status of the original port.
825
826 The method is only valid within calls to update_port_precommit and
827 update_port_postcommit.
828 """
829
830 @property
831 @abc.abstractmethod
832 def network(self):
833 """Return the NetworkContext associated with this port."""
834
835 @property
836 @abc.abstractmethod
837 def binding_levels(self):
838 """Return dictionaries describing the current binding levels.
839
840 This property returns a list of dictionaries describing each
841 binding level if the port is bound or partially bound, or None
842 if the port is unbound. Each returned dictionary contains the
843 name of the bound driver under the BOUND_DRIVER key, and the
844 bound segment dictionary under the BOUND_SEGMENT key.
845
846 The first entry (index 0) describes the top-level binding,
847 which always involves one of the port's network's static
848 segments. In the case of a hierarchical binding, subsequent
849 entries describe the lower-level bindings in descending order,
850 which may involve dynamic segments. Adjacent levels where
851 different drivers bind the same static or dynamic segment are
852 possible. The last entry (index -1) describes the bottom-level
853 binding that supplied the port's binding:vif_type and
854 binding:vif_details attribute values.
855
856 Within calls to MechanismDriver.bind_port, descriptions of the
857 levels above the level currently being bound are returned.
858 """
859
860 @property
861 @abc.abstractmethod
862 def original_binding_levels(self):
863 """Return dictionaries describing the original binding levels.
864
865 This property returns a list of dictionaries describing each
866 original binding level if the port was previously bound, or
867 None if the port was unbound. The content is as described for
868 the binding_levels property.
869
870 This property is only valid within calls to
871 update_port_precommit and update_port_postcommit. It returns
872 None otherwise.
873 """
874
875 @property
876 @abc.abstractmethod
877 def top_bound_segment(self):
878 """Return the current top-level bound segment dictionary.
879
880 This property returns the current top-level bound segment
881 dictionary, or None if the port is unbound. For a bound port,
882 top_bound_segment is equivalent to
883 binding_levels[0][BOUND_SEGMENT], and returns one of the
884 port's network's static segments.
885 """
886
887 @property
888 @abc.abstractmethod
889 def original_top_bound_segment(self):
890 """Return the original top-level bound segment dictionary.
891
892 This property returns the original top-level bound segment
893 dictionary, or None if the port was previously unbound. For a
894 previously bound port, original_top_bound_segment is
895 equivalent to original_binding_levels[0][BOUND_SEGMENT], and
896 returns one of the port's network's static segments.
897
898 This property is only valid within calls to
899 update_port_precommit and update_port_postcommit. It returns
900 None otherwise.
901 """
902
903 @property
904 @abc.abstractmethod
905 def bottom_bound_segment(self):
906 """Return the current bottom-level bound segment dictionary.
907
908 This property returns the current bottom-level bound segment
909 dictionary, or None if the port is unbound. For a bound port,
910 bottom_bound_segment is equivalent to
911 binding_levels[-1][BOUND_SEGMENT], and returns the segment
912 whose binding supplied the port's binding:vif_type and
913 binding:vif_details attribute values.
914 """
915
916 @property
917 @abc.abstractmethod
918 def original_bottom_bound_segment(self):
919 """Return the original bottom-level bound segment dictionary.
920
921 This property returns the original bottom-level bound segment
922 dictionary, or None if the port was previously unbound. For a
923 previously bound port, original_bottom_bound_segment is
924 equivalent to original_binding_levels[-1][BOUND_SEGMENT], and
925 returns the segment whose binding supplied the port's previous
926 binding:vif_type and binding:vif_details attribute values.
927
928 This property is only valid within calls to
929 update_port_precommit and update_port_postcommit. It returns
930 None otherwise.
931 """
932
933 @property
934 @abc.abstractmethod
935 def host(self):
936 """Return the host with which the port is associated.
937
938 In the context of a host-specific operation on a distributed
939 port, the host property indicates the host for which the port
940 operation is being performed. Otherwise, it is the same value
941 as current['binding:host_id'].
942 """
943
944 @property
945 @abc.abstractmethod
946 def original_host(self):
947 """Return the original host with which the port was associated.
948
949 In the context of a host-specific operation on a distributed
950 port, the original_host property indicates the host for which
951 the port operation is being performed. Otherwise, it is the
952 same value as original['binding:host_id'].
953
954 This property is only valid within calls to
955 update_port_precommit and update_port_postcommit. It returns
956 None otherwise.
957 """
958
959 @property
960 @abc.abstractmethod
961 def vif_type(self):
962 """Return the vif_type indicating the binding state of the port.
963
964 In the context of a host-specific operation on a distributed
965 port, the vif_type property indicates the binding state for
966 the host for which the port operation is being
967 performed. Otherwise, it is the same value as
968 current['binding:vif_type'].
969 """
970
971 @property
972 @abc.abstractmethod
973 def original_vif_type(self):
974 """Return the original vif_type of the port.
975
976 In the context of a host-specific operation on a distributed
977 port, the original_vif_type property indicates original
978 binding state for the host for which the port operation is
979 being performed. Otherwise, it is the same value as
980 original['binding:vif_type'].
981
982 This property is only valid within calls to
983 update_port_precommit and update_port_postcommit. It returns
984 None otherwise.
985 """
986
987 @property
988 @abc.abstractmethod
989 def vif_details(self):
990 """Return the vif_details describing the binding of the port.
991
992 In the context of a host-specific operation on a distributed
993 port, the vif_details property describes the binding for the
994 host for which the port operation is being
995 performed. Otherwise, it is the same value as
996 current['binding:vif_details'].
997 """
998
999 @property
1000 @abc.abstractmethod
1001 def original_vif_details(self):
1002 """Return the original vif_details of the port.
1003
1004 In the context of a host-specific operation on a distributed
1005 port, the original_vif_details property describes the original
1006 binding for the host for which the port operation is being
1007 performed. Otherwise, it is the same value as
1008 original['binding:vif_details'].
1009
1010 This property is only valid within calls to
1011 update_port_precommit and update_port_postcommit. It returns
1012 None otherwise.
1013 """
1014
1015 @property
1016 @abc.abstractmethod
1017 def segments_to_bind(self):
1018 """Return the list of segments with which to bind the port.
1019
1020 This property returns the list of segment dictionaries with
1021 which the mechanism driver may bind the port. When
1022 establishing a top-level binding, these will be the port's
1023 network's static segments. For each subsequent level, these
1024 will be the segments passed to continue_binding by the
1025 mechanism driver that bound the level above.
1026
1027 This property is only valid within calls to
1028 MechanismDriver.bind_port. It returns None otherwise.
1029 """
1030
1031 @abc.abstractmethod
1032 def host_agents(self, agent_type):
1033 """Get agents of the specified type on port's host.
1034
1035 :param agent_type: Agent type identifier
1036 :returns: List of neutron.db.models.agent.Agent records
1037 """
1038
1039 @abc.abstractmethod
1040 def set_binding(self, segment_id, vif_type, vif_details,
1041 status=None):
1042 """Set the bottom-level binding for the port.
1043
1044 :param segment_id: Network segment bound for the port.
1045 :param vif_type: The VIF type for the bound port.
1046 :param vif_details: Dictionary with details for VIF driver.
1047 :param status: Port status to set if not None.
1048
1049 This method is called by MechanismDriver.bind_port to indicate
1050 success and specify binding details to use for port. The
1051 segment_id must identify an item in the current value of the
1052 segments_to_bind property.
1053 """
1054
1055 @abc.abstractmethod
1056 def continue_binding(self, segment_id, next_segments_to_bind):
1057 """Continue binding the port with different segments.
1058
1059 :param segment_id: Network segment partially bound for the port.
1060 :param next_segments_to_bind: Segments to continue binding with.
1061
1062 This method is called by MechanismDriver.bind_port to indicate
1063 it was able to partially bind the port, but that one or more
1064 additional mechanism drivers are required to complete the
1065 binding. The segment_id must identify an item in the current
1066 value of the segments_to_bind property. The list of segments
1067 IDs passed as next_segments_to_bind identify dynamic (or
1068 static) segments of the port's network that will be used to
1069 populate segments_to_bind for the next lower level of a
1070 hierarchical binding.
1071 """
1072
1073 @abc.abstractmethod
1074 def allocate_dynamic_segment(self, segment):
1075 """Allocate a dynamic segment.
1076
1077 :param segment: A partially or fully specified segment dictionary
1078
1079 Called by the MechanismDriver.bind_port, create_port or update_port
1080 to dynamically allocate a segment for the port using the partial
1081 segment specified. The segment dictionary can be a fully or partially
1082 specified segment. At a minimum it needs the network_type populated to
1083 call on the appropriate type driver.
1084 """
1085
1086 @abc.abstractmethod
1087 def release_dynamic_segment(self, segment_id):
1088 """Release an allocated dynamic segment.
1089
1090 :param segment_id: UUID of the dynamic network segment.
1091
1092 Called by the MechanismDriver.delete_port or update_port to release
1093 the dynamic segment allocated for this port.
1094 """
1095
1096
1097 class ExtensionDriver(metaclass=abc.ABCMeta):
1098 """Define stable abstract interface for ML2 extension drivers.
1099
1100 An extension driver extends the core resources implemented by the
1101 ML2 plugin with additional attributes. Methods that process create
1102 and update operations for these resources validate and persist
1103 values for extended attributes supplied through the API. Other
1104 methods extend the resource dictionaries returned from the API
1105 operations with the values of the extended attributes.
1106 """
1107
1108 @abc.abstractmethod
1109 def initialize(self):
1110 """Perform driver initialization.
1111
1112 Called after all drivers have been loaded and the database has
1113 been initialized. No abstract methods defined below will be
1114 called prior to this method being called.
1115 """
1116
1117 @property
1118 def extension_alias(self):
1119 """Supported extension alias.
1120
1121 Return the alias identifying the core API extension supported
1122 by this driver. Do not declare if API extension handling will
1123 be left to a service plugin, and we just need to provide
1124 core resource extension and updates.
1125 """
1126 return
1127
1128 @property
1129 def extension_aliases(self):
1130 """List of extension aliases supported by the driver.
1131
1132 Return a list of aliases identifying the core API extensions
1133 supported by the driver. By default this just returns the
1134 extension_alias property for backwards compatibility.
1135 """
1136 return [self.extension_alias]
1137
1138 def process_create_network(self, plugin_context, data, result):
1139 """Process extended attributes for create network.
1140
1141 :param plugin_context: plugin request context
1142 :param data: dictionary of incoming network data
1143 :param result: network dictionary to extend
1144
1145 Called inside transaction context on plugin_context.session to
1146 validate and persist any extended network attributes defined by this
1147 driver. Extended attribute values must also be added to
1148 result.
1149 """
1150 pass
1151
1152 def process_create_subnet(self, plugin_context, data, result):
1153 """Process extended attributes for create subnet.
1154
1155 :param plugin_context: plugin request context
1156 :param data: dictionary of incoming subnet data
1157 :param result: subnet dictionary to extend
1158
1159 Called inside transaction context on plugin_context.session to
1160 validate and persist any extended subnet attributes defined by this
1161 driver. Extended attribute values must also be added to
1162 result.
1163 """
1164 pass
1165
1166 def process_create_port(self, plugin_context, data, result):
1167 """Process extended attributes for create port.
1168
1169 :param plugin_context: plugin request context
1170 :param data: dictionary of incoming port data
1171 :param result: port dictionary to extend
1172
1173 Called inside transaction context on plugin_context.session to
1174 validate and persist any extended port attributes defined by this
1175 driver. Extended attribute values must also be added to
1176 result.
1177 """
1178 pass
1179
1180 def process_update_network(self, plugin_context, data, result):
1181 """Process extended attributes for update network.
1182
1183 :param plugin_context: plugin request context
1184 :param data: dictionary of incoming network data
1185 :param result: network dictionary to extend
1186
1187 Called inside transaction context on plugin_context.session to
1188 validate and update any extended network attributes defined by this
1189 driver. Extended attribute values, whether updated or not,
1190 must also be added to result.
1191 """
1192 pass
1193
1194 def process_update_subnet(self, plugin_context, data, result):
1195 """Process extended attributes for update subnet.
1196
1197 :param plugin_context: plugin request context
1198 :param data: dictionary of incoming subnet data
1199 :param result: subnet dictionary to extend
1200
1201 Called inside transaction context on plugin_context.session to
1202 validate and update any extended subnet attributes defined by this
1203 driver. Extended attribute values, whether updated or not,
1204 must also be added to result.
1205 """
1206 pass
1207
1208 def process_update_port(self, plugin_context, data, result):
1209 """Process extended attributes for update port.
1210
1211 :param plugin_context: plugin request context
1212 :param data: dictionary of incoming port data
1213 :param result: port dictionary to extend
1214
1215 Called inside transaction context on plugin_context.session to
1216 validate and update any extended port attributes defined by this
1217 driver. Extended attribute values, whether updated or not,
1218 must also be added to result.
1219 """
1220 pass
1221
1222 def extend_network_dict(self, session, base_model, result):
1223 """Add extended attributes to network dictionary.
1224
1225 :param session: database session
1226 :param base_model: network model data
1227 :param result: network dictionary to extend
1228
1229 Called inside transaction context on session to add any
1230 extended attributes defined by this driver to a network
1231 dictionary to be used for mechanism driver calls and/or
1232 returned as the result of a network operation.
1233 """
1234 pass
1235
1236 def extend_subnet_dict(self, session, base_model, result):
1237 """Add extended attributes to subnet dictionary.
1238
1239 :param session: database session
1240 :param base_model: subnet model data
1241 :param result: subnet dictionary to extend
1242
1243 Called inside transaction context on session to add any
1244 extended attributes defined by this driver to a subnet
1245 dictionary to be used for mechanism driver calls and/or
1246 returned as the result of a subnet operation.
1247 """
1248 pass
1249
1250 def extend_port_dict(self, session, base_model, result):
1251 """Add extended attributes to port dictionary.
1252
1253 :param session: database session
1254 :param base_model: port model data
1255 :param result: port dictionary to extend
1256
1257 Called inside transaction context on session to add any
1258 extended attributes defined by this driver to a port
1259 dictionary to be used for mechanism driver calls
1260 and/or returned as the result of a port operation.
1261 """
1262 pass