Merge pull request #7416 from rainzm/network/create

fix(region): Don't allow address conflicts under vpc
This commit is contained in:
Zexi Li
2020-08-01 11:05:22 +08:00
committed by GitHub
2 changed files with 14 additions and 4 deletions
+4 -4
View File
@@ -1459,12 +1459,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
@@ -226,6 +226,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()