Merge pull request #7421 from rainzm/automated-cherry-pick-of-#7416-upstream-release-3.2

Automated cherry pick of #7416: fix(region): Don't allow address conflicts under vpc
This commit is contained in:
Zexi Li
2020-08-01 11:05:00 +08:00
committed by GitHub
2 changed files with 14 additions and 4 deletions
+4 -4
View File
@@ -1449,12 +1449,12 @@ func (manager *SNetworkManager) ValidateCreateData(ctx context.Context, userCred
}
}
{
nets := manager.getAllNetworks(wire.Id, "")
if nets == nil {
return input, httperrors.NewInternalServerError("query all networks fail")
nets, err := vpc.GetNetworks()
if err != nil {
return input, httperrors.NewInternalServerError("fail to GetNetworks of vpc: %v", err)
}
if isOverlapNetworks(nets, ipStart, ipEnd) {
return input, httperrors.NewInputParameterError("Conflict address space with existing networks")
return input, httperrors.NewInputParameterError("Conflict address space with existing networks in vpc %q", vpc.GetName())
}
}
+10
View File
@@ -214,6 +214,16 @@ func (self *SVpc) getNetworkQuery() *sqlchemy.SQuery {
return q
}
func (self *SVpc) GetNetworks() ([]SNetwork, error) {
q := self.getNetworkQuery()
nets := make([]SNetwork, 0, 5)
err := db.FetchModelObjects(NetworkManager, q, &nets)
if err != nil {
return nil, errors.Wrap(err, "db.FetchModelObjects")
}
return nets, nil
}
func (self *SVpc) GetNetworkCount() (int, error) {
q := self.getNetworkQuery()
return q.CountWithError()