@@ -1209,6 +1209,14 @@ def _output_opts_file(self):
1209
1209
file_utils .replace_file (name , '\n ' .join (options ))
1210
1210
return name
1211
1211
1212
+ def _get_ovn_metadata_port_ip (self , subnet ):
1213
+ m_ports = [port for port in self .network .ports if
1214
+ self ._is_ovn_metadata_port (port , self .network .id )]
1215
+ if m_ports :
1216
+ for fixed_ip in m_ports [0 ].fixed_ips :
1217
+ if fixed_ip .subnet_id == subnet .id :
1218
+ return fixed_ip .ip_address
1219
+
1212
1220
def _generate_opts_per_subnet (self ):
1213
1221
options = []
1214
1222
subnets_without_nameservers = set ()
@@ -1262,23 +1270,33 @@ def _generate_opts_per_subnet(self):
1262
1270
else :
1263
1271
host_routes .append ("%s,%s" % (hr .destination , hr .nexthop ))
1264
1272
1265
- # Add host routes for isolated network segments
1266
-
1267
- if ((self .conf .force_metadata or
1268
- (isolated_subnets [subnet .id ] and
1269
- self .conf .enable_isolated_metadata )) and
1270
- subnet .ip_version == 4 ):
1271
- subnet_dhcp_ip = subnet_to_interface_ip .get (subnet .id )
1272
- if subnet_dhcp_ip :
1273
+ # Determine metadata port route
1274
+ if subnet .ip_version == constants .IP_VERSION_4 :
1275
+ metadata_route_ip = None
1276
+ # NOTE: OVN metadata port IP is used in a case when the DHCP
1277
+ # agent is deployed in the ML2/OVN enviroment where the native
1278
+ # ovn-controller dhcp is disabled. The ovn metadata route
1279
+ # takes precedence over native force_metadata and
1280
+ # enable_isolated_metadata routes settings.
1281
+ ovn_metadata_port_ip = self ._get_ovn_metadata_port_ip (subnet )
1282
+ if ovn_metadata_port_ip :
1283
+ metadata_route_ip = ovn_metadata_port_ip
1284
+
1285
+ elif (self .conf .force_metadata or
1286
+ (isolated_subnets [subnet .id ] and
1287
+ self .conf .enable_isolated_metadata )):
1288
+ subnet_dhcp_ip = subnet_to_interface_ip .get (subnet .id )
1289
+ if subnet_dhcp_ip :
1290
+ metadata_route_ip = subnet_dhcp_ip
1291
+
1292
+ if not isolated_subnets [subnet .id ] and gateway :
1293
+ metadata_route_ip = gateway
1294
+
1295
+ if metadata_route_ip :
1273
1296
host_routes .append (
1274
- '%s,%s' % (constants .METADATA_CIDR , subnet_dhcp_ip )
1297
+ '%s,%s' % (constants .METADATA_CIDR , metadata_route_ip )
1275
1298
)
1276
- elif not isolated_subnets [subnet .id ] and gateway :
1277
- host_routes .append (
1278
- '%s,%s' % (constants .METADATA_CIDR , gateway )
1279
- )
1280
1299
1281
- if subnet .ip_version == 4 :
1282
1300
for s in self ._get_all_subnets (self .network ):
1283
1301
sub_segment_id = getattr (s , 'segment_id' , None )
1284
1302
if (s .ip_version == 4 and
@@ -1443,13 +1461,21 @@ def has_metadata_subnet(subnets):
1443
1461
return True
1444
1462
return False
1445
1463
1464
+ @staticmethod
1465
+ def _is_ovn_metadata_port (port , network_id ):
1466
+ return (port .device_id == 'ovnmeta-' + network_id and
1467
+ port .device_owner == constants .DEVICE_OWNER_DISTRIBUTED )
1468
+
1446
1469
@classmethod
1447
1470
def should_enable_metadata (cls , conf , network ):
1448
1471
"""Determine whether the metadata proxy is needed for a network
1449
1472
1450
- This method returns True for truly isolated networks (ie: not attached
1451
- to a router) when enable_isolated_metadata is True, or for all the
1452
- networks when the force_metadata flags is True.
1473
+ If the given network contains a ovn metadata port then this method
1474
+ assumes that the ovn metadata service is in use and this metadata
1475
+ service is not required, method returns False. For other cases this
1476
+ method returns True for truly isolated networks (ie: not attached to a
1477
+ router) when enable_isolated_metadata is True, or for all the networks
1478
+ when the force_metadata flags is True.
1453
1479
1454
1480
This method also returns True when enable_metadata_network is True,
1455
1481
and the network passed as a parameter has a subnet in the link-local
@@ -1458,6 +1484,10 @@ def should_enable_metadata(cls, conf, network):
1458
1484
providing access to the metadata service via logical routers built
1459
1485
with 3rd party backends.
1460
1486
"""
1487
+ for port in network .ports :
1488
+ if cls ._is_ovn_metadata_port (port , network .id ):
1489
+ return False
1490
+
1461
1491
all_subnets = cls ._get_all_subnets (network )
1462
1492
dhcp_subnets = [s for s in all_subnets if s .enable_dhcp ]
1463
1493
if not dhcp_subnets :
0 commit comments