Mount secondary storage as a datastore to implement ISO attachment

This commit is contained in:
Kelven Yang 2010-09-15 10:43:30 -07:00 committed by edison
parent f81491d5bd
commit 72e8b767fe
5 changed files with 24 additions and 10 deletions

View File

@ -21,6 +21,7 @@ package com.cloud.agent.api;
public class AttachIsoCommand extends Command {
private String vmName;
private String storeUrl;
private String isoPath;
private boolean attach;
@ -49,4 +50,12 @@ public class AttachIsoCommand extends Command {
public boolean isAttach() {
return attach;
}
public String getStoreUrl() {
return storeUrl;
}
public void setStoreUrl(String url) {
storeUrl = url;
}
}

View File

@ -138,7 +138,7 @@ public interface StorageManager extends Manager {
* @param datacenterId
* @return absolute ISO path
*/
public String getAbsoluteIsoPath(long templateId, long dataCenterId);
public Pair<String, String> getAbsoluteIsoPath(long templateId, long dataCenterId);
/**
* Returns the URL of the secondary storage host

View File

@ -2399,10 +2399,11 @@ public class ManagementServerImpl implements ManagementServer {
UserVmVO started = null;
if (isIso)
{
String isoPath = _storageMgr.getAbsoluteIsoPath(templateId, dataCenterId);
Pair<String, String> isoPath = _storageMgr.getAbsoluteIsoPath(templateId, dataCenterId);
assert(isoPath != null);
try
{
started = _vmMgr.startVirtualMachine(userId, created.getId(), password, isoPath, startEventId);
started = _vmMgr.startVirtualMachine(userId, created.getId(), password, isoPath.first(), startEventId);
}
catch (ExecutionException e)
{

View File

@ -1174,8 +1174,7 @@ public class StorageManagerImpl implements StorageManager {
return null;
}
@Override
public String getAbsoluteIsoPath(long templateId, long dataCenterId) {
public Pair<String, String> getAbsoluteIsoPath(long templateId, long dataCenterId) {
String isoPath = null;
List<HostVO> storageHosts = _hostDao.listBy(Host.Type.SecondaryStorage, dataCenterId);
@ -1184,12 +1183,12 @@ public class StorageManagerImpl implements StorageManager {
VMTemplateHostVO templateHostVO = _vmTemplateHostDao.findByHostTemplate(storageHost.getId(), templateId);
if (templateHostVO != null) {
isoPath = storageHost.getStorageUrl() + "/" + templateHostVO.getInstallPath();
break;
return new Pair<String, String>(isoPath, storageHost.getStorageUrl());
}
}
}
return isoPath;
return null;
}
@Override

View File

@ -527,15 +527,18 @@ public class UserVmManagerImpl implements UserVmManager {
}
// Get the path of the ISO
String isoPath = _storageMgr.getAbsoluteIsoPath(isoId, vm.getDataCenterId());
Pair<String, String> isoPathPair = _storageMgr.getAbsoluteIsoPath(isoId, vm.getDataCenterId());
String isoPath;
String isoName = _templateDao.findById(isoId).getName();
if (isoPath == null) {
if (isoPathPair == null) {
// we can't send a null path to the ServerResource, so return false if we are unable to find the isoPath
if (isoName.startsWith("xs-tools"))
isoPath = isoName;
else
return false;
} else {
isoPath = isoPathPair.first();
}
String vmName = vm.getInstanceName();
@ -545,6 +548,8 @@ public class UserVmManagerImpl implements UserVmManager {
return false;
AttachIsoCommand cmd = new AttachIsoCommand(vmName, isoPath, attach);
if(isoPathPair != null)
cmd.setStoreUrl(isoPathPair.second());
Answer a = _agentMgr.easySend(vm.getHostId(), cmd);
return (a != null);
}
@ -670,7 +675,7 @@ public class UserVmManagerImpl implements UserVmManager {
} else {
Long isoId = vm.getIsoId();
if (isoId != null) {
isoPath = _storageMgr.getAbsoluteIsoPath(isoId, vm.getDataCenterId());
isoPath = _storageMgr.getAbsoluteIsoPath(isoId, vm.getDataCenterId()).first();
}
}