mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
instance snapshot bugfix
This commit is contained in:
@@ -1124,10 +1124,14 @@ func (manager *SGuestManager) validateCreateData(
|
||||
return nil, httperrors.NewInputParameterError("invalid duration %s", input.Duration)
|
||||
}
|
||||
|
||||
if input.BillingType == billing_api.BILLING_TYPE_POSTPAID && !GetDriver(hypervisor).IsSupportPostpaidExpire() {
|
||||
return nil, httperrors.NewBadRequestError("guest %s unsupport postpaid expire", hypervisor)
|
||||
} else if !GetDriver(hypervisor).IsSupportedBillingCycle(billingCycle) {
|
||||
return nil, httperrors.NewInputParameterError("unsupported duration %s", input.Duration)
|
||||
if input.BillingType == billing_api.BILLING_TYPE_POSTPAID {
|
||||
if !GetDriver(hypervisor).IsSupportPostpaidExpire() {
|
||||
return nil, httperrors.NewBadRequestError("guest %s unsupport postpaid expire", hypervisor)
|
||||
}
|
||||
} else {
|
||||
if !GetDriver(hypervisor).IsSupportedBillingCycle(billingCycle) {
|
||||
return nil, httperrors.NewInputParameterError("unsupported duration %s", input.Duration)
|
||||
}
|
||||
}
|
||||
|
||||
if len(input.BillingType) == 0 {
|
||||
|
||||
@@ -57,6 +57,7 @@ type SInstanceSnapshot struct {
|
||||
RefCount int `default:"0" list:"user"`
|
||||
SecGroups jsonutils.JSONObject `nullable:"true" list:"user"`
|
||||
KeypairId string `width:"36" charset:"ascii" nullable:"true" list:"user"`
|
||||
OsType string `width:"36" charset:"ascii" nullable:"true" list:"user"`
|
||||
}
|
||||
|
||||
type SInstanceSnapshotManager struct {
|
||||
@@ -208,7 +209,7 @@ func (manager *SInstanceSnapshotManager) CreateInstanceSnapshot(
|
||||
}
|
||||
instanceSnapshot.SecGroups = jsonutils.Marshal(secIds)
|
||||
}
|
||||
|
||||
instanceSnapshot.OsType = guest.OsType
|
||||
instanceSnapshot.ServerMetadata = serverMetadata
|
||||
err := manager.TableSpec().Insert(instanceSnapshot)
|
||||
if err != nil {
|
||||
@@ -254,6 +255,7 @@ func (self *SInstanceSnapshot) ToInstanceCreateInput(
|
||||
}
|
||||
sourceInput.Secgroups = inputSecgs
|
||||
}
|
||||
sourceInput.OsType = self.OsType
|
||||
// sourceInput.Networks = serverConfig.Networks
|
||||
return sourceInput, nil
|
||||
}
|
||||
|
||||
@@ -133,7 +133,9 @@ func (self *GuestStartTask) OnStartComplete(ctx context.Context, obj db.IStandal
|
||||
guest := obj.(*models.SGuest)
|
||||
db.OpsLog.LogEvent(guest, db.ACT_START, guest.GetShortDesc(ctx), self.UserCred)
|
||||
self.SetStage("OnGuestSyncstatusAfterStart", nil)
|
||||
guest.StartSyncstatus(ctx, self.UserCred, self.GetTaskId())
|
||||
if guest.Hypervisor != api.HYPERVISOR_KVM {
|
||||
guest.StartSyncstatus(ctx, self.UserCred, self.GetTaskId())
|
||||
}
|
||||
// self.taskComplete(ctx, guest)
|
||||
}
|
||||
|
||||
|
||||
@@ -125,6 +125,12 @@ func (self *InstanceSnapshotCreateTask) GuestDiskCreateSnapshot(
|
||||
return
|
||||
}
|
||||
|
||||
err = models.InstanceSnapshotJointManager.CreateJoint(isp.Id, snapshot.Id, int8(diskIndex))
|
||||
if err != nil {
|
||||
self.taskFail(ctx, isp, guest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("disk_index", jsonutils.NewInt(int64(diskIndex)))
|
||||
params.Set(strconv.Itoa(diskIndex), jsonutils.NewString(snapshot.Id))
|
||||
@@ -147,18 +153,6 @@ func (self *InstanceSnapshotCreateTask) OnDiskSnapshot(
|
||||
return
|
||||
}
|
||||
|
||||
snapshotId, err := self.Params.GetString(strconv.Itoa(int(diskIndex)))
|
||||
if err != nil {
|
||||
self.taskFail(ctx, isp, guest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err = models.InstanceSnapshotJointManager.CreateJoint(isp.Id, snapshotId, int8(diskIndex))
|
||||
if err != nil {
|
||||
self.taskFail(ctx, isp, guest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
self.GuestDiskCreateSnapshot(ctx, isp, guest, int(diskIndex+1))
|
||||
}
|
||||
|
||||
|
||||
@@ -452,6 +452,9 @@ func (m *SGuestManager) GetStatus(sid string) string {
|
||||
}
|
||||
}
|
||||
if guest.IsRunning() {
|
||||
if guest.BlockJobsCount() > 0 {
|
||||
return GUEST_BLOCK_STREAM
|
||||
}
|
||||
return GUEST_RUNNING
|
||||
} else if guest.IsSuspend() {
|
||||
return GUEST_SUSPEND
|
||||
|
||||
@@ -666,6 +666,22 @@ func (s *SKVMGuestInstance) MirrorJobStatus() MirrorJob {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) BlockJobsCount() int {
|
||||
res := make(chan *jsonutils.JSONArray)
|
||||
s.Monitor.GetBlockJobs(func(jobs *jsonutils.JSONArray) {
|
||||
res <- jobs
|
||||
})
|
||||
select {
|
||||
case <-time.After(time.Second * 3):
|
||||
return -1
|
||||
case v := <-res:
|
||||
if v != nil && v.Length() > 0 {
|
||||
return v.Length()
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) CleanStartupTask() {
|
||||
log.Infof("Clean startup task ...")
|
||||
if s.startupTask != nil {
|
||||
|
||||
@@ -294,6 +294,8 @@ func NewNIC(desc string) (*SNIC, error) {
|
||||
log.Infof("IP %s/%s/%s", nic.Ip, nic.Bridge, nic.Inter)
|
||||
// 这是干啥呢 ???
|
||||
if len(nic.Ip) > 0 {
|
||||
// waiting for interface assign ip
|
||||
// in case nic bonding is too slow
|
||||
var max, wait = 30, 0
|
||||
for wait < max {
|
||||
inf := netutils2.NewNetInterfaceWithExpectIp(nic.Inter, nic.Ip)
|
||||
|
||||
@@ -17,8 +17,10 @@ package storageman
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
@@ -95,6 +97,15 @@ func (d *SLocalDisk) UmountFuseImage() {
|
||||
mntPath := path.Join(d.Storage.GetFuseMountPath(), d.Id)
|
||||
procutils.NewCommand("umount", mntPath).Run()
|
||||
procutils.NewCommand("rm", "-rf", mntPath).Run()
|
||||
tmpPath := d.Storage.GetFuseTmpPath()
|
||||
tmpFiles, err := ioutil.ReadDir(tmpPath)
|
||||
if err != nil {
|
||||
for _, f := range tmpFiles {
|
||||
if strings.HasPrefix(f.Name(), d.Id) {
|
||||
procutils.NewCommand("rm", "-f", path.Join(tmpPath, f.Name()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *SLocalDisk) Delete(ctx context.Context, params interface{}) (jsonutils.JSONObject, error) {
|
||||
@@ -317,6 +328,15 @@ func (d *SLocalDisk) PostCreateFromImageFuse() {
|
||||
if _, err := procutils.NewCommand("rm", "-rf", mntPath).Run(); err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
tmpPath := d.Storage.GetFuseTmpPath()
|
||||
tmpFiles, err := ioutil.ReadDir(tmpPath)
|
||||
if err != nil {
|
||||
for _, f := range tmpFiles {
|
||||
if strings.HasPrefix(f.Name(), d.Id) {
|
||||
procutils.NewCommand("rm", "-f", path.Join(tmpPath, f.Name()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *SLocalDisk) CreateSnapshot(snapshotId string) error {
|
||||
|
||||
Reference in New Issue
Block a user