fix: create cloudaccount with disabled state

This commit is contained in:
Qiu Jian
2020-05-11 12:44:23 +08:00
parent 1403fae69b
commit 3b0bc38583
3 changed files with 26 additions and 9 deletions
+11
View File
@@ -88,6 +88,17 @@ type EnabledBaseResourceCreateInput struct {
// 该资源是否被管理员*人为*启用或者禁用
// required: false
Enabled *bool `json:"enabled"`
// 该资源是否被管理员*人为*禁用, 和enabled互斥
// required: false
Disabled *bool `json:"disabled"`
}
func (input *EnabledBaseResourceCreateInput) AfterUnmarshal() {
if input.Disabled != nil && input.Enabled == nil {
enabled := !(*input.Disabled)
input.Enabled = &enabled
}
}
type StatusBaseResourceCreateInput struct {
+13 -9
View File
@@ -463,18 +463,22 @@ func (manager *SCloudaccountManager) ValidateCreateData(
}
func (self *SCloudaccount) CustomizeCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
self.SetEnabled(true)
if !data.Contains("enabled") {
self.SetEnabled(true)
}
if len(self.Brand) == 0 {
self.Brand = self.Provider
}
self.DomainId = ownerId.GetProjectDomainId()
// self.EnableAutoSync = false
// force private and share_mode=account_domain
self.ShareMode = api.CLOUD_ACCOUNT_SHARE_MODE_ACCOUNT_DOMAIN
self.IsPublic = false
self.PublicScope = string(rbacutils.ScopeNone)
// mark the public_scope has been set
data.(*jsonutils.JSONDict).Set("public_scope", jsonutils.NewString(self.PublicScope))
if !data.Contains("public_scope") {
self.ShareMode = api.CLOUD_ACCOUNT_SHARE_MODE_ACCOUNT_DOMAIN
self.IsPublic = false
self.PublicScope = string(rbacutils.ScopeNone)
// mark the public_scope has been set
data.(*jsonutils.JSONDict).Set("public_scope", jsonutils.NewString(self.PublicScope))
}
return self.SEnabledStatusInfrasResourceBase.CustomizeCreate(ctx, userCred, ownerId, query, data)
}
@@ -492,9 +496,9 @@ func (self *SCloudaccount) PostCreate(ctx context.Context, userCred mcclient.Tok
if err != nil {
log.Errorf("CancelPendingUsage fail %s", err)
}
// if !self.EnableAutoSync {
self.StartSyncCloudProviderInfoTask(ctx, userCred, nil, "")
// }
if self.Enabled.IsTrue() {
self.StartSyncCloudProviderInfoTask(ctx, userCred, nil, "")
}
}
func (self *SCloudaccount) savePassword(secret string) error {
+2
View File
@@ -85,6 +85,8 @@ type SCloudAccountCreateBaseOptions struct {
Project string `help:"project for this account"`
ProjectDomain string `help:"domain for this account"`
Disabled *bool `help:"create cloud account with disabled status"`
ProxySetting string `help:"proxy setting id or name" json:"proxy_setting"`
}