Merge pull request #1121 from ioito/hotfix/qx-brand-check

添加brand字段限制
This commit is contained in:
yunion-ci-robot
2019-06-11 00:11:50 +08:00
committed by GitHub
5 changed files with 22 additions and 1 deletions
+2
View File
@@ -44,6 +44,8 @@ const (
CLOUD_PROVIDER_HEALTH_SUSPENDED = "suspended" // 远端处于冻结状态
CLOUD_PROVIDER_HEALTH_ARREARS = "arrears" // 远端处于欠费状态
CLOUD_PROVIDER_HEALTH_UNKNOWN = "unknown" // 未知状态,查询失败
ZSTACK_BRAND_DSTACK = "DStack"
)
var (
+5
View File
@@ -44,6 +44,7 @@ type ICloudProviderFactory interface {
ValidateChangeBandwidth(instanceId string, bandwidth int64) error
ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error
ValidateUpdateCloudaccountCredential(ctx context.Context, userCred mcclient.TokenCredential, data jsonutils.JSONObject, cloudaccount string) (*SCloudaccount, error)
GetSupportedBrands() []string
IsPublicCloud() bool
IsOnPremise() bool
@@ -179,6 +180,10 @@ func (factory *baseProviderFactory) ValidateChangeBandwidth(instanceId string, b
return nil
}
func (factory *baseProviderFactory) GetSupportedBrands() []string {
return []string{}
}
func (factory *baseProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
return httperrors.NewNotImplementedError("Not Implemented ValidateCreateCloudaccountData")
}
+10
View File
@@ -256,6 +256,16 @@ func (manager *SCloudaccountManager) ValidateCreateData(ctx context.Context, use
if err := providerDriver.ValidateCreateCloudaccountData(ctx, userCred, data); err != nil {
return nil, err
}
brand, _ := data.GetString("brand")
if len(brand) > 0 && brand != providerDriver.GetName() {
brands := providerDriver.GetSupportedBrands()
if !utils.IsInStringArray(providerDriver.GetName(), brands) {
brands = append(brands, providerDriver.GetName())
}
if !utils.IsInStringArray(brand, brands) {
return nil, httperrors.NewUnsupportOperationError("Not support brand %s, only support %s", brand, brands)
}
}
data.Set("is_public_cloud", jsonutils.NewBool(providerDriver.IsPublicCloud()))
data.Set("is_on_premise", jsonutils.NewBool(providerDriver.IsOnPremise()))
// check duplication
+1 -1
View File
@@ -75,7 +75,7 @@ type SCloudAccountCreateBaseOptions struct {
Name string `help:"Name of cloud account" positional:"true"`
// PROVIDER string `help:"Driver for cloud account" choices:"VMware|Aliyun|Azure|Qcloud|OpenStack|Huawei|Aws"`
Desc string `help:"Description" token:"desc" json:"description"`
Brand string `help:"Brand of cloud account"`
Brand string `help:"Brand of cloud account" choices:"DStack"`
AutoCreateProject bool `help:"Enable the account with same name project"`
EnableAutoSync bool `help:"Enable automatically synchronize resources of this account"`
+4
View File
@@ -39,6 +39,10 @@ func (self *SZStackProviderFactory) GetName() string {
return zstack.CLOUD_PROVIDER_ZSTACK
}
func (self *SZStackProviderFactory) GetSupportedBrands() []string {
return []string{api.ZSTACK_BRAND_DSTACK}
}
func (self *SZStackProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
username, _ := data.GetString("username")
if len(username) == 0 {