mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
fix(region): Don't allow address conflicts under vpc
Except for default vpc, vpc and wire have a one-to-one correspondence. So prohibiting the address conflict of wire does not avoid the address conflict of default vpc.
This commit is contained in:
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user