mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix: create cloudaccount with disabled state
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user