mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix(region): allowed to manually refresh cloudimage
This commit is contained in:
@@ -29,6 +29,7 @@ import (
|
||||
func init() {
|
||||
cmd := shell.NewResourceCmd(&modules.Cloudregions).WithKeyword("cloud-region")
|
||||
cmd.PerformClass("sync-skus", &options.CloudregionSkuSyncOptions{})
|
||||
cmd.Perform("sync-images", &options.CloudregionIdOptions{})
|
||||
|
||||
R(&options.SkuTaskQueryOptions{}, "cloud-region-sync-task-show", "Show details of skus sync tasks", func(s *mcclient.ClientSession, args *options.SkuTaskQueryOptions) error {
|
||||
params, err := args.Params()
|
||||
|
||||
@@ -177,3 +177,6 @@ type CloudregionSkuSyncInput struct {
|
||||
// choices: serversku|elasticcachesku|dbinstance_sku
|
||||
Resource string `json:"resource"`
|
||||
}
|
||||
|
||||
type SyncImagesInput struct {
|
||||
}
|
||||
|
||||
@@ -201,6 +201,7 @@ const (
|
||||
ACT_SYNC_CLOUD_DISK = "sync_cloud_disk"
|
||||
ACT_SYNC_CLOUD_SERVER = "sync_cloud_server"
|
||||
ACT_SYNC_CLOUD_SKUS = "sync_cloud_skus"
|
||||
ACT_SYNC_CLOUD_IMAGES = "sync_cloud_images"
|
||||
ACT_SYNC_CLOUD_EIP = "sync_cloud_eip"
|
||||
ACT_SYNC_CLOUD_PROJECT = "sync_cloud_project"
|
||||
ACT_SYNC_CLOUD_ELASTIC_CACHE = "sync_cloud_elastic_cache"
|
||||
|
||||
@@ -30,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/compute/options"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -1125,6 +1126,23 @@ func (manager *SCloudregionManager) GetPropertySyncTasks(ctx context.Context, us
|
||||
return GetPropertySkusSyncTasks(ctx, userCred, query)
|
||||
}
|
||||
|
||||
func (self *SCloudregion) AllowSyncImages(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool {
|
||||
return db.IsAdminAllowPerform(userCred, self, "sync-images")
|
||||
}
|
||||
|
||||
func (self *SCloudregion) PerformSyncImages(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.SyncImagesInput) (jsonutils.JSONObject, error) {
|
||||
return nil, self.StartSyncImagesTask(ctx, userCred, "")
|
||||
}
|
||||
|
||||
func (self *SCloudregion) StartSyncImagesTask(ctx context.Context, userCred mcclient.TokenCredential, parentId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "CloudregionSyncImagesTask", self, userCred, nil, "", "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "NewTask")
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudregion) GetCloudprovider() (*SCloudprovider, error) {
|
||||
if len(self.ManagerId) == 0 {
|
||||
return nil, sql.ErrNoRows
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
// 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"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"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 CloudregionSyncImagesTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(CloudregionSyncImagesTask{})
|
||||
}
|
||||
|
||||
func (self *CloudregionSyncImagesTask) taskFailed(ctx context.Context, region *models.SCloudregion, err error) {
|
||||
db.OpsLog.LogEvent(region, db.ACT_SYNC_CLOUD_IMAGES, err, self.GetUserCred())
|
||||
logclient.AddActionLogWithStartable(self, region, logclient.ACT_CLOUD_SYNC, err, self.UserCred, false)
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||
}
|
||||
|
||||
func (self *CloudregionSyncImagesTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) {
|
||||
region := obj.(*models.SCloudregion)
|
||||
|
||||
err := region.SyncCloudImages(ctx, self.GetUserCred(), true)
|
||||
if err != nil {
|
||||
self.taskFailed(ctx, region, errors.Wrapf(err, "SyncCloudImages"))
|
||||
return
|
||||
}
|
||||
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
@@ -42,3 +42,15 @@ type CloudregionSkuSyncOptions struct {
|
||||
func (opts *CloudregionSkuSyncOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(opts), nil
|
||||
}
|
||||
|
||||
type CloudregionIdOptions struct {
|
||||
ID string `help:"Cloudregion Id"`
|
||||
}
|
||||
|
||||
func (opts *CloudregionIdOptions) GetId() string {
|
||||
return opts.ID
|
||||
}
|
||||
|
||||
func (opts *CloudregionIdOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user