fix: 允许gcp创建vpc时不指定cidr

This commit is contained in:
Qu Xuan
2020-06-02 22:03:17 +08:00
parent d3f8c71050
commit 766d5cf803
5 changed files with 18 additions and 1 deletions
+1
View File
@@ -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
+5 -1
View File
@@ -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"`
@@ -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)
+4
View File
@@ -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")
}
+4
View File
@@ -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()
+4
View File
@@ -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())
}