mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-6103: Pass VM iso information along with
PrepareForMigrationCommand, so that destination hypervisor can mount pool. This further exposed an issue for KVM where iso was not getting cleaned up upon successful migration, fixed as well.
This commit is contained in:
parent
433a2e44b1
commit
bb01aad377
|
|
@ -2909,6 +2909,7 @@ ServerResource {
|
|||
}
|
||||
|
||||
List<InterfaceDef> ifaces = null;
|
||||
List<DiskDef> disks = null;
|
||||
|
||||
Domain dm = null;
|
||||
Connect dconn = null;
|
||||
|
|
@ -2917,6 +2918,7 @@ ServerResource {
|
|||
try {
|
||||
conn = LibvirtConnection.getConnectionByVmName(cmd.getVmName());
|
||||
ifaces = getInterfaces(conn, vmName);
|
||||
disks = getDisks(conn, vmName);
|
||||
dm = conn.domainLookupByName(vmName);
|
||||
dconn = new Connect("qemu+tcp://" + cmd.getDestinationIp()
|
||||
+ "/system");
|
||||
|
|
@ -2926,6 +2928,12 @@ ServerResource {
|
|||
*/
|
||||
destDomain = dm.migrate(dconn, (1 << 0) | (1 << 3), vmName, "tcp:"
|
||||
+ cmd.getDestinationIp(), _migrateSpeed);
|
||||
for (DiskDef disk : disks) {
|
||||
if (disk.getDeviceType() == DiskDef.deviceType.CDROM
|
||||
&& disk.getDiskPath() != null) {
|
||||
cleanupDisk(conn, disk);
|
||||
}
|
||||
}
|
||||
} catch (LibvirtException e) {
|
||||
s_logger.debug("Can't migrate domain: " + e.getMessage());
|
||||
result = e.getMessage();
|
||||
|
|
|
|||
|
|
@ -2410,10 +2410,12 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
|||
vm.addDisk(disk);
|
||||
}
|
||||
|
||||
if (vm.getType() == VirtualMachine.Type.User && vm.getTemplate().getFormat() == ImageFormat.ISO) {
|
||||
DataTO dataTO = tmplFactory.getTemplate(vm.getTemplate().getId(), DataStoreRole.Image, vm.getVirtualMachine().getDataCenterId()).getTO();
|
||||
DiskTO iso = new DiskTO(dataTO, 3L, null, Volume.Type.ISO);
|
||||
vm.addDisk(iso);
|
||||
//if (vm.getType() == VirtualMachine.Type.User && vm.getTemplate().getFormat() == ImageFormat.ISO) {
|
||||
if (vm.getType() == VirtualMachine.Type.User) {
|
||||
_tmpltMgr.prepareIsoForVmProfile(vm);
|
||||
//DataTO dataTO = tmplFactory.getTemplate(vm.getTemplate().getId(), DataStoreRole.Image, vm.getVirtualMachine().getDataCenterId()).getTO();
|
||||
//DiskTO iso = new DiskTO(dataTO, 3L, null, Volume.Type.ISO);
|
||||
//vm.addDisk(iso);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import com.cloud.storage.VMTemplateHostVO;
|
|||
import com.cloud.storage.VMTemplateStoragePoolVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
/**
|
||||
* TemplateManager manages the templates stored on secondary storage. It is responsible for creating private/public templates.
|
||||
|
|
@ -112,6 +113,12 @@ public interface TemplateManager extends TemplateApiService{
|
|||
TemplateInfo prepareIso(long isoId, long dcId);
|
||||
|
||||
|
||||
/**
|
||||
* Adds ISO definition to given vm profile
|
||||
*
|
||||
* @param VirtualMachineProfile
|
||||
*/
|
||||
void prepareIsoForVmProfile(VirtualMachineProfile profile);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
|||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
|
||||
import org.apache.cloudstack.storage.to.TemplateObjectTO;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
@ -156,6 +157,7 @@ import com.cloud.storage.download.DownloadMonitor;
|
|||
import com.cloud.storage.secondary.SecondaryStorageVmManager;
|
||||
import com.cloud.storage.upload.UploadMonitor;
|
||||
import com.cloud.template.TemplateAdapter.TemplateAdapterType;
|
||||
import com.cloud.template.VirtualMachineTemplate.BootloaderType;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountService;
|
||||
|
|
@ -181,6 +183,7 @@ import com.cloud.vm.UserVmManager;
|
|||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.UserVmDetailsDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
|
@ -498,6 +501,38 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||
return extractUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareIsoForVmProfile(VirtualMachineProfile profile) {
|
||||
UserVmVO vm = _userVmDao.findById(profile.getId());
|
||||
if (vm.getIsoId() != null) {
|
||||
TemplateInfo template = prepareIso(vm.getIsoId(), vm.getDataCenterId());
|
||||
if (template == null){
|
||||
s_logger.error("Failed to prepare ISO on secondary or cache storage");
|
||||
throw new CloudRuntimeException("Failed to prepare ISO on secondary or cache storage");
|
||||
}
|
||||
if (template.isBootable()) {
|
||||
profile.setBootLoaderType(BootloaderType.CD);
|
||||
}
|
||||
|
||||
GuestOSVO guestOS = _guestOSDao.findById(template.getGuestOSId());
|
||||
String displayName = null;
|
||||
if (guestOS != null) {
|
||||
displayName = guestOS.getDisplayName();
|
||||
}
|
||||
|
||||
TemplateObjectTO iso = (TemplateObjectTO)template.getTO();
|
||||
iso.setGuestOsType(displayName);
|
||||
DiskTO disk = new DiskTO(iso, 3L, null, Volume.Type.ISO);
|
||||
profile.addDisk(disk);
|
||||
} else {
|
||||
TemplateObjectTO iso = new TemplateObjectTO();
|
||||
iso.setFormat(ImageFormat.ISO);
|
||||
DiskTO disk = new DiskTO(iso, 3L, null, Volume.Type.ISO);
|
||||
profile.addDisk(disk);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void prepareTemplateInAllStoragePools(final VMTemplateVO template, long zoneId) {
|
||||
List<StoragePoolVO> pools = _poolDao.listByStatus(StoragePoolStatus.Up);
|
||||
for (final StoragePoolVO pool : pools) {
|
||||
|
|
|
|||
|
|
@ -402,7 +402,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
|
|||
@Inject
|
||||
VpcManager _vpcMgr;
|
||||
@Inject
|
||||
TemplateManager templateMgr;
|
||||
TemplateManager _templateMgr;
|
||||
@Inject
|
||||
protected GuestOSCategoryDao _guestOSCategoryDao;
|
||||
@Inject
|
||||
|
|
@ -3023,34 +3023,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
|
|||
UserVmVO vm = profile.getVirtualMachine();
|
||||
Map<String, String> details = _vmDetailsDao.findDetails(vm.getId());
|
||||
vm.setDetails(details);
|
||||
|
||||
if (vm.getIsoId() != null) {
|
||||
TemplateInfo template = this.templateMgr.prepareIso(vm.getIsoId(), vm.getDataCenterId());
|
||||
if (template == null){
|
||||
s_logger.error("Failed to prepare ISO on secondary or cache storage");
|
||||
throw new CloudRuntimeException("Failed to prepare ISO on secondary or cache storage");
|
||||
}
|
||||
if (template.isBootable()) {
|
||||
profile.setBootLoaderType(BootloaderType.CD);
|
||||
}
|
||||
|
||||
GuestOSVO guestOS = _guestOSDao.findById(template.getGuestOSId());
|
||||
String displayName = null;
|
||||
if (guestOS != null) {
|
||||
displayName = guestOS.getDisplayName();
|
||||
}
|
||||
|
||||
TemplateObjectTO iso = (TemplateObjectTO)template.getTO();
|
||||
iso.setGuestOsType(displayName);
|
||||
DiskTO disk = new DiskTO(iso, 3L, null, Volume.Type.ISO);
|
||||
profile.addDisk(disk);
|
||||
} else {
|
||||
TemplateObjectTO iso = new TemplateObjectTO();
|
||||
iso.setFormat(ImageFormat.ISO);
|
||||
DiskTO disk = new DiskTO(iso, 3L, null, Volume.Type.ISO);
|
||||
profile.addDisk(disk);
|
||||
}
|
||||
|
||||
_templateMgr.prepareIsoForVmProfile(profile);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue