mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-17 16:26:57 +08:00
fix storage attach host sync status
This commit is contained in:
@@ -62,6 +62,17 @@ func (self *SKVMHostDriver) ValidateAttachStorage(host *models.SHost, storage *m
|
||||
pool, _ := storage.StorageConf.GetString("pool")
|
||||
data.Set("mount_point", jsonutils.NewString(fmt.Sprintf("rbd:%s", pool)))
|
||||
} else if utils.IsInStringArray(storage.StorageType, api.SHARED_FILE_STORAGE) {
|
||||
mountPoint, err := data.GetString("mount_point")
|
||||
if err != nil {
|
||||
return httperrors.NewMissingParameterError("mount_point")
|
||||
}
|
||||
count, err := models.HoststorageManager.Query().Equals("host_id", host.Id).Equals("mount_point", mountPoint).CountWithError()
|
||||
if err != nil {
|
||||
return httperrors.NewInternalServerError("Query host storage error %s", err)
|
||||
}
|
||||
if count > 0 {
|
||||
return httperrors.NewBadRequestError("Host %s already have mount point %s with other storage", host.Name, mountPoint)
|
||||
}
|
||||
if host.HostStatus != api.HOST_ONLINE {
|
||||
return httperrors.NewInvalidStatusError("Attach nfs storage require host status is online")
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@ func (self *HostStorageAttachTask) OnAttachStorageComplete(ctx context.Context,
|
||||
db.OpsLog.LogEvent(storage, db.ACT_ATTACH, "", self.GetUserCred())
|
||||
logclient.AddActionLogWithContext(ctx, storage, logclient.ACT_ATTACH_HOST,
|
||||
fmt.Sprintf("Attach host %s success", host.Name), self.GetUserCred(), true)
|
||||
storage.SyncStatusWithHosts()
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,14 @@ package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"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 HostStorageDetachTask struct {
|
||||
@@ -33,6 +35,15 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *HostStorageDetachTask) taskFail(ctx context.Context, host *models.SHost, reason string) {
|
||||
var hoststorage = new(models.SHoststorage)
|
||||
storageId, _ := self.GetParams().GetString("storage_id")
|
||||
err := models.HoststorageManager.Query().Equals("host_id", host.Id).Equals("storage_id", storageId).First(hoststorage)
|
||||
if err == nil {
|
||||
storage := hoststorage.GetStorage()
|
||||
note := fmt.Sprintf("detach host %s failed: %s", host.Name, reason)
|
||||
db.OpsLog.LogEvent(storage, db.ACT_DETACH_FAIL, note, self.GetUserCred())
|
||||
logclient.AddActionLogWithContext(ctx, storage, logclient.ACT_DETACH_HOST, note, self.GetUserCred(), false)
|
||||
}
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
@@ -53,7 +64,13 @@ func (self *HostStorageDetachTask) OnInit(ctx context.Context, obj db.IStandalon
|
||||
}
|
||||
|
||||
func (self *HostStorageDetachTask) OnDetachStorageComplete(ctx context.Context, host *models.SHost, data jsonutils.JSONObject) {
|
||||
storageId, _ := self.GetParams().GetString("storage_id")
|
||||
storage := models.StorageManager.FetchStorageById(storageId)
|
||||
db.OpsLog.LogEvent(storage, db.ACT_DETACH, "", self.GetUserCred())
|
||||
logclient.AddActionLogWithContext(ctx, storage, logclient.ACT_DETACH_HOST,
|
||||
fmt.Sprintf("Detach host %s success", host.Name), self.GetUserCred(), true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
storage.SyncStatusWithHosts()
|
||||
}
|
||||
|
||||
func (self *HostStorageDetachTask) OnDetachStorageCompleteFailed(ctx context.Context, host *models.SHost, reason jsonutils.JSONObject) {
|
||||
|
||||
@@ -141,6 +141,7 @@ const (
|
||||
ACT_APPLY_SNAPSHOT_POLICY = "绑定快照策略"
|
||||
ACT_CANCEL_SNAPSHOT_POLICY = "取消快照策略"
|
||||
ACT_ATTACH_HOST = "关联宿主机"
|
||||
ACT_DETACH_HOST = "取消关联宿主机"
|
||||
|
||||
ACT_IMAGE_SAVE = "上传镜像"
|
||||
ACT_IMAGE_PROBE = "镜像检测"
|
||||
|
||||
Reference in New Issue
Block a user