mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 16:13:56 +08:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
436b809249 | ||
|
|
d894992e29 | ||
|
|
c0db3ead14 | ||
|
|
91dbb1b64e | ||
|
|
7f52cc5ec0 | ||
|
|
213637679e | ||
|
|
02dc737ccd | ||
|
|
627e97b73a |
@@ -43,6 +43,9 @@ const (
|
||||
|
||||
SERVICE_TYPE_ETCD = "etcd"
|
||||
SERVICE_TYPE_INFLUXDB = "influxdb"
|
||||
|
||||
STATUS_UPDATE_TAGS = "update_tags"
|
||||
STATUS_UPDATE_TAGS_FAILED = "update_tags_fail"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -784,17 +784,13 @@ func (self *SMongoDB) PerformRemoteUpdate(ctx context.Context, userCred mcclient
|
||||
|
||||
func (self *SMongoDB) StartRemoteUpdateTask(ctx context.Context, userCred mcclient.TokenCredential, replaceTags bool, parentTaskId string) error {
|
||||
data := jsonutils.NewDict()
|
||||
if replaceTags {
|
||||
data.Add(jsonutils.JSONTrue, "replace_tags")
|
||||
data.Add(jsonutils.NewBool(replaceTags), "replace_tags")
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "MongoDBRemoteUpdateTask", self, userCred, data, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "NewTask")
|
||||
}
|
||||
if task, err := taskman.TaskManager.NewTask(ctx, "MongoDBRemoteUpdateTask", self, userCred, data, parentTaskId, "", nil); err != nil {
|
||||
log.Errorln(err)
|
||||
return errors.Wrap(err, "Start ElasticcacheRemoteUpdateTask")
|
||||
} else {
|
||||
self.SetStatus(userCred, api.DBINSTANCE_UPDATE_TAGS, "StartRemoteUpdateTask")
|
||||
task.ScheduleRun(nil)
|
||||
}
|
||||
return nil
|
||||
self.SetStatus(userCred, apis.STATUS_UPDATE_TAGS, "StartRemoteUpdateTask")
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SMongoDB) OnMetadataUpdated(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
|
||||
94
pkg/compute/tasks/mongodb_remote_update_task.go
Normal file
94
pkg/compute/tasks/mongodb_remote_update_task.go
Normal file
@@ -0,0 +1,94 @@
|
||||
// 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/apis"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type MongoDBRemoteUpdateTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(MongoDBRemoteUpdateTask{})
|
||||
}
|
||||
|
||||
func (self *MongoDBRemoteUpdateTask) taskFail(ctx context.Context, mongodb *models.SMongoDB, err error) {
|
||||
mongodb.SetStatus(self.UserCred, apis.STATUS_UPDATE_TAGS_FAILED, err.Error())
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||
}
|
||||
|
||||
func (self *MongoDBRemoteUpdateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
mongodb := obj.(*models.SMongoDB)
|
||||
replaceTags := jsonutils.QueryBoolean(self.Params, "replace_tags", false)
|
||||
|
||||
iMongoDB, err := mongodb.GetIMongoDB()
|
||||
if err != nil {
|
||||
self.taskFail(ctx, mongodb, errors.Wrapf(err, "GetIMongoDB"))
|
||||
return
|
||||
}
|
||||
|
||||
oldTags, err := iMongoDB.GetTags()
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
self.OnRemoteUpdateComplete(ctx, mongodb, nil)
|
||||
return
|
||||
}
|
||||
self.taskFail(ctx, mongodb, errors.Wrapf(err, "GetTags"))
|
||||
return
|
||||
}
|
||||
tags, err := mongodb.GetAllUserMetadata()
|
||||
if err != nil {
|
||||
self.taskFail(ctx, mongodb, errors.Wrapf(err, "GetAllUserMetadata"))
|
||||
return
|
||||
}
|
||||
tagsUpdateInfo := cloudprovider.TagsUpdateInfo{OldTags: oldTags, NewTags: tags}
|
||||
err = cloudprovider.SetTags(ctx, iMongoDB, mongodb.ManagerId, tags, replaceTags)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
self.OnRemoteUpdateComplete(ctx, mongodb, nil)
|
||||
return
|
||||
}
|
||||
logclient.AddActionLogWithStartable(self, mongodb, logclient.ACT_UPDATE_TAGS, err, self.GetUserCred(), false)
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||
return
|
||||
}
|
||||
logclient.AddActionLogWithStartable(self, mongodb, logclient.ACT_UPDATE_TAGS, tagsUpdateInfo, self.GetUserCred(), true)
|
||||
self.OnRemoteUpdateComplete(ctx, mongodb, nil)
|
||||
}
|
||||
|
||||
func (self *MongoDBRemoteUpdateTask) OnRemoteUpdateComplete(ctx context.Context, mongodb *models.SMongoDB, data jsonutils.JSONObject) {
|
||||
self.SetStage("OnSyncStatusComplete", nil)
|
||||
models.StartResourceSyncStatusTask(ctx, self.UserCred, mongodb, "MongoDBSyncstatusTask", self.GetTaskId())
|
||||
}
|
||||
|
||||
func (self *MongoDBRemoteUpdateTask) OnSyncStatusComplete(ctx context.Context, mongodb *models.SMongoDB, data jsonutils.JSONObject) {
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *MongoDBRemoteUpdateTask) OnSyncStatusCompleteFailed(ctx context.Context, mongodb *models.SMongoDB, data jsonutils.JSONObject) {
|
||||
self.SetStageFailed(ctx, data)
|
||||
}
|
||||
@@ -104,6 +104,7 @@ func checkSshableForYunionCloud(session *mcclient.ClientSession, serverDetail *c
|
||||
lfParams := jsonutils.NewDict()
|
||||
lfParams.Set("proto", jsonutils.NewString("tcp"))
|
||||
lfParams.Set("port", jsonutils.NewInt(22))
|
||||
lfParams.Set("addr", jsonutils.NewString(ip))
|
||||
data, err := modules.Servers.PerformAction(session, serverDetail.Id, "list-forward", lfParams)
|
||||
if err != nil {
|
||||
err = errors.Wrapf(err, "unable to List Forward for server %s", serverDetail.Id)
|
||||
|
||||
@@ -115,7 +115,7 @@ type SImage struct {
|
||||
// 镜像大小, 单位Byte
|
||||
Size int64 `nullable:"true" list:"user" create:"optional"`
|
||||
// 存储地址
|
||||
Location string `nullable:"true"`
|
||||
Location string `nullable:"true" list:"user"`
|
||||
|
||||
// 镜像格式
|
||||
DiskFormat string `width:"20" charset:"ascii" nullable:"true" list:"user" create:"optional" default:"raw"`
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/image/models"
|
||||
"yunion.io/x/onecloud/pkg/image/options"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/notify"
|
||||
"yunion.io/x/onecloud/pkg/util/procutils"
|
||||
)
|
||||
@@ -89,8 +90,10 @@ func (self *PutImageTask) OnInit(ctx context.Context, obj db.IStandaloneModel, d
|
||||
if err != nil {
|
||||
log.Errorf("failed update image location %s", err)
|
||||
} else {
|
||||
if err = procutils.NewCommand("rm", "-f", imagePath).Run(); err != nil {
|
||||
log.Errorf("failed remove file %s: %s", imagePath, err)
|
||||
if !strings.Contains(imagePath, options.Options.S3MountPoint) {
|
||||
if err = procutils.NewCommand("rm", "-f", imagePath).Run(); err != nil {
|
||||
log.Errorf("failed remove file %s: %s", imagePath, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,12 +71,13 @@ const (
|
||||
ALIYUN_ES_API_VERSION = "2017-06-13"
|
||||
ALIYUN_KAFKA_API_VERSION = "2019-09-16"
|
||||
|
||||
ALIYUN_SERVICE_ECS = "ecs"
|
||||
ALIYUN_SERVICE_VPC = "vpc"
|
||||
ALIYUN_SERVICE_RDS = "rds"
|
||||
ALIYUN_SERVICE_SLB = "slb"
|
||||
ALIYUN_SERVICE_KVS = "kvs"
|
||||
ALIYUN_SERVICE_NAS = "nas"
|
||||
ALIYUN_SERVICE_ECS = "ecs"
|
||||
ALIYUN_SERVICE_VPC = "vpc"
|
||||
ALIYUN_SERVICE_RDS = "rds"
|
||||
ALIYUN_SERVICE_SLB = "slb"
|
||||
ALIYUN_SERVICE_KVS = "kvs"
|
||||
ALIYUN_SERVICE_NAS = "nas"
|
||||
ALIYUN_SERVICE_MONGO_DB = "mongodb"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -252,6 +252,10 @@ func (self *SRegion) GetMongoDBsByType(mongoType string) ([]SMongoDB, error) {
|
||||
return dbs, nil
|
||||
}
|
||||
|
||||
func (self *SMongoDB) SetTags(tags map[string]string, replace bool) error {
|
||||
return self.region.SetResourceTags(ALIYUN_SERVICE_MONGO_DB, "INSTANCE", self.GetId(), tags, replace)
|
||||
}
|
||||
|
||||
func (self *SRegion) GetICloudMongoDBById(id string) (cloudprovider.ICloudMongoDB, error) {
|
||||
db, err := self.GetMongoDB(id)
|
||||
if err != nil {
|
||||
|
||||
@@ -38,6 +38,8 @@ func (self *SRegion) tagRequest(serviceType, action string, params map[string]st
|
||||
return self.kvsRequest(action, params)
|
||||
case ALIYUN_SERVICE_NAS:
|
||||
return self.nasRequest(action, params)
|
||||
case ALIYUN_SERVICE_MONGO_DB:
|
||||
return self.mongodbRequest(action, params)
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid service type")
|
||||
}
|
||||
|
||||
@@ -251,6 +251,10 @@ func (self *SRegion) DeleteMongoDB(id string) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (self *SMongoDB) SetTags(tags map[string]string, replace bool) error {
|
||||
return self.region.SetResourceTags("mongodb", "instance", []string{self.InstanceId}, tags, replace)
|
||||
}
|
||||
|
||||
func (self *SMongoDB) GetIBackups() ([]cloudprovider.SMongoDBBackup, error) {
|
||||
return self.region.GetMongoDBBackups(self.InstanceId)
|
||||
}
|
||||
|
||||
@@ -177,6 +177,9 @@ func (r *SBaseRedfishClient) Probe(ctx context.Context) error {
|
||||
if r.IsDebug {
|
||||
log.Debugf("%s", resp.PrettyString())
|
||||
}
|
||||
if resp == nil {
|
||||
return errors.Errorf("Response is nil")
|
||||
}
|
||||
err = r.IRedfishDriver().ParseRoot(resp)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "r.IRedfishDriver().ParseRoot(resp)")
|
||||
|
||||
Reference in New Issue
Block a user