Skip to content

Commit

Permalink
Merge pull request #2182 from zhaoqin-github/vlan
Browse files Browse the repository at this point in the history
[OPENSTACK-2998] Compare vlan between neutron and bigip before purging
  • Loading branch information
zhaoqin-github authored Mar 11, 2024
2 parents 1669459 + c801c0a commit febe119
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
35 changes: 35 additions & 0 deletions f5_openstack_agent/lbaasv2/drivers/bigip/agent_manager_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
from f5_openstack_agent.lbaasv2.drivers.bigip import exceptions as f5_ex
from f5_openstack_agent.lbaasv2.drivers.bigip import opts
from f5_openstack_agent.lbaasv2.drivers.bigip import plugin_rpc
from f5_openstack_agent.lbaasv2.drivers.bigip.resource import RouteDomain
from f5_openstack_agent.lbaasv2.drivers.bigip import resource_manager
from f5_openstack_agent.lbaasv2.drivers.bigip import utils
from f5_openstack_agent.lbaasv2.drivers.bigip.utils import serialized

from f5_openstack_agent.lbaasv2.drivers.bigip.system_helper import \
Expand Down Expand Up @@ -1823,6 +1825,39 @@ def purge_loadbalancer(self, context, loadbalancer, service):
try:
bigip_device.set_bigips(service, self.conf)

# Purging might occur after rebuilding to a different device, so
# that network segmentation id in neutron db might already be
# modified by SDN. Need to check the route domain id in bigip. If
# it is different from the segmentation id in neutron, we need to
# use the route domain id in bigip to purge configuration.

lb_network_id = service["loadbalancer"]["network_id"]
lb_network = service["networks"][lb_network_id]

if not self.lbdriver.conf.f5_global_routed_mode and \
not lb_network["shared"]:
device = service["device"]
tenant_id = service["loadbalancer"]["tenant_id"]
partition = self.lbdriver.service_adapter.get_folder_name(
tenant_id)
vtep_node_ip = utils.get_node_vtep(device)
rd_id = utils.get_vtep_vlan(lb_network, vtep_node_ip)
rd_name = self.lbdriver.network_builder.get_rd_name(lb_network)

r = RouteDomain()
for bigip in service["bigips"]:
rd = r.load(bigip, name=rd_name, partition=partition,
ignore=[404])
if not rd:
# If rd not exist, goto next bigip
continue
else:
if rd.id != rd_id:
utils.modify_vtep_vlan(lb_network, vtep_node_ip,
rd.id)
# We can complete, once we get rd id in bigip
break

# a l7policy contains l7rules, no need to purge l7rule.
for plc in l7policies:
plc_id = plc['id']
Expand Down
25 changes: 25 additions & 0 deletions f5_openstack_agent/lbaasv2/drivers/bigip/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,31 @@ def get_vtep_vlan(network, vtep_node_ip):
return network['provider:segmentation_id']


def modify_vtep_vlan(network, vtep_node_ip, seg_id):
# NOTE(qzhao): only purge need this
vlanid = None
default_vlanid = None
segments = network.get('segments', [])

for seg in segments:
phy_net = seg["provider:physical_network"]
vlanid = seg["provider:segmentation_id"]

if phy_net == "default":
default_vlanid = vlanid
default_seg = seg
if phy_net is not None and phy_net == vtep_node_ip:
seg["provider:segmentation_id"] = seg_id
return

if default_vlanid is not None:
default_seg["provider:segmentation_id"] = seg_id
return

network['provider:segmentation_id'] = seg_id
return


def get_node_vtep(device):
if not device:
raise Exception(
Expand Down

0 comments on commit febe119

Please sign in to comment.