mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
* fix(host): slvm storage active on init * fix(region): guest live migrate cache all of guestimage caches
This commit is contained in:
@@ -146,26 +146,55 @@ func (task *GuestMigrateTask) SaveScheduleResult(ctx context.Context, obj ISched
|
||||
body.Set("is_local_storage", jsonutils.JSONFalse)
|
||||
}
|
||||
|
||||
task.SetStage("OnCachedImageComplete", body)
|
||||
// prepare disk for migration
|
||||
if len(disk.TemplateId) > 0 && isLocalStorage {
|
||||
targetStorageCache := targetHost.GetLocalStoragecache()
|
||||
if targetStorageCache != nil {
|
||||
input := api.CacheImageInput{
|
||||
ImageId: disk.TemplateId,
|
||||
Format: disk.DiskFormat,
|
||||
IsForce: false,
|
||||
SourceHostId: guest.HostId,
|
||||
ParentTaskId: task.GetTaskId(),
|
||||
templates := []string{}
|
||||
guestdisks, _ := guest.GetDisks()
|
||||
for i := range guestdisks {
|
||||
if guestdisks[i].TemplateId != "" {
|
||||
templates = append(templates, guestdisks[i].TemplateId)
|
||||
}
|
||||
err := targetStorageCache.StartImageCacheTask(ctx, task.UserCred, input)
|
||||
if err != nil {
|
||||
task.TaskFailed(ctx, guest, jsonutils.NewString(err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
if len(templates) > 0 {
|
||||
body.Set("cache_templates", jsonutils.NewStringArray(templates))
|
||||
}
|
||||
}
|
||||
task.OnCachedImageComplete(ctx, guest, nil)
|
||||
task.SetStage("OnStartCacheImages", body)
|
||||
task.OnStartCacheImages(ctx, guest, nil)
|
||||
}
|
||||
|
||||
func (task *GuestMigrateTask) OnStartCacheImages(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
|
||||
templates, _ := task.Params.GetArray("cache_templates")
|
||||
if len(templates) == 0 {
|
||||
task.OnCachedImageComplete(ctx, guest, nil)
|
||||
return
|
||||
}
|
||||
|
||||
templateId, _ := templates[0].GetString()
|
||||
task.Params.Set("cache_templates", jsonutils.NewArray(templates[1:]...))
|
||||
task.SetStage("OnStartCacheImages", nil)
|
||||
|
||||
targetHostId, _ := task.Params.GetString("target_host_id")
|
||||
targetHost := models.HostManager.FetchHostById(targetHostId)
|
||||
targetStorageCache := targetHost.GetLocalStoragecache()
|
||||
if targetStorageCache != nil {
|
||||
input := api.CacheImageInput{
|
||||
ImageId: templateId,
|
||||
IsForce: false,
|
||||
SourceHostId: guest.HostId,
|
||||
ParentTaskId: task.GetTaskId(),
|
||||
}
|
||||
err := targetStorageCache.StartImageCacheTask(ctx, task.UserCred, input)
|
||||
if err != nil {
|
||||
task.TaskFailed(ctx, guest, jsonutils.NewString(err.Error()))
|
||||
}
|
||||
return
|
||||
}
|
||||
task.OnStartCacheImages(ctx, guest, nil)
|
||||
}
|
||||
|
||||
func (task *GuestMigrateTask) OnStartCacheImagesFailed(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
|
||||
task.TaskFailed(ctx, guest, data)
|
||||
}
|
||||
|
||||
// For local storage get disk info
|
||||
|
||||
@@ -261,3 +261,15 @@ func VgDisplay(vgName string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func VgActive(vgName string, active bool) error {
|
||||
opts := "-ay"
|
||||
if !active {
|
||||
opts = "-an"
|
||||
}
|
||||
out, err := procutils.NewRemoteCommandAsFarAsPossible("lvm", "vgchange", opts, vgName).Output()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "vgchange %s %s failed %s", opts, vgName, out)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -89,6 +89,10 @@ func (s *SSLVMStorage) GetDiskById(diskId string) (IDisk, error) {
|
||||
}
|
||||
|
||||
func (s *SSLVMStorage) Accessible() error {
|
||||
if err := lvmutils.VgActive(s.Path, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := lvmutils.VgDisplay(s.Path); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user