mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
unified syncstatus action
This commit is contained in:
@@ -56,10 +56,10 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type BucketShowOptions struct {
|
||||
type BucketIdOptions struct {
|
||||
ID string `help:"ID or name of bucket"`
|
||||
}
|
||||
R(&BucketShowOptions{}, "bucket-show", "Show details of bucket", func(s *mcclient.ClientSession, args *BucketShowOptions) error {
|
||||
R(&BucketIdOptions{}, "bucket-show", "Id details of bucket", func(s *mcclient.ClientSession, args *BucketIdOptions) error {
|
||||
result, err := modules.Buckets.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -68,6 +68,15 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&BucketIdOptions{}, "bucket-syncstatus", "Sync bucket statust", func(s *mcclient.ClientSession, args *BucketIdOptions) error {
|
||||
result, err := modules.Buckets.PerformAction(s, args.ID, "syncstatus", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type BucketUpdateOptions struct {
|
||||
ID string `help:"ID or name of bucket" json:"-"`
|
||||
Name string `help:"new name of bucket" json:"name"`
|
||||
|
||||
@@ -80,6 +80,15 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&DBInstanceBackupIdOptions{}, "dbinstance-backup-syncstatus", "Sync DB instance backup status", func(s *mcclient.ClientSession, opts *DBInstanceBackupIdOptions) error {
|
||||
result, err := modules.DBInstanceBackups.PerformAction(s, opts.ID, "syncstatus", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&DBInstanceBackupIdOptions{}, "dbinstance-backup-delete", "Delete DB instance backup", func(s *mcclient.ClientSession, opts *DBInstanceBackupIdOptions) error {
|
||||
result, err := modules.DBInstanceBackups.Delete(s, opts.ID, nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -258,6 +258,15 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&DBInstanceIdOptions{}, "dbinstance-syncstatus", "Sync status for DB instance", func(s *mcclient.ClientSession, opts *DBInstanceIdOptions) error {
|
||||
result, err := modules.DBInstance.PerformAction(s, opts.ID, "syncstatus", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&DBInstanceIdOptions{}, "dbinstance-sync-status", "Sync status for DB instance", func(s *mcclient.ClientSession, opts *DBInstanceIdOptions) error {
|
||||
result, err := modules.DBInstance.PerformAction(s, opts.ID, "sync-status", nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -133,6 +133,15 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&DiskDetailOptions{}, "disk-syncstatus", "Sync status for disk", func(s *mcclient.ClientSession, args *DiskDetailOptions) error {
|
||||
ret, e := modules.Disks.PerformAction(s, args.ID, "syncstatus", nil)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
printObject(ret)
|
||||
return nil
|
||||
})
|
||||
|
||||
type DiskUpdateOptions struct {
|
||||
ID string `help:"ID or name of disk"`
|
||||
Name string `help:"New name of disk"`
|
||||
|
||||
@@ -75,6 +75,16 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&options.ElasticCacheIdOptions{}, "elastic-cache-syncstatus", "Sync elastisc cache instance status", func(s *mcclient.ClientSession, opts *options.ElasticCacheIdOptions) error {
|
||||
result, err := modules.ElasticCache.PerformAction(s, opts.ID, "syncstatus", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&options.ElasticCacheIdOptions{}, "elastic-cache-delete", "Delete elastisc cache instance", func(s *mcclient.ClientSession, opts *options.ElasticCacheIdOptions) error {
|
||||
result, err := modules.ElasticCache.Delete(s, opts.ID, nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -170,6 +170,15 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&EipSingleOptions{}, "eip-syncstatus", "Synchronize status of an EIP", func(s *mcclient.ClientSession, args *EipSingleOptions) error {
|
||||
result, err := modules.Elasticips.PerformAction(s, args.ID, "syncstatus", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type ServerCreateEipOptions struct {
|
||||
ID string `help:"server ID or name"`
|
||||
BW int `help:"EIP bandwidth in Mbps"`
|
||||
|
||||
@@ -35,7 +35,7 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&options.NatGatewayShowOptions{}, "natgateway-show", "Show a NAT gateway", func(s *mcclient.ClientSession, args *options.NatGatewayShowOptions) error {
|
||||
R(&options.NatGatewayIdOptions{}, "natgateway-show", "Show a NAT gateway", func(s *mcclient.ClientSession, args *options.NatGatewayIdOptions) error {
|
||||
results, err := modules.NatGateways.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -44,6 +44,15 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&options.NatGatewayIdOptions{}, "natgateway-syncstatus", "Sync NAT gateway status", func(s *mcclient.ClientSession, args *options.NatGatewayIdOptions) error {
|
||||
result, err := modules.NatGateways.PerformAction(s, args.ID, "syncstatus", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type NatGatewayListEipOptions struct {
|
||||
ID string `help:"ID"`
|
||||
}
|
||||
|
||||
@@ -139,10 +139,10 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type NetworkShowOptions struct {
|
||||
type NetworkIdOptions struct {
|
||||
ID string `help:"ID or Name of the zone to show"`
|
||||
}
|
||||
R(&NetworkShowOptions{}, "network-show", "Show network details", func(s *mcclient.ClientSession, args *NetworkShowOptions) error {
|
||||
R(&NetworkIdOptions{}, "network-show", "Show network details", func(s *mcclient.ClientSession, args *NetworkIdOptions) error {
|
||||
result, err := modules.Networks.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -151,7 +151,7 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&NetworkShowOptions{}, "network-metadata", "Show metadata of a network", func(s *mcclient.ClientSession, args *NetworkShowOptions) error {
|
||||
R(&NetworkIdOptions{}, "network-metadata", "Show metadata of a network", func(s *mcclient.ClientSession, args *NetworkIdOptions) error {
|
||||
result, err := modules.Networks.GetMetadata(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -160,7 +160,7 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&NetworkShowOptions{}, "network-private", "Make a network private", func(s *mcclient.ClientSession, args *NetworkShowOptions) error {
|
||||
R(&NetworkIdOptions{}, "network-private", "Make a network private", func(s *mcclient.ClientSession, args *NetworkIdOptions) error {
|
||||
result, err := modules.Networks.PerformAction(s, args.ID, "private", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -169,8 +169,17 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&NetworkIdOptions{}, "network-syncstatus", "Sync network status", func(s *mcclient.ClientSession, args *NetworkIdOptions) error {
|
||||
result, err := modules.Networks.PerformAction(s, args.ID, "syncstatus", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type NetworkShareOptions struct {
|
||||
NetworkShowOptions
|
||||
NetworkIdOptions
|
||||
Scope string `help:"sharing scope" choices:"system|domain"`
|
||||
ShareToProject []string `help:"Share to prject"`
|
||||
}
|
||||
@@ -187,7 +196,7 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&NetworkShowOptions{}, "network-delete", "Delete a network", func(s *mcclient.ClientSession, args *NetworkShowOptions) error {
|
||||
R(&NetworkIdOptions{}, "network-delete", "Delete a network", func(s *mcclient.ClientSession, args *NetworkIdOptions) error {
|
||||
result, err := modules.Networks.Delete(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -196,7 +205,7 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&NetworkShowOptions{}, "network-purge", "Purge a managed network, not delete the remote entity", func(s *mcclient.ClientSession, args *NetworkShowOptions) error {
|
||||
R(&NetworkIdOptions{}, "network-purge", "Purge a managed network, not delete the remote entity", func(s *mcclient.ClientSession, args *NetworkIdOptions) error {
|
||||
result, err := modules.Networks.PerformAction(s, args.ID, "purge", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -66,10 +66,10 @@ func init() {
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
type SnapshotShowOptions struct {
|
||||
type SnapshotIdOptions struct {
|
||||
ID string `help:"ID or Name of snapshot"`
|
||||
}
|
||||
R(&SnapshotShowOptions{}, "snapshot-show", "Show snapshot details", func(s *mcclient.ClientSession, args *SnapshotShowOptions) error {
|
||||
R(&SnapshotIdOptions{}, "snapshot-show", "Show snapshot details", func(s *mcclient.ClientSession, args *SnapshotIdOptions) error {
|
||||
result, err := modules.Snapshots.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -78,10 +78,16 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type SnapshotPurgeOptions struct {
|
||||
ID string `help:"ID or name of Snapshot"`
|
||||
}
|
||||
R(&SnapshotPurgeOptions{}, "snapshot-purge", "Purge Snapshot db records", func(s *mcclient.ClientSession, args *SnapshotPurgeOptions) error {
|
||||
R(&SnapshotIdOptions{}, "snapshot-syncstatus", "Sync snapshot status", func(s *mcclient.ClientSession, args *SnapshotIdOptions) error {
|
||||
result, err := modules.Snapshots.PerformAction(s, args.ID, "syncstatus", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&SnapshotIdOptions{}, "snapshot-purge", "Purge Snapshot db records", func(s *mcclient.ClientSession, args *SnapshotIdOptions) error {
|
||||
result, err := modules.Snapshots.PerformAction(s, args.ID, "purge", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -168,4 +168,14 @@ func init() {
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&VpcUpdateStatusOptions{}, "vpc-syncstatus", "Sync the status of a vpc", func(s *mcclient.ClientSession, args *VpcUpdateStatusOptions) error {
|
||||
result, err := modules.Vpcs.PerformAction(s, args.ID, "syncstatus", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -27,14 +27,16 @@ import (
|
||||
const (
|
||||
BUCKET_OPS_STATS_CHANGE = "stats_change"
|
||||
|
||||
BUCKET_STATUS_START_CREATE = "start_create"
|
||||
BUCKET_STATUS_CREATING = "creating"
|
||||
BUCKET_STATUS_READY = "ready"
|
||||
BUCKET_STATUS_CREATE_FAIL = "create_fail"
|
||||
BUCKET_STATUS_START_DELETE = "start_delete"
|
||||
BUCKET_STATUS_DELETING = "deleting"
|
||||
BUCKET_STATUS_DELETED = "deleted"
|
||||
BUCKET_STATUS_DELETE_FAIL = "delete_fail"
|
||||
BUCKET_STATUS_START_CREATE = "start_create"
|
||||
BUCKET_STATUS_CREATING = "creating"
|
||||
BUCKET_STATUS_READY = "ready"
|
||||
BUCKET_STATUS_CREATE_FAIL = "create_fail"
|
||||
BUCKET_STATUS_START_DELETE = "start_delete"
|
||||
BUCKET_STATUS_DELETING = "deleting"
|
||||
BUCKET_STATUS_DELETED = "deleted"
|
||||
BUCKET_STATUS_DELETE_FAIL = "delete_fail"
|
||||
BUCKET_STATUS_SYNCING_STATUS = "syncing"
|
||||
BUCKET_STATUS_UNKNOWN = "unknown"
|
||||
|
||||
BUCKET_UPLOAD_OBJECT_KEY_HEADER = "X-Yunion-Bucket-Upload-Key"
|
||||
BUCKET_UPLOAD_OBJECT_ACL_HEADER = "X-Yunion-Bucket-Upload-Acl"
|
||||
@@ -112,3 +114,6 @@ type BucketListInput struct {
|
||||
// ACL
|
||||
Acl []string `json:"acl"`
|
||||
}
|
||||
|
||||
type BucketSyncstatusInput struct {
|
||||
}
|
||||
|
||||
@@ -43,13 +43,14 @@ const (
|
||||
DBINSTANCE_FAILE = "failed" //操作失败
|
||||
|
||||
//备份状态
|
||||
DBINSTANCE_BACKUP_READY = "ready" //正常
|
||||
DBINSTANCE_BACKUP_CREATING = "creating" //创建中
|
||||
DBINSTANCE_BACKUP_CREATE_FAILED = "create_failed" //创建失败
|
||||
DBINSTANCE_BACKUP_DELETING = "deleting" //删除中
|
||||
DBINSTANCE_BACKUP_DELETE_FAILED = "delete_failed" //删除失败
|
||||
DBINSTANCE_BACKUP_FAILED = "failed" //异常
|
||||
DBINSTANCE_BACKUP_UNKNOWN = "unknown" //未知
|
||||
DBINSTANCE_BACKUP_READY = "ready" //正常
|
||||
DBINSTANCE_BACKUP_CREATING = "creating" //创建中
|
||||
DBINSTANCE_BACKUP_CREATE_FAILED = "create_failed" //创建失败
|
||||
DBINSTANCE_BACKUP_DELETING = "deleting" //删除中
|
||||
DBINSTANCE_BACKUP_DELETE_FAILED = "delete_failed" //删除失败
|
||||
DBINSTANCE_BACKUP_FAILED = "failed" //异常
|
||||
DBINSTANCE_BACKUP_SYNCING_STATUS = "syncing" //同步状态
|
||||
DBINSTANCE_BACKUP_UNKNOWN = "unknown" //未知
|
||||
|
||||
//备份模式
|
||||
BACKUP_MODE_AUTOMATED = "automated" //自动
|
||||
|
||||
@@ -216,3 +216,6 @@ type DiskResourceInfo struct {
|
||||
|
||||
StorageResourceInfo
|
||||
}
|
||||
|
||||
type DiskSyncstatusInput struct {
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ const (
|
||||
DISK_DETACHING = "detaching"
|
||||
DISK_ATTACHING = "attaching"
|
||||
DISK_CLONING = "cloning" // 硬盘克隆
|
||||
DISK_SYNCING_STATUS = "syncing" // 同步状态
|
||||
|
||||
DISK_START_SAVE = "start_save"
|
||||
DISK_SAVING = "saving"
|
||||
|
||||
@@ -83,3 +83,6 @@ type ElasticcacheParameterDetails struct {
|
||||
|
||||
SElasticcacheParameter
|
||||
}
|
||||
|
||||
type ElasticcacheSyncstatusInput struct {
|
||||
}
|
||||
|
||||
@@ -78,3 +78,6 @@ type ElasticipDetails struct {
|
||||
// 绑定资源名称
|
||||
AssociateName string `json:"associate_name"`
|
||||
}
|
||||
|
||||
type ElasticipSyncstatusInput struct {
|
||||
}
|
||||
|
||||
@@ -19,14 +19,15 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
NAT_STAUTS_AVAILABLE = "available" //可用
|
||||
NAT_STATUS_ALLOCATE = "allocate" //创建中
|
||||
NAT_STATUS_DEPLOYING = "deploying" //配置中
|
||||
NAT_STATUS_UNKNOWN = "unknown" //未知状态
|
||||
NAT_STATUS_FAILED = "failed" //创建失败
|
||||
NAT_STATUS_DELETED = "deleted" //删除
|
||||
NAT_STATUS_DELETING = "deleting" //删除中
|
||||
NAT_STATUS_DELETE_FAILED = "delete_failed" //删除失败
|
||||
NAT_STAUTS_AVAILABLE = "available" //可用
|
||||
NAT_STATUS_ALLOCATE = "allocate" //创建中
|
||||
NAT_STATUS_DEPLOYING = "deploying" //配置中
|
||||
NAT_STATUS_UNKNOWN = "unknown" //未知状态
|
||||
NAT_STATUS_FAILED = "failed" //创建失败
|
||||
NAT_STATUS_DELETED = "deleted" //删除
|
||||
NAT_STATUS_DELETING = "deleting" //删除中
|
||||
NAT_STATUS_SYNCING_STATUS = "syncing" //同步状态
|
||||
NAT_STATUS_DELETE_FAILED = "delete_failed" //删除失败
|
||||
|
||||
NAT_SPEC_SMALL = "small" //小型
|
||||
NAT_SPEC_MIDDLE = "middle" //中型
|
||||
@@ -100,3 +101,6 @@ type NatEntryDetails struct {
|
||||
// NAT ENTRY的真实名称??
|
||||
RealName string `json:"real_name"`
|
||||
}
|
||||
|
||||
type NatGatewaySyncstatusInput struct {
|
||||
}
|
||||
|
||||
@@ -112,3 +112,6 @@ type SnapshotDetails struct {
|
||||
// 是否是子快照
|
||||
IsSubSnapshot bool `json:"is_sub_snapshot,allowempty"`
|
||||
}
|
||||
|
||||
type SnapshotSyncstatusInput struct {
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ const (
|
||||
|
||||
SNAPSHOT_POLICY_CREATING = "creating"
|
||||
|
||||
SNAPSHOT_SYNCING_STATUS = "syncing"
|
||||
|
||||
SNAPSHOT_POLICY_READY = "ready"
|
||||
SNAPSHOT_POLICY_UPDATING = "updating"
|
||||
SNAPSHOT_POLICY_UNKNOWN = "unknown"
|
||||
|
||||
@@ -59,3 +59,6 @@ type VpcResourceInfo struct {
|
||||
|
||||
ManagedResourceInfo
|
||||
}
|
||||
|
||||
type VpcSyncstatusInput struct {
|
||||
}
|
||||
|
||||
@@ -63,6 +63,10 @@ func (model *SStatusStandaloneResourceBase) SetStatus(userCred mcclient.TokenCre
|
||||
return statusBaseSetStatus(model, userCred, status, reason)
|
||||
}
|
||||
|
||||
func (model *SStatusStandaloneResourceBase) GetStatus() string {
|
||||
return model.Status
|
||||
}
|
||||
|
||||
func (manager *SStatusStandaloneResourceBaseManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, input apis.StatusStandaloneResourceCreateInput) (apis.StatusStandaloneResourceCreateInput, error) {
|
||||
var err error
|
||||
input.StandaloneResourceCreateInput, err = manager.SStandaloneResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, input.StandaloneResourceCreateInput)
|
||||
|
||||
@@ -1071,6 +1071,34 @@ func (bucket *SBucket) PerformAcl(
|
||||
}
|
||||
}
|
||||
|
||||
func (bucket *SBucket) AllowPerformSyncstatus(ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
data jsonutils.JSONObject,
|
||||
) bool {
|
||||
return bucket.IsOwner(userCred)
|
||||
}
|
||||
|
||||
// 同步存储桶状态
|
||||
func (bucket *SBucket) PerformSyncstatus(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
input api.BucketSyncstatusInput,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
var openTask = true
|
||||
count, err := taskman.TaskManager.QueryTasksOfObject(bucket, time.Now().Add(-3*time.Minute), &openTask).CountWithError()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if count > 0 {
|
||||
return nil, httperrors.NewBadRequestError("Bucket has %d task active, can't sync status", count)
|
||||
}
|
||||
|
||||
bucket.SetStatus(userCred, api.BUCKET_STATUS_SYNCING_STATUS, "perform_syncstatus")
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, bucket, "BucketSyncstatusTask", "")
|
||||
}
|
||||
|
||||
func (bucket *SBucket) AllowPerformSync(ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
|
||||
@@ -333,6 +333,44 @@ func (manager *SDBInstanceBackupManager) FetchCustomizeColumns(
|
||||
return rows
|
||||
}
|
||||
|
||||
func (self *SDBInstanceBackup) AllowPerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "syncstatus")
|
||||
}
|
||||
|
||||
// 同步RDS备份状态
|
||||
func (self *SDBInstanceBackup) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.DiskSyncstatusInput) (jsonutils.JSONObject, error) {
|
||||
var openTask = true
|
||||
count, err := taskman.TaskManager.QueryTasksOfObject(self, time.Now().Add(-3*time.Minute), &openTask).CountWithError()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if count > 0 {
|
||||
return nil, httperrors.NewBadRequestError("DBInstance backup has %d task active, can't sync status", count)
|
||||
}
|
||||
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, self, "DBInstanceBackupSyncstatusTask", "")
|
||||
}
|
||||
|
||||
func (backup *SDBInstanceBackup) GetIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
region := backup.GetRegion()
|
||||
if region == nil {
|
||||
return nil, errors.Wrap(httperrors.ErrInvalidStatus, "no valid cloudregion")
|
||||
}
|
||||
provider, err := backup.GetDriver()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return provider.GetIRegionById(region.GetExternalId())
|
||||
}
|
||||
|
||||
func (backup *SDBInstanceBackup) GetIDBInstanceBackup() (cloudprovider.ICloudDBInstanceBackup, error) {
|
||||
iRegion, err := backup.GetIRegion()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "backup.GetIRegion")
|
||||
}
|
||||
return iRegion.GetIDBInstanceBackupById(backup.ExternalId)
|
||||
}
|
||||
|
||||
func (manager *SDBInstanceBackupManager) SyncDBInstanceBackups(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, instance *SDBInstance, region *SCloudregion, cloudBackups []cloudprovider.ICloudDBInstanceBackup) compare.SyncResult {
|
||||
lockman.LockClass(ctx, manager, db.GetLockClassKey(manager, provider.GetOwnerId()))
|
||||
defer lockman.ReleaseClass(ctx, manager, db.GetLockClassKey(manager, provider.GetOwnerId()))
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
@@ -56,22 +55,6 @@ func (self *SDBInstanceResourceBase) GetVpc() (*SVpc, error) {
|
||||
return nat.GetVpc()
|
||||
}
|
||||
|
||||
func (self *SDBInstanceResourceBase) GetRegion() (*SCloudregion, error) {
|
||||
vpc, err := self.GetVpc()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetVpc")
|
||||
}
|
||||
return vpc.GetRegion()
|
||||
}
|
||||
|
||||
func (self *SDBInstanceResourceBase) GetIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
vpc, err := self.GetVpc()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetVpc")
|
||||
}
|
||||
return vpc.GetIRegion()
|
||||
}
|
||||
|
||||
func (self *SDBInstanceResourceBase) GetCloudprovider() *SCloudprovider {
|
||||
vpc, err := self.GetVpc()
|
||||
if err != nil {
|
||||
|
||||
@@ -733,12 +733,21 @@ func (self *SDBInstance) PerformReboot(ctx context.Context, userCred mcclient.To
|
||||
return nil, self.StartDBInstanceRebootTask(ctx, userCred, jsonutils.NewDict(), "")
|
||||
}
|
||||
|
||||
//同步RDS实例状态
|
||||
func (self *SDBInstance) AllowPerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "syncstatus")
|
||||
}
|
||||
|
||||
func (self *SDBInstance) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, self, "DBInstanceSyncStatusTask", "")
|
||||
}
|
||||
|
||||
func (self *SDBInstance) AllowPerformSyncStatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "sync-status")
|
||||
}
|
||||
|
||||
func (self *SDBInstance) PerformSyncStatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
return nil, self.StartDBInstanceSyncStatusTask(ctx, userCred, jsonutils.NewDict(), "")
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, self, "DBInstanceSyncStatusTask", "")
|
||||
}
|
||||
|
||||
func (self *SDBInstance) AllowPerformRenew(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
@@ -930,16 +939,6 @@ func (self *SDBInstance) StartDBInstanceRebootTask(ctx context.Context, userCred
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SDBInstance) StartDBInstanceSyncStatusTask(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, parentTaskId string) error {
|
||||
self.SetStatus(userCred, api.DBINSTANCE_SYNC_STATUS, "")
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "DBInstanceSyncStatusTask", self, userCred, data, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SDBInstanceManager) getDBInstancesByProviderId(providerId string) ([]SDBInstance, error) {
|
||||
instances := []SDBInstance{}
|
||||
err := fetchByManagerId(manager, providerId, &instances)
|
||||
|
||||
@@ -1766,6 +1766,24 @@ func (self *SDisk) RealDelete(ctx context.Context, userCred mcclient.TokenCreden
|
||||
return self.SVirtualResourceBase.Delete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SDisk) AllowPerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "syncstatus")
|
||||
}
|
||||
|
||||
// 同步磁盘状态
|
||||
func (self *SDisk) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.DiskSyncstatusInput) (jsonutils.JSONObject, error) {
|
||||
var openTask = true
|
||||
count, err := taskman.TaskManager.QueryTasksOfObject(self, time.Now().Add(-3*time.Minute), &openTask).CountWithError()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if count > 0 {
|
||||
return nil, httperrors.NewBadRequestError("Disk has %d task active, can't sync status", count)
|
||||
}
|
||||
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, self, "DiskSyncstatusTask", "")
|
||||
}
|
||||
|
||||
func (self *SDisk) AllowPerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "purge")
|
||||
}
|
||||
|
||||
@@ -1350,6 +1350,24 @@ func (self *SElasticcache) StartUpdateBackupPolicyTask(ctx context.Context, user
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SElasticcache) AllowPerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "syncstatus")
|
||||
}
|
||||
|
||||
// 同步弹性缓存状态
|
||||
func (self *SElasticcache) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.ElasticcacheSyncstatusInput) (jsonutils.JSONObject, error) {
|
||||
var openTask = true
|
||||
count, err := taskman.TaskManager.QueryTasksOfObject(self, time.Now().Add(-3*time.Minute), &openTask).CountWithError()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if count > 0 {
|
||||
return nil, httperrors.NewBadRequestError("Elasticcache has %d task active, can't sync status", count)
|
||||
}
|
||||
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, self, "ElasticcacheSyncstatusTask", "")
|
||||
}
|
||||
|
||||
func (self *SElasticcache) AllowPerformSync(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "sync")
|
||||
}
|
||||
|
||||
@@ -1136,6 +1136,19 @@ func (self *SElasticip) GetIEip() (cloudprovider.ICloudEIP, error) {
|
||||
return iregion.GetIEipById(self.GetExternalId())
|
||||
}
|
||||
|
||||
func (self *SElasticip) AllowPerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "syncstatus")
|
||||
}
|
||||
|
||||
// 同步弹性公网IP状态
|
||||
func (self *SElasticip) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.ElasticipSyncstatusInput) (jsonutils.JSONObject, error) {
|
||||
if self.Mode == api.EIP_MODE_INSTANCE_PUBLICIP {
|
||||
return nil, httperrors.NewUnsupportOperationError("fixed eip cannot sync status")
|
||||
}
|
||||
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, self, "EipSyncstatusTask", "")
|
||||
}
|
||||
|
||||
func (self *SElasticip) AllowPerformSync(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "sync")
|
||||
}
|
||||
@@ -1149,19 +1162,7 @@ func (self *SElasticip) PerformSync(ctx context.Context, userCred mcclient.Token
|
||||
return nil, httperrors.NewUnsupportOperationError("fixed eip cannot sync status")
|
||||
}
|
||||
|
||||
err := self.StartEipSyncstatusTask(ctx, userCred, "")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (self *SElasticip) StartEipSyncstatusTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "EipSyncstatusTask", self, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
log.Errorf("create EipSyncstatusTask fail %s", err)
|
||||
return err
|
||||
}
|
||||
self.SetStatus(userCred, "sync", "synchronize")
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, self, "EipSyncstatusTask", "")
|
||||
}
|
||||
|
||||
func (self *SElasticip) GetExtraDetails(
|
||||
|
||||
@@ -2617,6 +2617,7 @@ func (self *SGuest) AllowPerformSyncstatus(ctx context.Context, userCred mcclien
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "syncstatus")
|
||||
}
|
||||
|
||||
// 同步虚拟机状态
|
||||
func (self *SGuest) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
var openTask = true
|
||||
count, err := taskman.TaskManager.QueryTasksOfObject(self, time.Now().Add(-3*time.Minute), &openTask).CountWithError()
|
||||
|
||||
@@ -320,19 +320,7 @@ func (lb *SLoadbalancer) AllowPerformSyncstatus(ctx context.Context, userCred mc
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
return nil, lb.StartLoadBalancerSyncstatusTask(ctx, userCred, "")
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) StartLoadBalancerSyncstatusTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(lb.Status), "origin_status")
|
||||
lb.SetStatus(userCred, api.LB_SYNC_STATUS, "")
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerSyncstatusTask", lb, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, lb, "LoadbalancerSyncstatusTask", "")
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
@@ -29,6 +30,7 @@ import (
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -348,7 +350,7 @@ func (self *SNatGateway) syncRemoveCloudNatGateway(ctx context.Context, userCred
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
if err != nil { // cannot delete
|
||||
return self.SetStatus(userCred, api.VPC_STATUS_UNKNOWN, "sync to delete")
|
||||
return self.SetStatus(userCred, api.NAT_STATUS_UNKNOWN, "sync to delete")
|
||||
}
|
||||
return self.purge(ctx, userCred)
|
||||
}
|
||||
@@ -475,6 +477,24 @@ func (self *SNatGateway) SyncNatGatewayEips(ctx context.Context, userCred mcclie
|
||||
return result
|
||||
}
|
||||
|
||||
func (self *SNatGateway) AllowPerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return db.IsAdminAllowPerform(userCred, self, "syncstatus")
|
||||
}
|
||||
|
||||
// 同步NAT网关状态
|
||||
func (self *SNatGateway) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.NatGatewaySyncstatusInput) (jsonutils.JSONObject, error) {
|
||||
var openTask = true
|
||||
count, err := taskman.TaskManager.QueryTasksOfObject(self, time.Now().Add(-3*time.Minute), &openTask).CountWithError()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if count > 0 {
|
||||
return nil, httperrors.NewBadRequestError("Nat gateway has %d task active, can't sync status", count)
|
||||
}
|
||||
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, self, "NatGatewaySyncstatusTask", "")
|
||||
}
|
||||
|
||||
func (self *SNatGateway) GetINatGateway() (cloudprovider.ICloudNatGateway, error) {
|
||||
model, err := VpcManager.FetchById(self.VpcId)
|
||||
if err != nil {
|
||||
|
||||
@@ -2456,6 +2456,16 @@ func (network *SNetwork) GetDetailsAddresses(ctx context.Context, userCred mccli
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (net *SNetwork) AllowPerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return net.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, net, "syncstatus")
|
||||
}
|
||||
|
||||
// 同步接入云IP子网状态
|
||||
// 本地IDC不支持此操作
|
||||
func (net *SNetwork) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input *api.NetworkSyncInput) (jsonutils.JSONObject, error) {
|
||||
return net.PerformSync(ctx, userCred, query, input)
|
||||
}
|
||||
|
||||
func (net *SNetwork) AllowPerformSync(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return net.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, net, "sync")
|
||||
}
|
||||
@@ -2465,22 +2475,9 @@ func (net *SNetwork) AllowPerformSync(ctx context.Context, userCred mcclient.Tok
|
||||
func (net *SNetwork) PerformSync(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input *api.NetworkSyncInput) (jsonutils.JSONObject, error) {
|
||||
vpc := net.GetVpc()
|
||||
if vpc != nil && vpc.IsManaged() {
|
||||
err := net.StartNetworkSyncstatusTask(ctx, userCred, "")
|
||||
return nil, err
|
||||
} else {
|
||||
return nil, httperrors.NewUnsupportOperationError("on-premise network cannot sync status")
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, net, "NetworkSyncstatusTask", "")
|
||||
}
|
||||
}
|
||||
|
||||
func (net *SNetwork) StartNetworkSyncstatusTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "NetworkSyncstatusTask", net, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
log.Errorf("create NetworkSyncstatusTask fail %s", err)
|
||||
return err
|
||||
}
|
||||
net.SetStatus(userCred, api.NETWORK_STATUS_START_SYNC, "synchronize")
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
return nil, httperrors.NewUnsupportOperationError("on-premise network cannot sync status")
|
||||
}
|
||||
|
||||
func (net *SNetwork) AllowPerformStatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformStatusInput) bool {
|
||||
|
||||
@@ -127,6 +127,12 @@ type IRegionDriver interface {
|
||||
|
||||
IsSupportedBillingCycle(bc billing.SBillingCycle, resource string) bool
|
||||
GetSecgroupVpcid(vpcId string) string
|
||||
|
||||
RequestSyncDiskStatus(ctx context.Context, userCred mcclient.TokenCredential, disk *SDisk, task taskman.ITask) error
|
||||
RequestSyncSnapshotStatus(ctx context.Context, userCred mcclient.TokenCredential, snapshot *SSnapshot, task taskman.ITask) error
|
||||
RequestSyncNatGatewayStatus(ctx context.Context, userCred mcclient.TokenCredential, natgateway *SNatGateway, task taskman.ITask) error
|
||||
RequestSyncBucketStatus(ctx context.Context, userCred mcclient.TokenCredential, bucket *SBucket, task taskman.ITask) error
|
||||
RequestSyncDBInstanceBackupStatus(ctx context.Context, userCred mcclient.TokenCredential, backup *SDBInstanceBackup, task taskman.ITask) error
|
||||
}
|
||||
|
||||
type IDBInstanceDriver interface {
|
||||
@@ -177,6 +183,8 @@ type IElasticcacheDriver interface {
|
||||
RequestElasticcacheFlushInstance(ctx context.Context, userCred mcclient.TokenCredential, elasticcache *SElasticcache, task taskman.ITask) error
|
||||
RequestElasticcacheUpdateInstanceParameters(ctx context.Context, userCred mcclient.TokenCredential, elasticcache *SElasticcache, task taskman.ITask) error
|
||||
RequestElasticcacheUpdateBackupPolicy(ctx context.Context, userCred mcclient.TokenCredential, elasticcache *SElasticcache, task taskman.ITask) error
|
||||
|
||||
RequestSyncElasticcacheStatus(ctx context.Context, userCred mcclient.TokenCredential, elasticcache *SElasticcache, task taskman.ITask) error
|
||||
}
|
||||
|
||||
type IElasticcacheAccount interface {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
const (
|
||||
SYNCING_STATUS = "syncing"
|
||||
)
|
||||
|
||||
type IStatusBase interface {
|
||||
SetStatus(userCred mcclient.TokenCredential, status string, reason string) error
|
||||
GetStatus() string
|
||||
}
|
||||
|
||||
type IStatusStandaloneBase interface {
|
||||
db.IStandaloneModel
|
||||
IStatusBase
|
||||
}
|
||||
|
||||
func StartResourceSyncStatusTask(ctx context.Context, userCred mcclient.TokenCredential, obj IStatusStandaloneBase, taskName string, parentTaskId string) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(obj.GetStatus()), "origin_status")
|
||||
task, err := taskman.TaskManager.NewTask(ctx, taskName, obj, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
obj.SetStatus(userCred, SYNCING_STATUS, "perform_syncstatus")
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
@@ -646,6 +646,24 @@ func (self *SSnapshot) PerformDeleted(ctx context.Context, userCred mcclient.Tok
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (self *SSnapshot) AllowPerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "syncstatus")
|
||||
}
|
||||
|
||||
// 同步快照状态
|
||||
func (self *SSnapshot) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.SnapshotSyncstatusInput) (jsonutils.JSONObject, error) {
|
||||
var openTask = true
|
||||
count, err := taskman.TaskManager.QueryTasksOfObject(self, time.Now().Add(-3*time.Minute), &openTask).CountWithError()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if count > 0 {
|
||||
return nil, httperrors.NewBadRequestError("Snapshot has %d task active, can't sync status", count)
|
||||
}
|
||||
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, self, "SnapshotSyncstatusTask", "")
|
||||
}
|
||||
|
||||
func (self *SSnapshotManager) AllowGetPropertyMaxCount(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
+12
-16
@@ -971,28 +971,24 @@ func (self *SVpc) SyncRemoteWires(ctx context.Context, userCred mcclient.TokenCr
|
||||
return nil
|
||||
}
|
||||
|
||||
func (vpc *SVpc) AllowPerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return db.IsAdminAllowPerform(userCred, vpc, "syncstatus")
|
||||
}
|
||||
|
||||
// 同步VPC状态
|
||||
func (vpc *SVpc) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.VpcSyncstatusInput) (jsonutils.JSONObject, error) {
|
||||
return vpc.PerformSync(ctx, userCred, query, input)
|
||||
}
|
||||
|
||||
func (vpc *SVpc) AllowPerformSync(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return db.IsAdminAllowPerform(userCred, vpc, "sync")
|
||||
}
|
||||
|
||||
func (vpc *SVpc) PerformSync(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
func (vpc *SVpc) PerformSync(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.VpcSyncstatusInput) (jsonutils.JSONObject, error) {
|
||||
if vpc.IsManaged() {
|
||||
err := vpc.StartVpcSyncstatusTask(ctx, userCred, "")
|
||||
return nil, err
|
||||
} else {
|
||||
return nil, httperrors.NewUnsupportOperationError("on-premise vpc cannot sync status")
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, vpc, "VpcSyncstatusTask", "")
|
||||
}
|
||||
}
|
||||
|
||||
func (vpc *SVpc) StartVpcSyncstatusTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "VpcSyncstatusTask", vpc, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
log.Errorf("create NetworkSyncstatusTask fail %s", err)
|
||||
return err
|
||||
}
|
||||
vpc.SetStatus(userCred, api.VPC_STATUS_START_SYNC, "synchronize")
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
return nil, httperrors.NewUnsupportOperationError("on-premise vpc cannot sync status")
|
||||
}
|
||||
|
||||
func (self *SVpc) initWire(ctx context.Context, zone *SZone) (*SWire, error) {
|
||||
|
||||
@@ -314,3 +314,27 @@ func (self *SBaseRegionDriver) IsSupportedDBInstance() bool {
|
||||
func (self *SBaseRegionDriver) IsSupportedElasticcache() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestSyncDiskStatus(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestSyncDiskStatus")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestSyncSnapshotStatus(ctx context.Context, userCred mcclient.TokenCredential, snapshot *models.SSnapshot, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestSyncSnapshotStatus")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestSyncNatGatewayStatus(ctx context.Context, userCred mcclient.TokenCredential, natgateway *models.SNatGateway, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestSyncNatGatewayStatus")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestSyncBucketStatus(ctx context.Context, userCred mcclient.TokenCredential, bucket *models.SBucket, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestSyncBucketStatus")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestSyncDBInstanceBackupStatus(ctx context.Context, userCred mcclient.TokenCredential, backup *models.SDBInstanceBackup, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestSyncDBInstanceBackupStatus")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestSyncElasticcacheStatus(ctx context.Context, userCred mcclient.TokenCredential, elasticcache *models.SElasticcache, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestSyncElasticcacheStatus")
|
||||
}
|
||||
|
||||
@@ -2647,3 +2647,85 @@ func (self *SManagedVirtualizationRegionDriver) RequestElasticcacheBackupRestore
|
||||
func (self *SManagedVirtualizationRegionDriver) AllowUpdateElasticcacheAuthMode(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, elasticcache *models.SElasticcache) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestSyncDiskStatus(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
iDisk, err := disk.GetIDisk()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "disk.GetIDisk")
|
||||
}
|
||||
|
||||
return nil, disk.SetStatus(userCred, iDisk.GetStatus(), "syncstatus")
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestSyncSnapshotStatus(ctx context.Context, userCred mcclient.TokenCredential, snapshot *models.SSnapshot, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
iRegion, err := snapshot.GetISnapshotRegion()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "snapshot.GetISnapshotRegion")
|
||||
}
|
||||
|
||||
iSnapshot, err := iRegion.GetISnapshotById(snapshot.ExternalId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "iRegion.GetISnapshotById(%s)", snapshot.ExternalId)
|
||||
}
|
||||
|
||||
return nil, snapshot.SetStatus(userCred, iSnapshot.GetStatus(), "syncstatus")
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestSyncNatGatewayStatus(ctx context.Context, userCred mcclient.TokenCredential, natgateway *models.SNatGateway, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
iNat, err := natgateway.GetINatGateway()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "natgateway.GetINatGateway")
|
||||
}
|
||||
|
||||
return nil, natgateway.SetStatus(userCred, iNat.GetStatus(), "syncstatus")
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestSyncBucketStatus(ctx context.Context, userCred mcclient.TokenCredential, bucket *models.SBucket, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
iBucket, err := bucket.GetIBucket()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "bucket.GetIBucket")
|
||||
}
|
||||
|
||||
return nil, bucket.SetStatus(userCred, iBucket.GetStatus(), "syncstatus")
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestSyncDBInstanceBackupStatus(ctx context.Context, userCred mcclient.TokenCredential, backup *models.SDBInstanceBackup, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
iDBInstanceBackup, err := backup.GetIDBInstanceBackup()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "backup.GetIDBInstanceBackup")
|
||||
}
|
||||
|
||||
return nil, backup.SetStatus(userCred, iDBInstanceBackup.GetStatus(), "syncstatus")
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestSyncElasticcacheStatus(ctx context.Context, userCred mcclient.TokenCredential, elasticcache *models.SElasticcache, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
iRegion, err := elasticcache.GetIRegion()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "elasticcache.GetIRegion")
|
||||
}
|
||||
|
||||
iElasticcache, err := iRegion.GetIElasticcacheById(elasticcache.ExternalId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "elasticcache.GetIElasticcache")
|
||||
}
|
||||
|
||||
return nil, elasticcache.SetStatus(userCred, iElasticcache.GetStatus(), "syncstatus")
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type BucketSyncstatusTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(BucketSyncstatusTask{})
|
||||
}
|
||||
|
||||
func (self *BucketSyncstatusTask) taskFailed(ctx context.Context, bucket *models.SBucket, err error) {
|
||||
bucket.SetStatus(self.GetUserCred(), api.BUCKET_STATUS_UNKNOWN, err.Error())
|
||||
self.SetStageFailed(ctx, err.Error())
|
||||
db.OpsLog.LogEvent(bucket, db.ACT_SYNC_STATUS, bucket.GetShortDesc(ctx), self.GetUserCred())
|
||||
logclient.AddActionLogWithContext(ctx, bucket, logclient.ACT_SYNC_STATUS, err, self.UserCred, false)
|
||||
}
|
||||
|
||||
func (self *BucketSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
bucket := obj.(*models.SBucket)
|
||||
|
||||
region, err := bucket.GetRegion()
|
||||
if err != nil {
|
||||
self.taskFailed(ctx, bucket, errors.Wrap(err, "bucket.GetRegion"))
|
||||
return
|
||||
}
|
||||
|
||||
self.SetStage("OnBucketSyncStatusComplete", nil)
|
||||
err = region.GetDriver().RequestSyncBucketStatus(ctx, self.GetUserCred(), bucket, self)
|
||||
if err != nil {
|
||||
self.taskFailed(ctx, bucket, errors.Wrap(err, "RequestSyncBucketStatus"))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (self *BucketSyncstatusTask) OnBucketSyncStatusComplete(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *BucketSyncstatusTask) OnBucketSyncStatusCompleteFailed(ctx context.Context, bucket *models.SBucket, data jsonutils.JSONObject) {
|
||||
self.taskFailed(ctx, bucket, fmt.Errorf(data.String()))
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type DBInstanceBackupSyncstatusTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(DBInstanceBackupSyncstatusTask{})
|
||||
}
|
||||
|
||||
func (self *DBInstanceBackupSyncstatusTask) taskFailed(ctx context.Context, backup *models.SDBInstanceBackup, err error) {
|
||||
backup.SetStatus(self.GetUserCred(), api.DBINSTANCE_BACKUP_UNKNOWN, err.Error())
|
||||
self.SetStageFailed(ctx, err.Error())
|
||||
db.OpsLog.LogEvent(backup, db.ACT_SYNC_STATUS, backup.GetShortDesc(ctx), self.GetUserCred())
|
||||
logclient.AddActionLogWithContext(ctx, backup, logclient.ACT_SYNC_STATUS, err, self.UserCred, false)
|
||||
}
|
||||
|
||||
func (self *DBInstanceBackupSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
backup := obj.(*models.SDBInstanceBackup)
|
||||
|
||||
region := backup.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFailed(ctx, backup, fmt.Errorf("failed to found cloudregion for backup storage %s(%s)", backup.Name, backup.Id))
|
||||
return
|
||||
}
|
||||
|
||||
self.SetStage("OnDBInstanceBackupSyncStatusComplete", nil)
|
||||
err := region.GetDriver().RequestSyncDBInstanceBackupStatus(ctx, self.GetUserCred(), backup, self)
|
||||
if err != nil {
|
||||
self.taskFailed(ctx, backup, errors.Wrap(err, "RequestSyncDBInstanceBackupStatus"))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (self *DBInstanceBackupSyncstatusTask) OnDBInstanceBackupSyncStatusComplete(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *DBInstanceBackupSyncstatusTask) OnDBInstanceBackupSyncStatusCompleteFailed(ctx context.Context, backup *models.SDBInstanceBackup, data jsonutils.JSONObject) {
|
||||
self.taskFailed(ctx, backup, fmt.Errorf(data.String()))
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func (self *DBInstanceChangeConfigTask) OnDBInstanceChangeConfigComplete(ctx con
|
||||
logclient.AddActionLogWithStartable(self, dbinstance, logclient.ACT_CHANGE_CONFIG, nil, self.UserCred, true)
|
||||
|
||||
self.SetStage("OnSyncDBInstanceStatusComplete", nil)
|
||||
dbinstance.StartDBInstanceSyncStatusTask(ctx, self.UserCred, nil, self.GetTaskId())
|
||||
models.StartResourceSyncStatusTask(ctx, self.UserCred, dbinstance, "DBInstanceSyncStatusTask", self.GetTaskId())
|
||||
}
|
||||
|
||||
func (self *DBInstanceChangeConfigTask) OnDBInstanceChangeConfigCompleteFailed(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
|
||||
@@ -92,7 +92,7 @@ func (self *DBInstanceCreateTask) OnCreateDBInstanceComplete(ctx context.Context
|
||||
}
|
||||
|
||||
self.SetStage("OnSyncDBInstanceStatusComplete", nil)
|
||||
dbinstance.StartDBInstanceSyncStatusTask(ctx, self.UserCred, nil, self.GetTaskId())
|
||||
models.StartResourceSyncStatusTask(ctx, self.UserCred, dbinstance, "DBInstanceSyncStatusTask", self.GetTaskId())
|
||||
}
|
||||
|
||||
func (self *DBInstanceCreateTask) OnCreateDBInstanceCompleteFailed(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
|
||||
@@ -64,6 +64,6 @@ func (self *DBInstanceRenewTask) OnInit(ctx context.Context, obj db.IStandaloneM
|
||||
|
||||
logclient.AddActionLogWithStartable(self, instance, logclient.ACT_RENEW, nil, self.UserCred, true)
|
||||
|
||||
instance.StartDBInstanceSyncStatusTask(ctx, self.UserCred, nil, self.GetTaskId())
|
||||
models.StartResourceSyncStatusTask(ctx, self.UserCred, instance, "DBInstanceSyncStatusTask", self.GetTaskId())
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type DiskSyncstatusTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(DiskSyncstatusTask{})
|
||||
}
|
||||
|
||||
func (self *DiskSyncstatusTask) taskFailed(ctx context.Context, disk *models.SDisk, err error) {
|
||||
disk.SetStatus(self.GetUserCred(), api.DISK_UNKNOWN, err.Error())
|
||||
self.SetStageFailed(ctx, err.Error())
|
||||
db.OpsLog.LogEvent(disk, db.ACT_SYNC_STATUS, disk.GetShortDesc(ctx), self.GetUserCred())
|
||||
logclient.AddActionLogWithContext(ctx, disk, logclient.ACT_SYNC_STATUS, err, self.UserCred, false)
|
||||
}
|
||||
|
||||
func (self *DiskSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
disk := obj.(*models.SDisk)
|
||||
|
||||
storage := disk.GetStorage()
|
||||
if storage == nil {
|
||||
self.taskFailed(ctx, disk, fmt.Errorf("failed to found storage for disk %s", disk.Name))
|
||||
return
|
||||
}
|
||||
region := storage.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFailed(ctx, disk, fmt.Errorf("failed to found cloudregion for disk storage %s(%s)", disk.Name, disk.Id))
|
||||
return
|
||||
}
|
||||
|
||||
self.SetStage("OnDiskSyncStatusComplete", nil)
|
||||
err := region.GetDriver().RequestSyncDiskStatus(ctx, self.GetUserCred(), disk, self)
|
||||
if err != nil {
|
||||
self.taskFailed(ctx, disk, errors.Wrap(err, "RequestSyncDiskStatus"))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (self *DiskSyncstatusTask) OnDiskSyncStatusComplete(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *DiskSyncstatusTask) OnDiskSyncStatusCompleteFailed(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) {
|
||||
self.taskFailed(ctx, disk, fmt.Errorf(data.String()))
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type ElasticcacheSyncstatusTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(ElasticcacheSyncstatusTask{})
|
||||
}
|
||||
|
||||
func (self *ElasticcacheSyncstatusTask) taskFailed(ctx context.Context, cache *models.SElasticcache, err error) {
|
||||
cache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_UNKNOWN, err.Error())
|
||||
self.SetStageFailed(ctx, err.Error())
|
||||
db.OpsLog.LogEvent(cache, db.ACT_SYNC_STATUS, cache.GetShortDesc(ctx), self.GetUserCred())
|
||||
logclient.AddActionLogWithContext(ctx, cache, logclient.ACT_SYNC_STATUS, err, self.UserCred, false)
|
||||
}
|
||||
|
||||
func (self *ElasticcacheSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
cache := obj.(*models.SElasticcache)
|
||||
|
||||
region := cache.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFailed(ctx, cache, fmt.Errorf("failed to found cloudregion for elasticcache %s(%s)", cache.Name, cache.Id))
|
||||
return
|
||||
}
|
||||
|
||||
self.SetStage("OnElasticcacheSyncStatusComplete", nil)
|
||||
err := region.GetDriver().RequestSyncElasticcacheStatus(ctx, self.GetUserCred(), cache, self)
|
||||
if err != nil {
|
||||
self.taskFailed(ctx, cache, errors.Wrap(err, "RequestSyncElasticcacheStatus"))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (self *ElasticcacheSyncstatusTask) OnElasticcacheSyncStatusComplete(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *ElasticcacheSyncstatusTask) OnElasticcacheSyncStatusCompleteFailed(ctx context.Context, cache *models.SElasticcache, data jsonutils.JSONObject) {
|
||||
self.taskFailed(ctx, cache, fmt.Errorf(data.String()))
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type NatGatewaySyncstatusTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(NatGatewaySyncstatusTask{})
|
||||
}
|
||||
|
||||
func (self *NatGatewaySyncstatusTask) taskFailed(ctx context.Context, natgateway *models.SNatGateway, err error) {
|
||||
natgateway.SetStatus(self.GetUserCred(), api.NAT_STATUS_UNKNOWN, err.Error())
|
||||
self.SetStageFailed(ctx, err.Error())
|
||||
db.OpsLog.LogEvent(natgateway, db.ACT_SYNC_STATUS, natgateway.GetShortDesc(ctx), self.GetUserCred())
|
||||
logclient.AddActionLogWithContext(ctx, natgateway, logclient.ACT_SYNC_STATUS, err, self.UserCred, false)
|
||||
}
|
||||
|
||||
func (self *NatGatewaySyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
natgateway := obj.(*models.SNatGateway)
|
||||
|
||||
region := natgateway.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFailed(ctx, natgateway, fmt.Errorf("failed to found cloudregion for natgateway %s(%s)", natgateway.Name, natgateway.Id))
|
||||
return
|
||||
}
|
||||
|
||||
self.SetStage("OnNatGatewaySyncStatusComplete", nil)
|
||||
err := region.GetDriver().RequestSyncNatGatewayStatus(ctx, self.GetUserCred(), natgateway, self)
|
||||
if err != nil {
|
||||
self.taskFailed(ctx, natgateway, errors.Wrap(err, "RequestSyncNatGatewayStatus"))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (self *NatGatewaySyncstatusTask) OnNatGatewaySyncStatusComplete(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *NatGatewaySyncstatusTask) OnNatGatewaySyncStatusCompleteFailed(ctx context.Context, natgateway *models.SNatGateway, data jsonutils.JSONObject) {
|
||||
self.taskFailed(ctx, natgateway, fmt.Errorf(data.String()))
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type SnapshotSyncstatusTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(SnapshotSyncstatusTask{})
|
||||
}
|
||||
|
||||
func (self *SnapshotSyncstatusTask) taskFailed(ctx context.Context, snapshot *models.SSnapshot, err error) {
|
||||
snapshot.SetStatus(self.GetUserCred(), api.DISK_UNKNOWN, err.Error())
|
||||
self.SetStageFailed(ctx, err.Error())
|
||||
db.OpsLog.LogEvent(snapshot, db.ACT_SYNC_STATUS, snapshot.GetShortDesc(ctx), self.GetUserCred())
|
||||
logclient.AddActionLogWithContext(ctx, snapshot, logclient.ACT_SYNC_STATUS, err, self.UserCred, false)
|
||||
}
|
||||
|
||||
func (self *SnapshotSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
snapshot := obj.(*models.SSnapshot)
|
||||
|
||||
region := snapshot.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFailed(ctx, snapshot, fmt.Errorf("failed to found cloudregion for snapshot %s(%s)", snapshot.Name, snapshot.Id))
|
||||
return
|
||||
}
|
||||
|
||||
self.SetStage("OnSnapshotSyncStatusComplete", nil)
|
||||
err := region.GetDriver().RequestSyncSnapshotStatus(ctx, self.GetUserCred(), snapshot, self)
|
||||
if err != nil {
|
||||
self.taskFailed(ctx, snapshot, errors.Wrap(err, "RequestSyncSnapshotStatus"))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SnapshotSyncstatusTask) OnSnapshotSyncStatusComplete(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SnapshotSyncstatusTask) OnSnapshotSyncStatusCompleteFailed(ctx context.Context, snapshot *models.SSnapshot, data jsonutils.JSONObject) {
|
||||
self.taskFailed(ctx, snapshot, fmt.Errorf(data.String()))
|
||||
}
|
||||
@@ -42,7 +42,7 @@ type NatSDeleteShowOptions struct {
|
||||
ID string `help:"ID of the SNat"`
|
||||
}
|
||||
|
||||
type NatGatewayShowOptions struct {
|
||||
type NatGatewayIdOptions struct {
|
||||
ID string `help:"ID of Nat Gateway"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user