mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
修正:host-undo-recycle fail
This commit is contained in:
@@ -25,9 +25,9 @@ func init() {
|
||||
}
|
||||
var result *modules.ListResult
|
||||
var err error
|
||||
if len(args.Storage) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Storage), "storage")
|
||||
}
|
||||
// if len(args.Storage) > 0 {
|
||||
// params.Add(jsonutils.NewString(args.Storage), "storage")
|
||||
// }
|
||||
if len(args.Host) > 0 {
|
||||
result, err = modules.Hoststorages.ListDescendent(s, args.Host, params)
|
||||
} else if len(args.Storage) > 0 {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/tristate"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
@@ -351,7 +352,10 @@ func doUndoPrepaidRecycle(ctx context.Context, userCred mcclient.TokenCredential
|
||||
q := HostManager.Query()
|
||||
q = q.Equals("external_id", host.ExternalId)
|
||||
q = q.Equals("host_type", host.HostType)
|
||||
q = q.IsNullOrEmpty("resource_type")
|
||||
q = q.Filter(sqlchemy.OR(
|
||||
sqlchemy.IsNullOrEmpty(q.Field("resource_type")),
|
||||
sqlchemy.Equals(q.Field("resource_type"), HostResourceTypeShared),
|
||||
))
|
||||
|
||||
oHostCnt := q.Count()
|
||||
|
||||
@@ -428,13 +432,14 @@ func doUndoPrepaidRecycle(ctx context.Context, userCred mcclient.TokenCredential
|
||||
return err
|
||||
}
|
||||
|
||||
oStorageObj, err := StorageManager.FetchByExternalId(istorage.GetGlobalId())
|
||||
if err != nil {
|
||||
log.Errorf("StorageManager.FetchByExternalId fail %s", err)
|
||||
return err
|
||||
oHostStorage := oHost.GetHoststorageByExternalId(istorage.GetGlobalId())
|
||||
if oHostStorage == nil {
|
||||
msg := fmt.Sprintf("oHost.GetHoststorageByExternalId not found %s", istorage.GetGlobalId())
|
||||
log.Errorf(msg)
|
||||
return errors.New(msg)
|
||||
}
|
||||
|
||||
oStorage := oStorageObj.(*SStorage)
|
||||
oStorage := oHostStorage.GetStorage()
|
||||
|
||||
if storage.StorageType == STORAGE_LOCAL {
|
||||
_, err = disk.GetModelManager().TableSpec().Update(disk, func() error {
|
||||
|
||||
@@ -502,6 +502,26 @@ func (self *SHost) GetHoststorageOfId(storageId string) *SHoststorage {
|
||||
return &hoststorage
|
||||
}
|
||||
|
||||
func (self *SHost) GetHoststorageByExternalId(extId string) *SHoststorage {
|
||||
hoststorage := SHoststorage{}
|
||||
hoststorage.SetModelManager(HoststorageManager)
|
||||
|
||||
hoststorages := HoststorageManager.Query().SubQuery()
|
||||
storages := StorageManager.Query().SubQuery()
|
||||
q := hoststorages.Query()
|
||||
q = q.Join(storages, sqlchemy.Equals(hoststorages.Field("storage_id"), storages.Field("id")))
|
||||
q = q.Filter(sqlchemy.Equals(hoststorages.Field("host_id"), self.Id))
|
||||
q = q.Filter(sqlchemy.Equals(storages.Field("external_id"), extId))
|
||||
|
||||
err := q.First(&hoststorage)
|
||||
if err != nil {
|
||||
log.Errorf("GetHoststorageByExternalId fail %s", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
return &hoststorage
|
||||
}
|
||||
|
||||
func (self *SHost) GetStorageByFilePath(path string) *SStorage {
|
||||
hoststorages := self.GetHoststorages()
|
||||
if hoststorages == nil {
|
||||
|
||||
Reference in New Issue
Block a user