refactor: Optimize the method of obtaining port based on device owners
Optimize the method of obtaining port based on device owners: call from multiple APIs, adjust to one API call, because the device_owner parameter supports array format Change-Id: Ia14c187f793e5c3528cdd1a603f2e52510d90f03
This commit is contained in:
parent
57a17b83d2
commit
8a1537349a
@ -52,15 +52,14 @@ export function getSubnetToRouter(
|
|||||||
) {
|
) {
|
||||||
const canReachSubnetIdsWithRouterId = [];
|
const canReachSubnetIdsWithRouterId = [];
|
||||||
// Save the information of all subnets and create a mapping of router_id => subnet_id
|
// Save the information of all subnets and create a mapping of router_id => subnet_id
|
||||||
portsWithFixedIPs.forEach((type) => {
|
portsWithFixedIPs.forEach((port) => {
|
||||||
type.forEach((port) => {
|
|
||||||
const router = routerIdWithExternalNetworkInfo.find((r) => {
|
const router = routerIdWithExternalNetworkInfo.find((r) => {
|
||||||
if (shouldHaveExternalGateway && !r.external_gateway_info) {
|
if (shouldHaveExternalGateway && !r.external_gateway_info) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return r.id === port.device_id;
|
return r.id === port.device_id;
|
||||||
});
|
});
|
||||||
if (router && router.id === port.device_id) {
|
if (router) {
|
||||||
port.fixed_ips.forEach((item) => {
|
port.fixed_ips.forEach((item) => {
|
||||||
canReachSubnetIdsWithRouterId.push({
|
canReachSubnetIdsWithRouterId.push({
|
||||||
subnet_id: item.subnet_id,
|
subnet_id: item.subnet_id,
|
||||||
@ -69,7 +68,6 @@ export function getSubnetToRouter(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
return canReachSubnetIdsWithRouterId;
|
return canReachSubnetIdsWithRouterId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,14 +77,10 @@ export async function getPortsWithFixedIPs() {
|
|||||||
'network:router_interface',
|
'network:router_interface',
|
||||||
'network:ha_router_replicated_interface',
|
'network:ha_router_replicated_interface',
|
||||||
];
|
];
|
||||||
const portsWithFixedIPs = await Promise.all(
|
const portsWithFixedIPs = await globalPortStore.pureFetchList({
|
||||||
deviceOwnerList.map((item) =>
|
device_owner: deviceOwnerList,
|
||||||
globalPortStore.pureFetchList({
|
fields: ['fixed_ips', 'device_id', 'device_owner'],
|
||||||
device_owner: item,
|
});
|
||||||
fields: ['fixed_ips', 'device_id'],
|
|
||||||
})
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return portsWithFixedIPs;
|
return portsWithFixedIPs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user