mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-25 10:16:12 +08:00
import from libvirt link disk, do not move
This commit is contained in:
@@ -2075,6 +2075,10 @@ func (self *SGuest) PerformDiskSnapshot(ctx context.Context, userCred mcclient.T
|
||||
if !utils.IsInStringArray(self.Status, []string{api.VM_RUNNING, api.VM_READY}) {
|
||||
return nil, httperrors.NewInvalidStatusError("Cannot do snapshot when VM in status %s", self.Status)
|
||||
}
|
||||
if self.IsImport(userCred) {
|
||||
return nil, httperrors.NewBadRequestError("VM is import form libvirt, can't do snapshot")
|
||||
}
|
||||
|
||||
diskId, err := data.GetString("disk_id")
|
||||
if err != nil {
|
||||
return nil, httperrors.NewBadRequestError(err.Error())
|
||||
|
||||
@@ -4342,3 +4342,7 @@ func (self *SGuest) ToIsolatedDevicesConfig() []*api.IsolatedDeviceConfig {
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *SGuest) IsImport(userCred mcclient.TokenCredential) bool {
|
||||
return self.GetMetadata("__is_import", userCred) == "true"
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ func (self *HostImportLibvirtServersTask) StartImportServers(
|
||||
}
|
||||
|
||||
if success {
|
||||
guest.SetMetadata(ctx, "__is_import", "ture", self.UserCred)
|
||||
db.OpsLog.LogEvent(host, db.ACT_HOST_IMPORT_LIBVIRT_SERVERS, note, self.UserCred)
|
||||
} else {
|
||||
log.Errorln(note)
|
||||
|
||||
@@ -45,9 +45,10 @@ func (m *SGuestManager) GuestCreateFromLibvirt(
|
||||
}
|
||||
iDisk := storage.CreateDisk(diskId)
|
||||
|
||||
output, err := procutils.NewCommand("mv", diskPath, iDisk.GetPath()).Run()
|
||||
// use symbol link replace mv, more security
|
||||
output, err := procutils.NewCommand("ln", "-s", diskPath, iDisk.GetPath()).Run()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Mv disk from %s to %s error %s", diskPath, iDisk.GetPath(), output)
|
||||
return nil, fmt.Errorf("Symbol link disk from %s to %s error %s", diskPath, iDisk.GetPath(), output)
|
||||
}
|
||||
disksPath.Set(diskId, jsonutils.NewString(iDisk.GetPath()))
|
||||
}
|
||||
@@ -221,6 +222,9 @@ func (m *SGuestManager) LibvirtDomainDiskToDiskConfig(
|
||||
domainDisks []libvirtxml.DomainDisk) ([]compute.SImportDisk, error) {
|
||||
var diskConfigs = []compute.SImportDisk{}
|
||||
for _, disk := range domainDisks {
|
||||
if disk.Device != "disk" {
|
||||
continue
|
||||
}
|
||||
if disk.Source == nil || disk.Source.File == nil {
|
||||
return nil, fmt.Errorf("Domain disk missing source file ?")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user