-
Notifications
You must be signed in to change notification settings - Fork 491
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vpcagent: add cmp() for search and pre-cleanup
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package ovn | ||
|
||
import ( | ||
"yunion.io/x/onecloud/pkg/vpcagent/ovnutil" | ||
) | ||
|
||
// cmp scans the database for irows. For those present, mark them with ocver. | ||
// If all rows are found, return true to indicate this. Otherwise return as | ||
// 2nd value the args to destroy these found records | ||
func cmp(db *ovnutil.OVNNorthbound, ocver string, irows ...ovnutil.IRow) (bool, []string) { | ||
irowsFound := make([]ovnutil.IRow, 0, len(irows)) | ||
|
||
for _, irow := range irows { | ||
irowFound := db.FindOneMatchNonZeros(irow) | ||
if irowFound != nil { | ||
irowsFound = append(irowsFound, irowFound) | ||
} | ||
} | ||
// mark them anyway even if not all found, to avoid the destroy | ||
// call at sweep stage | ||
for _, irowFound := range irowsFound { | ||
irowFound.OvnSetExternalIds(externalKeyOcVersion, ocver) | ||
} | ||
if len(irowsFound) == len(irows) { | ||
return true, nil | ||
} | ||
args := ovnutil.OvnNbctlArgsDestroy(irowsFound) | ||
return false, args | ||
} |