-
Notifications
You must be signed in to change notification settings - Fork 9
feat: Implement vrf router with auto-allocating evpn_vni attribute #2109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stevekeay
wants to merge
2
commits into
main
Choose a base branch
from
vrf-router-evpn-vni
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| __version__ = "0.1" | ||
|
|
||
| # Neutron's extension loader looks for ``<service_plugin_root>.extensions`` as | ||
| # an attribute on the imported top-level package. | ||
| from neutron_understack import extensions # noqa: F401 |
Empty file.
Empty file.
37 changes: 37 additions & 0 deletions
37
python/neutron-understack/neutron_understack/api/definitions/understack_vni.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from neutron_lib import constants | ||
| from neutron_lib.api import converters | ||
| from neutron_lib.api.definitions import l3 | ||
|
|
||
| ALIAS = "understack_vni" | ||
| IS_SHIM_EXTENSION = False | ||
| IS_STANDARD_ATTR_EXTENSION = False | ||
| NAME = "Understack Router VNI" | ||
| API_PREFIX = "" | ||
| DESCRIPTION = "Router extension for Understack hardware VRF VNI allocation" | ||
| UPDATED_TIMESTAMP = "2026-07-01T00:00:00-00:00" | ||
| RESOURCE_NAME = l3.ROUTER | ||
| COLLECTION_NAME = l3.ROUTERS | ||
|
|
||
| EVPN_VNI = "evpn_vni" | ||
|
|
||
| RESOURCE_ATTRIBUTE_MAP = { | ||
| COLLECTION_NAME: { | ||
| EVPN_VNI: { | ||
| "allow_post": True, | ||
| "allow_put": False, | ||
| "convert_to": converters.convert_to_int_if_not_none, | ||
| "default": 0, | ||
| "is_visible": True, | ||
| "is_filter": True, | ||
| "is_sort_key": True, | ||
| "enforce_policy": True, | ||
| "validate": {"type:range_or_none": [0, constants.MAX_VXLAN_VNI]}, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| SUB_RESOURCE_ATTRIBUTE_MAP = {} | ||
| ACTION_MAP = {} | ||
| REQUIRED_EXTENSIONS = [l3.ALIAS] | ||
| OPTIONAL_EXTENSIONS = [] | ||
| ACTION_STATUS = {} | ||
Empty file.
9 changes: 9 additions & 0 deletions
9
python/neutron-understack/neutron_understack/conf/policies/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import itertools | ||
|
|
||
| from neutron_understack.conf.policies import evpn | ||
|
|
||
|
|
||
| def list_rules(): | ||
| return itertools.chain( | ||
| evpn.list_rules(), | ||
| ) |
34 changes: 34 additions & 0 deletions
34
python/neutron-understack/neutron_understack/conf/policies/evpn.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| from neutron.conf.policies import base | ||
| from oslo_policy import policy | ||
|
|
||
| COLLECTION_PATH = "/routers" | ||
| RESOURCE_PATH = "/routers/{id}" | ||
|
|
||
| ACTION_POST = [ | ||
| {"method": "POST", "path": COLLECTION_PATH}, | ||
| ] | ||
| ACTION_GET = [ | ||
| {"method": "GET", "path": COLLECTION_PATH}, | ||
| {"method": "GET", "path": RESOURCE_PATH}, | ||
| ] | ||
|
|
||
| rules = [ | ||
| policy.DocumentedRuleDefault( | ||
| name="create_router:evpn_vni", | ||
| check_str=base.ADMIN, | ||
| scope_types=["project"], | ||
| description="Specify ``evpn_vni`` attribute when creating a router", | ||
| operations=ACTION_POST, | ||
| ), | ||
| policy.DocumentedRuleDefault( | ||
| name="get_router:evpn_vni", | ||
| check_str=base.ADMIN_OR_PROJECT_READER, | ||
| scope_types=["project"], | ||
| description="Get ``evpn_vni`` attribute of a router", | ||
| operations=ACTION_GET, | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| def list_rules(): | ||
| return rules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
67 changes: 67 additions & 0 deletions
67
python/neutron-understack/neutron_understack/db/migration/alembic_migrations/env.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| from logging.config import fileConfig | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import context | ||
| from neutron_lib.db import model_base | ||
| from oslo_config import cfg | ||
| from oslo_db.sqlalchemy import session | ||
| from sqlalchemy import event | ||
|
|
||
| VERSION_TABLE = "neutron_understack_alembic_version" | ||
| MYSQL_ENGINE = None | ||
| config = context.config | ||
| neutron_config = config.neutron_config | ||
| fileConfig(config.config_file_name) | ||
| target_metadata = model_base.BASEV2.metadata | ||
|
|
||
|
|
||
| def set_mysql_engine(): | ||
| try: | ||
| mysql_engine = neutron_config.command.mysql_engine | ||
| except cfg.NoSuchOptError: | ||
| mysql_engine = None | ||
|
|
||
| global MYSQL_ENGINE # noqa: PLW0603 | ||
| MYSQL_ENGINE = mysql_engine or model_base.BASEV2.__table_args__["mysql_engine"] | ||
|
|
||
|
|
||
| def run_migrations_offline(): | ||
| set_mysql_engine() | ||
| kwargs = {"version_table": VERSION_TABLE} | ||
| if neutron_config.database.connection: | ||
| kwargs["url"] = neutron_config.database.connection | ||
| else: | ||
| kwargs["dialect_name"] = neutron_config.database.engine | ||
| context.configure(**kwargs) | ||
|
|
||
| with context.begin_transaction(): | ||
| context.run_migrations() | ||
|
|
||
|
|
||
| @event.listens_for(sa.Table, "after_parent_attach") | ||
| def set_storage_engine(target, parent): | ||
| if MYSQL_ENGINE: | ||
| target.kwargs["mysql_engine"] = MYSQL_ENGINE | ||
|
|
||
|
|
||
| def run_migrations_online(): | ||
| set_mysql_engine() | ||
| engine = session.create_engine(neutron_config.database.connection) | ||
| connection = engine.connect() | ||
| context.configure( | ||
| connection=connection, | ||
| target_metadata=target_metadata, | ||
| version_table=VERSION_TABLE, | ||
| ) | ||
| try: | ||
| with context.begin_transaction(): | ||
| context.run_migrations() | ||
| finally: | ||
| connection.close() | ||
| engine.dispose() | ||
|
|
||
|
|
||
| if context.is_offline_mode(): | ||
| run_migrations_offline() | ||
| else: | ||
| run_migrations_online() |
38 changes: 38 additions & 0 deletions
38
python/neutron-understack/neutron_understack/db/migration/alembic_migrations/script.py.mako
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Copyright ${create_date.year} Understack Developers | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
| # not use this file except in compliance with the License. You may obtain | ||
| # a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| # License for the specific language governing permissions and limitations | ||
| # under the License. | ||
| # | ||
|
|
||
| """${message} | ||
|
|
||
| Revision ID: ${up_revision} | ||
| Revises: ${down_revision} | ||
| Create Date: ${create_date} | ||
|
|
||
| """ | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
| ${imports if imports else ""} | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = ${repr(up_revision)} | ||
| down_revision = ${repr(down_revision)} | ||
| % if branch_labels: | ||
| branch_labels = ${repr(branch_labels)} | ||
| % endif | ||
|
|
||
|
|
||
| def upgrade(): | ||
| ${upgrades if upgrades else "pass"} |
Empty file.
17 changes: 17 additions & 0 deletions
17
...gration/alembic_migrations/versions/2026.1/contract/8f5b7d0f4b2b_start_contract_branch.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| """Start neutron-understack contract branch. | ||
|
|
||
| Revision ID: 8f5b7d0f4b2b | ||
| Revises: start_neutron_understack | ||
| Create Date: 2026-07-01 00:00:00.000000 | ||
|
|
||
| """ | ||
|
|
||
| from neutron.db.migration import cli | ||
|
|
||
| revision = "8f5b7d0f4b2b" | ||
| down_revision = "start_neutron_understack" | ||
| branch_labels = (cli.CONTRACT_BRANCH,) | ||
|
|
||
|
|
||
| def upgrade(): | ||
| pass |
Empty file.
36 changes: 36 additions & 0 deletions
36
.../alembic_migrations/versions/2026.1/expand/5b7f7d0f4b2a_add_understack_vni_allocations.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| """Add Understack router VNI allocation table. | ||
|
|
||
| Revision ID: 5b7f7d0f4b2a | ||
| Revises: start_neutron_understack | ||
| Create Date: 2026-07-01 00:00:00.000000 | ||
|
|
||
| """ | ||
|
|
||
| import sqlalchemy as sa | ||
| from neutron.db import migration | ||
| from neutron.db.migration import cli | ||
|
|
||
| revision = "5b7f7d0f4b2a" | ||
| down_revision = "start_neutron_understack" | ||
| branch_labels = (cli.EXPAND_BRANCH,) | ||
|
|
||
|
|
||
| def upgrade(): | ||
| migration.create_table_if_not_exists( | ||
| "understack_router_vni_allocations", | ||
| sa.Column("vni", sa.Integer(), autoincrement=False, nullable=False), | ||
| sa.Column("router_id", sa.String(length=36), nullable=True), | ||
| sa.Column( | ||
| "allocated_at", | ||
| sa.DateTime(), | ||
| nullable=False, | ||
| server_default=sa.func.now(), | ||
| ), | ||
| sa.Column("released_at", sa.DateTime(), nullable=True), | ||
| sa.ForeignKeyConstraint(["router_id"], ["routers.id"], ondelete="SET NULL"), | ||
| sa.PrimaryKeyConstraint("vni"), | ||
| sa.UniqueConstraint( | ||
| "router_id", | ||
| name="uniq_understack_router_vni_allocations0router_id", | ||
| ), | ||
| ) |
Empty file.
1 change: 1 addition & 0 deletions
1
...tron-understack/neutron_understack/db/migration/alembic_migrations/versions/CONTRACT_HEAD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 8f5b7d0f4b2b |
1 change: 1 addition & 0 deletions
1
...eutron-understack/neutron_understack/db/migration/alembic_migrations/versions/EXPAND_HEAD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 5b7f7d0f4b2a |
Empty file.
14 changes: 14 additions & 0 deletions
14
...k/neutron_understack/db/migration/alembic_migrations/versions/start_neutron_understack.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| """Start neutron-understack migration chain. | ||
|
|
||
| Revision ID: start_neutron_understack | ||
| Revises: None | ||
| Create Date: 2026-07-01 00:00:00.000000 | ||
|
|
||
| """ | ||
|
|
||
| revision = "start_neutron_understack" | ||
| down_revision = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| pass |
43 changes: 43 additions & 0 deletions
43
python/neutron-understack/neutron_understack/db/understack_vni.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import sqlalchemy as sa | ||
| from neutron_lib.db import model_base | ||
| from sqlalchemy import orm | ||
|
|
||
|
|
||
| class UnderstackRouterVNIAllocation(model_base.BASEV2): | ||
| __tablename__ = "understack_router_vni_allocations" | ||
|
|
||
| vni = sa.Column(sa.Integer(), primary_key=True, autoincrement=False) | ||
| router_id = sa.Column( | ||
| sa.String(36), | ||
| sa.ForeignKey("routers.id", ondelete="SET NULL"), | ||
| nullable=True, | ||
| ) | ||
| allocated_at = sa.Column( | ||
| sa.DateTime(), | ||
| nullable=False, | ||
| server_default=sa.func.now(), | ||
| ) | ||
| released_at = sa.Column(sa.DateTime(), nullable=True) | ||
|
|
||
| __table_args__ = ( | ||
| sa.UniqueConstraint( | ||
| "router_id", | ||
| name="uniq_understack_router_vni_allocations0router_id", | ||
| ), | ||
| model_base.BASEV2.__table_args__, | ||
| ) | ||
|
|
||
| router = orm.relationship( | ||
| "Router", | ||
| lazy="noload", | ||
| load_on_pending=True, | ||
| viewonly=True, | ||
| backref=orm.backref( | ||
| "understack_vni_allocation", | ||
| lazy="selectin", | ||
| uselist=False, | ||
| viewonly=True, | ||
| ), | ||
| ) | ||
|
|
||
| revises_on_change = ("router",) |
Empty file.
23 changes: 23 additions & 0 deletions
23
python/neutron-understack/neutron_understack/extensions/understack_vni.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from importlib import util as importlib_util | ||
|
|
||
| from neutron_lib.api import extensions | ||
|
|
||
| try: | ||
| from neutron_lib.api.definitions import evpn as evpn_apidef | ||
| except ImportError: | ||
| evpn_apidef = None | ||
|
|
||
| from neutron_understack.api.definitions import understack_vni as apidef | ||
|
|
||
|
|
||
| def _api_definition(): | ||
| if ( | ||
| evpn_apidef is not None | ||
| and importlib_util.find_spec("neutron.extensions.evpn") is None | ||
| ): | ||
| return evpn_apidef | ||
| return apidef | ||
|
|
||
|
|
||
| class Understack_vni(extensions.APIExtensionDescriptor): | ||
| api_definition = _api_definition() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should that be
0orATTR_NOT_SPECIFIED? I am concerned if having it as 0 will not prevent non-admin users from creating routersThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit hazy on the logic for collections, but I think we want non-admin users to create routers, we just don't want them to be able to choose a VNI.
A value of zero is explicitly interpreted as "please auto-assign" in the assignment hook, so the value that actually gets persisted should be non-zero.
Technically it may be more correct to use the sentinel value but I thought this was going to the DB layer, I'm not sure what the best answer is.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The python/neutron-understack/neutron_understack/conf/policies/evpn.py has:
which will translate to
"create_router:evpn_vni": "rule:admin_only"inside a default policy (similarly to stock one and if the user provides any value of the attribute in the request, it will match the rule, effectively requiring admin privileges, so we may need to adjustbase.ADMINto sth else.