|
9 | 9 | from oslo_config import cfg
|
10 | 10 | from oslo_log import log
|
11 | 11 |
|
12 |
| -from neutron_understack import config |
13 | 12 | from neutron_understack import utils
|
14 |
| -from neutron_understack.nautobot import Nautobot |
15 |
| - |
16 |
| -config.register_ml2_understack_opts(cfg.CONF) |
17 | 13 |
|
18 | 14 | LOG = log.getLogger(__name__)
|
19 | 15 |
|
@@ -48,8 +44,7 @@ def __init__(
|
48 | 44 | agent_type=agent_type,
|
49 | 45 | can_trunk_bound_port=can_trunk_bound_port,
|
50 | 46 | )
|
51 |
| - conf = cfg.CONF.ml2_understack |
52 |
| - self.nb = Nautobot(conf.nb_url, conf.nb_token) |
| 47 | + self.nb = self.plugin_driver.nb |
53 | 48 |
|
54 | 49 | @property
|
55 | 50 | def is_loaded(self):
|
@@ -83,41 +78,46 @@ def register(self, resource, event, trigger, payload=None):
|
83 | 78 | self.trunk_created, resources.TRUNK, events.AFTER_CREATE, cancellable=True
|
84 | 79 | )
|
85 | 80 |
|
86 |
| - def _configure_tenant_vlan_id( |
87 |
| - self, tenant_vlan_id: int | None, ucvni_uuid: str, subport: SubPort |
| 81 | + def _handle_segmentation_id_mismatch( |
| 82 | + self, subport: SubPort, ucvni_uuid: str, tenant_vlan_id: int |
88 | 83 | ) -> None:
|
| 84 | + subport.delete() |
| 85 | + raise SubportSegmentationIDError( |
| 86 | + seg_id=subport.segmentation_id, |
| 87 | + net_id=ucvni_uuid, |
| 88 | + nb_seg_id=tenant_vlan_id, |
| 89 | + subport_id=subport.port_id, |
| 90 | + ) |
| 91 | + |
| 92 | + def _configure_tenant_vlan_id(self, ucvni_uuid: str, subport: SubPort) -> None: |
89 | 93 | subport_seg_id = subport.segmentation_id
|
90 |
| - if not tenant_vlan_id: |
91 |
| - self.nb.add_tenant_vlan_tag_to_ucvni( |
92 |
| - network_uuid=ucvni_uuid, vlan_tag=subport_seg_id |
93 |
| - ) |
94 |
| - LOG.info( |
95 |
| - "Segmentation ID: %(seg_id)s is now set on Nautobot's UCVNI " |
96 |
| - "UUID: %(ucvni_uuid)s in the tenant_vlan_id custom field", |
97 |
| - {"seg_id": subport_seg_id, "ucvni_uuid": ucvni_uuid}, |
98 |
| - ) |
99 |
| - elif tenant_vlan_id != subport_seg_id: |
100 |
| - subport.delete() |
101 |
| - raise SubportSegmentationIDError( |
102 |
| - seg_id=subport_seg_id, |
103 |
| - net_id=ucvni_uuid, |
104 |
| - nb_seg_id=tenant_vlan_id, |
105 |
| - subport_id=subport.port_id, |
106 |
| - ) |
| 94 | + self.nb.add_tenant_vlan_tag_to_ucvni( |
| 95 | + network_uuid=ucvni_uuid, vlan_tag=subport_seg_id |
| 96 | + ) |
| 97 | + LOG.info( |
| 98 | + "Segmentation ID: %(seg_id)s is now set on Nautobot's UCVNI " |
| 99 | + "UUID: %(ucvni_uuid)s in the tenant_vlan_id custom field", |
| 100 | + {"seg_id": subport_seg_id, "ucvni_uuid": ucvni_uuid}, |
| 101 | + ) |
107 | 102 |
|
108 | 103 | def _subports_added(self, subports: list[SubPort]) -> None:
|
109 | 104 | for subport in subports:
|
110 |
| - subport_id = subport.port_id |
111 |
| - subport_network_id = utils.fetch_subport_network_id(subport_id=subport_id) |
| 105 | + subport_network_id = utils.fetch_subport_network_id( |
| 106 | + subport_id=subport.port_id |
| 107 | + ) |
112 | 108 | ucvni_tenant_vlan_id = self.nb.fetch_ucvni_tenant_vlan_id(
|
113 | 109 | network_id=subport_network_id
|
114 | 110 | )
|
115 |
| - |
116 |
| - self._configure_tenant_vlan_id( |
117 |
| - tenant_vlan_id=ucvni_tenant_vlan_id, |
118 |
| - ucvni_uuid=subport_network_id, |
119 |
| - subport=subport, |
120 |
| - ) |
| 111 | + if not ucvni_tenant_vlan_id: |
| 112 | + self._configure_tenant_vlan_id( |
| 113 | + ucvni_uuid=subport_network_id, subport=subport |
| 114 | + ) |
| 115 | + elif ucvni_tenant_vlan_id != subport.segmentation_id: |
| 116 | + self._handle_segmentation_id_mismatch( |
| 117 | + subport=subport, |
| 118 | + ucvni_uuid=subport_network_id, |
| 119 | + tenant_vlan_id=ucvni_tenant_vlan_id, |
| 120 | + ) |
121 | 121 |
|
122 | 122 | def subports_added(self, resource, event, trunk_plugin, payload):
|
123 | 123 | subports = payload.metadata["subports"]
|
|
0 commit comments