From 50bb3bf96fd1ceac31fe1ad60513958a7f420464 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Thu, 26 Sep 2024 15:57:06 -0500 Subject: [PATCH] feat(neutron-understack): create VNIs on network create When a network is created in neutron, the corresponding VNI will be created inside of Nautobot. --- .../neutron_understack/config.py | 4 +++ .../neutron_understack_mech.py | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/python/neutron-understack/neutron_understack/config.py b/python/neutron-understack/neutron_understack/config.py index 97d24e821..03085c384 100644 --- a/python/neutron-understack/neutron_understack/config.py +++ b/python/neutron-understack/neutron_understack/config.py @@ -39,6 +39,10 @@ "nb_token", help="Nautobot API token", ), + cfg.StrOpt( + "ucvni_group", + help="hack", + ), ] diff --git a/python/neutron-understack/neutron_understack/neutron_understack_mech.py b/python/neutron-understack/neutron_understack/neutron_understack_mech.py index 4c6e6bf0b..4da0ff079 100644 --- a/python/neutron-understack/neutron_understack/neutron_understack_mech.py +++ b/python/neutron-understack/neutron_understack/neutron_understack_mech.py @@ -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, @@ -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.TYPE_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)