Skip to content

Commit

Permalink
Merge pull request #456 from rackerlabs/delete_tenant_network
Browse files Browse the repository at this point in the history
feat: delete tenant network
  • Loading branch information
cardoe authored Nov 8, 2024
2 parents 2e1fe24 + eef1088 commit a08ee15
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
10 changes: 10 additions & 0 deletions python/neutron-understack/neutron_understack/nautobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,13 @@ def ucvni_create(
resp = self.s.post(url, json=payload, timeout=10)
LOG.debug("ucvni_create resp: %(resp)s", {"resp": resp.json()})
resp.raise_for_status()

def ucvni_delete(self, network_id):
payload = {"id": network_id}

ucvni_url = f"/api/plugins/undercloud-vni/ucvnis/{network_id}/"
url = urljoin(self.base_url, ucvni_url)
LOG.debug("ucvni_delete payload: %(payload)s", {"payload": payload})
resp = self.s.delete(url, json=payload, timeout=10)
LOG.debug("ucvni_delete resp: %(resp)s", {"resp": resp.status_code})
resp.raise_for_status()
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ def create_network_postcommit(self, context):
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)",
"network %(net_id)s has been added on ucvni_group %(ucvni_group)s, "
"physnet %(physnet)s",
{"net_id": network_id, "ucvni_group": ucvni_group, "physnet": physnet},
)

Expand All @@ -157,6 +157,28 @@ def delete_network_precommit(self, context):
def delete_network_postcommit(self, context):
log_call("delete_network_postcommit", context)

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

if provider_type == p_const.TYPE_VXLAN:
conf = cfg.CONF.ml2_understack
ucvni_group = conf.ucvni_group
try:
self.nb.ucvni_delete(network_id)
except Exception as e:
LOG.exception(
"unable to delete 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 deleted from ucvni_group %(ucvni_group)s, "
"physnet %(physnet)s",
{"net_id": network_id, "ucvni_group": ucvni_group, "physnet": physnet},
)

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

Expand Down

0 comments on commit a08ee15

Please sign in to comment.