Skip to content

Commit

Permalink
fix: 允许gcp创建vpc时不指定cidr
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu Xuan committed Jun 2, 2020
1 parent 0d5be52 commit 53d7710
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/compute/models/regiondrivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type IRegionDriver interface {
RequestDeleteLoadbalancerListenerRule(ctx context.Context, userCred mcclient.TokenCredential, lbr *SLoadbalancerListenerRule, task taskman.ITask) error

ValidateCreateVpcData(ctx context.Context, userCred mcclient.TokenCredential, input api.VpcCreateInput) (api.VpcCreateInput, error)
IsVpcCreateNeedInputCidr() bool
ValidateCreateEipData(ctx context.Context, userCred mcclient.TokenCredential, input *api.SElasticipCreateInput) error
RequestCreateVpc(ctx context.Context, userCred mcclient.TokenCredential, region *SCloudregion, vpc *SVpc, task taskman.ITask) error
RequestDeleteVpc(ctx context.Context, userCred mcclient.TokenCredential, region *SCloudregion, vpc *SVpc, task taskman.ITask) error
Expand Down
6 changes: 5 additions & 1 deletion pkg/compute/models/vpcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type SVpc struct {

// CIDR地址段
// example: 192.168.222.0/24
CidrBlock string `charset:"ascii" nullable:"true" list:"domain" create:"domain_required"`
CidrBlock string `charset:"ascii" nullable:"true" list:"domain" create:"domain_optional"`

// 区域Id
// CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"domain" create:"domain_required" default:"default"`
Expand Down Expand Up @@ -660,6 +660,10 @@ func (manager *SVpcManager) ValidateCreateData(
return input, errors.Wrapf(err, "region.GetDriver().ValidateCreateVpcData")
}

if region.GetDriver().IsVpcCreateNeedInputCidr() && len(input.CidrBlock) == 0 {
return input, httperrors.NewMissingParameterError("cidr")
}

keys := GetVpcQuotaKeysFromCreateInput(input)
quota := &SInfrasQuota{Vpc: 1}
quota.SetKeys(keys)
Expand Down
4 changes: 4 additions & 0 deletions pkg/compute/regiondrivers/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ func (self *SBaseRegionDriver) RequestBingToNatgateway(ctx context.Context, task
return fmt.Errorf("Not implement RequestBindIPToNatgateway")
}

func (self *SBaseRegionDriver) IsVpcCreateNeedInputCidr() bool {
return true
}

func (self *SBaseRegionDriver) RequestCreateVpc(ctx context.Context, userCred mcclient.TokenCredential, region *models.SCloudregion, vpc *models.SVpc, task taskman.ITask) error {
return fmt.Errorf("Not implement RequestCreateVpc")
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/compute/regiondrivers/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (self *SGoogleRegionDriver) IsVpcBelongGlobalVpc() bool {
return true
}

func (self *SGoogleRegionDriver) IsVpcCreateNeedInputCidr() bool {
return false
}

func (self *SGoogleRegionDriver) RequestCreateVpc(ctx context.Context, userCred mcclient.TokenCredential, region *models.SCloudregion, vpc *models.SVpc, task taskman.ITask) error {
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
provider := vpc.GetCloudprovider()
Expand Down
4 changes: 4 additions & 0 deletions pkg/compute/regiondrivers/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func (self *SOpenStackRegionDriver) GetProvider() string {
return api.CLOUD_PROVIDER_OPENSTACK
}

func (self *SOpenStackRegionDriver) IsVpcCreateNeedInputCidr() bool {
return false
}

func (self *SOpenStackRegionDriver) ValidateCreateLoadbalancerData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
return nil, httperrors.NewNotImplementedError("%s does not currently support creating loadbalancer", self.GetProvider())
}
Expand Down

0 comments on commit 53d7710

Please sign in to comment.