mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 01:35:56 +08:00
Merge pull request #7416 from rainzm/network/create
fix(region): Don't allow address conflicts under vpc
This commit is contained in:
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user