mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
networks: auto-create zone wire
This commit is contained in:
@@ -1374,7 +1374,15 @@ func (manager *SNetworkManager) ValidateCreateData(ctx context.Context, userCred
|
||||
return input, httperrors.NewInternalServerError("query wire for zone %s and vpc %s: %v", input.Zone, input.Vpc, err)
|
||||
}
|
||||
if len(wires) == 0 {
|
||||
return input, httperrors.NewNotFoundError("wire not found for zone %s and vpc %s", input.Zone, input.Vpc)
|
||||
if region.Provider == api.CLOUD_PROVIDER_ONECLOUD {
|
||||
wire, err := vpc.initWire(ctx, zone)
|
||||
if err != nil {
|
||||
return input, httperrors.NewNotFoundError("init wire for zone %s and vpc %s: %v", input.Zone, input.Vpc, err)
|
||||
}
|
||||
input.WireId = wire.Id
|
||||
} else {
|
||||
return input, httperrors.NewNotFoundError("wire not found for zone %s and vpc %s", input.Zone, input.Vpc)
|
||||
}
|
||||
} else if len(wires) > 1 {
|
||||
return input, httperrors.NewConflictError("found %d wires for zone %s and vpc %s", len(wires), input.Zone, input.Vpc)
|
||||
} else {
|
||||
|
||||
@@ -927,3 +927,20 @@ func (vpc *SVpc) GetGlobalVpc() (*SGlobalVpc, error) {
|
||||
}
|
||||
return gv.(*SGlobalVpc), nil
|
||||
}
|
||||
|
||||
func (self *SVpc) initWire(ctx context.Context, zone *SZone) (*SWire, error) {
|
||||
wire := &SWire{
|
||||
VpcId: self.Id,
|
||||
ZoneId: zone.Id,
|
||||
Bandwidth: 10000,
|
||||
Mtu: 1500,
|
||||
}
|
||||
wire.IsEmulated = true
|
||||
wire.Name = fmt.Sprintf("vpc-%s", self.Name)
|
||||
wire.SetModelManager(WireManager, wire)
|
||||
err := WireManager.TableSpec().Insert(wire)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return wire, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user