mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #3779 from tb365/bugfix/tb-bugfix-111902
redis create bugfix & redis acl create bugfix
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
@@ -175,6 +176,18 @@ func (manager *SElasticcacheAccountManager) newFromCloudElasticcacheAccount(ctx
|
||||
return &account, nil
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheAccountManager) FetchParentId(ctx context.Context, data jsonutils.JSONObject) string {
|
||||
parentId, _ := data.GetString("elasticcache_id")
|
||||
return parentId
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheAccountManager) FilterByParentId(q *sqlchemy.SQuery, parentId string) *sqlchemy.SQuery {
|
||||
if len(parentId) > 0 {
|
||||
q = q.Equals("elasticcache_id", parentId)
|
||||
}
|
||||
return q
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheAccountManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return db.IsAdminAllowCreate(userCred, manager)
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
@@ -159,6 +160,18 @@ func (manager *SElasticcacheAclManager) newFromCloudElasticcacheAcl(ctx context.
|
||||
return &acl, nil
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheAclManager) FetchParentId(ctx context.Context, data jsonutils.JSONObject) string {
|
||||
parentId, _ := data.GetString("elasticcache_id")
|
||||
return parentId
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheAclManager) FilterByParentId(q *sqlchemy.SQuery, parentId string) *sqlchemy.SQuery {
|
||||
if len(parentId) > 0 {
|
||||
q = q.Equals("elasticcache_id", parentId)
|
||||
}
|
||||
return q
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheAclManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return db.IsAdminAllowCreate(userCred, manager)
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
@@ -199,6 +200,18 @@ func (manager *SElasticcacheBackupManager) newFromCloudElasticcacheBackup(ctx co
|
||||
return &backup, nil
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheBackupManager) FetchParentId(ctx context.Context, data jsonutils.JSONObject) string {
|
||||
parentId, _ := data.GetString("elasticcache_id")
|
||||
return parentId
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheBackupManager) FilterByParentId(q *sqlchemy.SQuery, parentId string) *sqlchemy.SQuery {
|
||||
if len(parentId) > 0 {
|
||||
q = q.Equals("elasticcache_id", parentId)
|
||||
}
|
||||
return q
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheBackupManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return db.IsAdminAllowCreate(userCred, manager)
|
||||
}
|
||||
|
||||
@@ -414,6 +414,15 @@ func (manager *SElasticcacheManager) AllowCreateItem(ctx context.Context, userCr
|
||||
return db.IsAdminAllowCreate(userCred, manager)
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheManager) BatchCreateValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
input, err := manager.ValidateCreateData(ctx, userCred, ownerId, query, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
var region *SCloudregion
|
||||
if id, _ := data.GetString("network"); len(id) > 0 {
|
||||
@@ -433,21 +442,18 @@ func (manager *SElasticcacheManager) ValidateCreateData(ctx context.Context, use
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if reset, _ := data.Bool("reset_password"); reset {
|
||||
if _, err := data.GetString("password"); err != nil {
|
||||
randomPasswd := seclib2.RandomPassword2(12)
|
||||
data.Set("password", jsonutils.NewString(randomPasswd))
|
||||
}
|
||||
}
|
||||
|
||||
return region.GetDriver().ValidateCreateElasticcacheData(ctx, userCred, nil, data)
|
||||
}
|
||||
|
||||
func (self *SElasticcache) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
self.SVirtualResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
password, _ := data.GetString("password")
|
||||
if reset, _ := data.Bool("reset_password"); reset && len(password) == 0 {
|
||||
password = seclib2.RandomPassword2(12)
|
||||
}
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("password", jsonutils.NewString(password))
|
||||
self.SetStatus(userCred, api.ELASTIC_CACHE_STATUS_DEPLOYING, "")
|
||||
if err := self.StartElasticcacheCreateTask(ctx, userCred, params, ""); err != nil {
|
||||
|
||||
@@ -1403,7 +1403,12 @@ func (self *SAliyunRegionDriver) RequestCreateElasticcacheAccount(ctx context.Co
|
||||
return nil, errors.Wrap(err, "aliyunRegionDriver.CreateElasticcacheAccount.SetExternalId")
|
||||
}
|
||||
|
||||
if err := ea.SyncWithCloudElasticcacheAccount(ctx, userCred, iea); err != nil {
|
||||
err = cloudprovider.WaitStatusWithDelay(iea, api.ELASTIC_CACHE_ACCOUNT_STATUS_AVAILABLE, 3*time.Second, 3*time.Second, 180*time.Second)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "aliyunRegionDriver.CreateElasticcacheAccount.WaitStatusWithDelay")
|
||||
}
|
||||
|
||||
if err = ea.SyncWithCloudElasticcacheAccount(ctx, userCred, iea); err != nil {
|
||||
return nil, errors.Wrap(err, "aliyunRegionDriver.CreateElasticcacheAccount.SyncWithCloudElasticcache")
|
||||
}
|
||||
|
||||
|
||||
@@ -2041,12 +2041,19 @@ func (self *SManagedVirtualizationRegionDriver) ValidateCreateElasticcacheAclDat
|
||||
}
|
||||
|
||||
ipV := validators.NewIPv4AddrValidator("ip")
|
||||
cidrV := validators.NewIPv4PrefixValidator("ip")
|
||||
_ips := strings.Split(ips, ",")
|
||||
for _, ip := range _ips {
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("ip", jsonutils.NewString(ip))
|
||||
if err := ipV.Validate(params); err != nil {
|
||||
return nil, err
|
||||
if strings.Contains(ip, "/") {
|
||||
if err := cidrV.Validate(params); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if err := ipV.Validate(params); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,6 @@ func (self *ElasticcacheBackupCreateTask) OnInit(ctx context.Context, obj db.ISt
|
||||
}
|
||||
|
||||
func (self *ElasticcacheBackupCreateTask) OnElasticcacheBackupCreateComplete(ctx context.Context, eb *models.SElasticcacheBackup, data jsonutils.JSONObject) {
|
||||
eb.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_RUNNING, "")
|
||||
logclient.AddActionLogWithStartable(self, eb, logclient.ACT_CREATE, "", self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package aliyun
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
@@ -60,10 +61,10 @@ func (self *SElasticcacheAccount) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (self *SElasticcacheAccount) GetStatus() string {
|
||||
switch self.AccountStatus {
|
||||
case "Unavailable":
|
||||
switch strings.ToLower(self.AccountStatus) {
|
||||
case "unavailable":
|
||||
return api.ELASTIC_CACHE_ACCOUNT_STATUS_UNAVAILABLE
|
||||
case "Available":
|
||||
case "available":
|
||||
return api.ELASTIC_CACHE_ACCOUNT_STATUS_AVAILABLE
|
||||
default:
|
||||
return self.AccountStatus
|
||||
|
||||
Reference in New Issue
Block a user