Skip to content

Commit

Permalink
feat(neutron-understack): create VNIs on network create
Browse files Browse the repository at this point in the history
When a network is created in neutron, the corresponding VNI will be
created inside of Nautobot.
  • Loading branch information
cardoe committed Sep 26, 2024
1 parent 610895e commit bcec408
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/neutron-understack/neutron_understack/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
"nb_token",
help="Nautobot API token",
),
cfg.StrOpt(
"ucvni_group",
help="hack",
),
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import neutron_lib.api.definitions.portbindings as portbindings
from neutron_lib import constants as p_const
from neutron_lib import exceptions as exc
from neutron_lib.plugins.ml2 import api
from neutron_lib.plugins.ml2.api import (
MechanismDriver,
Expand Down Expand Up @@ -117,6 +118,32 @@ def create_network_precommit(self, context):
def create_network_postcommit(self, context):
log_call("create_network_postcommit", context)

network = context.current
network_id = network["id"]
network_name = network["name"]
provider_type = network.get("provider:network_type")
segmentation_id = network.get("provider:segmentation_id")
physnet = network.get("provider:physical_network")

if provider_type == p_const.VXLAN and segmentation_id:
conf = cfg.CONF.ml2_understack
ucvni_group = conf.ucvni_group
try:
self.nb.ucvni_create(
network_id, segmentation_id, ucvni_group, network_name
)
except Exception as e:
LOG.exception(
"unable to create network %(net_id)s", {"net_id": network_id}
)
raise exc.NetworkNotFound(net_id=network_id) from e

LOG.info(
"network %(net_id)s has been added on ucvni_group %(ucvni_group) "
"/ physnet %(physnet)",
{"net_id": network_id, "ucvni_group": ucvni_group, "physnet": physnet},
)

def update_network_precommit(self, context):
log_call("update_network_precommit", context)

Expand Down

0 comments on commit bcec408

Please sign in to comment.