mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
refactor attach/detach iso
This commit is contained in:
parent
63c3634b79
commit
7d6938ba2f
@ -55,6 +55,7 @@ import com.cloud.projects.ProjectService;
|
||||
import com.cloud.resource.ResourceService;
|
||||
import com.cloud.server.ManagementService;
|
||||
import com.cloud.server.TaggedResourceService;
|
||||
import com.cloud.storage.orchestra.StorageOrchestraEngine;
|
||||
import com.cloud.storage.pool.StoragePoolService;
|
||||
import com.cloud.storage.snapshot.SnapshotService;
|
||||
import com.cloud.template.TemplateService;
|
||||
@ -117,7 +118,6 @@ public abstract class BaseCmd {
|
||||
public static StoragePoolService _storageService;
|
||||
public static ResourceService _resourceService;
|
||||
public static NetworkService _networkService;
|
||||
public static TemplateService _templateService;
|
||||
public static SecurityGroupService _securityGroupService;
|
||||
public static SnapshotService _snapshotService;
|
||||
public static ConsoleProxyService _consoleProxyService;
|
||||
@ -138,6 +138,7 @@ public abstract class BaseCmd {
|
||||
public static VpcService _vpcService;
|
||||
public static NetworkACLService _networkACLService;
|
||||
public static Site2SiteVpnService _s2sVpnService;
|
||||
public static StorageOrchestraEngine _storageEngine;
|
||||
|
||||
static void setComponents(ResponseGenerator generator) {
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
|
||||
@ -148,7 +149,6 @@ public abstract class BaseCmd {
|
||||
_storageService = locator.getManager(StoragePoolService.class);
|
||||
_resourceService = locator.getManager(ResourceService.class);
|
||||
_networkService = locator.getManager(NetworkService.class);
|
||||
_templateService = locator.getManager(TemplateService.class);
|
||||
_securityGroupService = locator.getManager(SecurityGroupService.class);
|
||||
_snapshotService = locator.getManager(SnapshotService.class);
|
||||
_consoleProxyService = locator.getManager(ConsoleProxyService.class);
|
||||
@ -169,6 +169,7 @@ public abstract class BaseCmd {
|
||||
_vpcService = locator.getManager(VpcService.class);
|
||||
_networkACLService = locator.getManager(NetworkACLService.class);
|
||||
_s2sVpnService = locator.getManager(Site2SiteVpnService.class);
|
||||
_storageEngine = locator.getManager(StorageOrchestraEngine.class);
|
||||
}
|
||||
|
||||
public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException;
|
||||
|
||||
@ -95,7 +95,7 @@ public class AttachIsoCmd extends BaseAsyncCmd {
|
||||
@Override
|
||||
public void execute(){
|
||||
UserContext.current().setEventDetails("Vm Id: " +getVirtualMachineId()+ " ISO Id: "+getId());
|
||||
boolean result = _templateService.attachIso(id, virtualMachineId);
|
||||
boolean result = _storageEngine.attachIsoToVm(id, virtualMachineId);
|
||||
if (result) {
|
||||
UserVm userVm = _responseGenerator.findUserVmById(virtualMachineId);
|
||||
if (userVm != null) {
|
||||
|
||||
@ -35,4 +35,6 @@ public interface StorageOrchestraEngine {
|
||||
VolumeVO allocVolume(CreateVolumeCmd cmd)
|
||||
throws ResourceAllocationException;
|
||||
Volume attachVolumeToVM(AttachVolumeCmd command);
|
||||
boolean attachIsoToVm(long isoId, long vmId);
|
||||
boolean detachIsoToVm(long vmId);
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import javax.naming.ConfigurationException;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.AttachIsoCommand;
|
||||
import com.cloud.agent.api.AttachVolumeAnswer;
|
||||
import com.cloud.agent.api.AttachVolumeCommand;
|
||||
import com.cloud.agent.api.CreateVolumeFromSnapshotAnswer;
|
||||
@ -48,6 +49,7 @@ import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.org.Grouping;
|
||||
import com.cloud.resource.ResourceManager;
|
||||
@ -63,11 +65,13 @@ import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.dao.DiskOfferingDao;
|
||||
import com.cloud.storage.dao.SnapshotDao;
|
||||
import com.cloud.storage.dao.StoragePoolDao;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.storage.pool.Storage;
|
||||
import com.cloud.storage.pool.StoragePool;
|
||||
import com.cloud.storage.pool.Storage.ImageFormat;
|
||||
import com.cloud.storage.pool.Storage.StoragePoolType;
|
||||
import com.cloud.storage.pool.Storage.TemplateType;
|
||||
import com.cloud.storage.pool.StoragePoolManager;
|
||||
import com.cloud.storage.snapshot.Snapshot;
|
||||
import com.cloud.storage.snapshot.SnapshotManager;
|
||||
@ -83,6 +87,7 @@ import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.ResourceLimitService;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.Inject;
|
||||
@ -127,6 +132,8 @@ public class StorageOrchestraEngineImpl implements StorageOrchestraEngine, Manag
|
||||
protected UsageEventDao _usageEventDao;
|
||||
@Inject
|
||||
protected UserVmDao _userVmDao;
|
||||
@Inject
|
||||
protected VMTemplateDao _templateDao;
|
||||
|
||||
|
||||
|
||||
@ -530,5 +537,52 @@ public class StorageOrchestraEngineImpl implements StorageOrchestraEngine, Manag
|
||||
return _volumeMgr.attachVolumeToVM(volume, vm, deviceId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_ISO_ATTACH, eventDescription = "attaching ISO", async = true)
|
||||
public boolean attachIsoToVm(long isoId, long vmId) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
Long userId = UserContext.current().getCallerUserId();
|
||||
|
||||
UserVmVO vm = _userVmDao.findById(vmId);
|
||||
if (vm == null) {
|
||||
throw new InvalidParameterValueException("Unable to find a virtual machine with id " + vmId);
|
||||
}
|
||||
|
||||
VMTemplateVO iso = _templateDao.findById(isoId);
|
||||
if (iso == null || iso.getRemoved() != null) {
|
||||
throw new InvalidParameterValueException("Unable to find an ISO with id " + isoId);
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, null, false, iso, vm);
|
||||
|
||||
Account vmOwner = _accountDao.findById(vm.getAccountId());
|
||||
_accountMgr.checkAccess(vmOwner, null, false, iso, vm);
|
||||
|
||||
_volumeMgr.attachISOToVm(vm, iso);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_ISO_DETACH, eventDescription = "detaching ISO", async = true)
|
||||
public boolean detachIsoToVm(long vmId) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
Long userId = UserContext.current().getCallerUserId();
|
||||
|
||||
UserVmVO vm = _userVmDao.findById(vmId);
|
||||
if (vm == null) {
|
||||
throw new InvalidParameterValueException ("Unable to find a virtual machine with id " + vmId);
|
||||
}
|
||||
|
||||
Long isoId = vm.getIsoId();
|
||||
if (isoId == null) {
|
||||
throw new InvalidParameterValueException("The specified VM has no ISO attached to it.");
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, null, true, vm);
|
||||
UserContext.current().setEventDetails("Vm Id: " + vmId + " ISO Id: " + isoId);
|
||||
|
||||
_volumeMgr.detachISOToVM(vm);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1933,10 +1933,7 @@ public class StoragePoolManagerImpl implements StoragePoolManager, Manager, Clus
|
||||
}
|
||||
}
|
||||
|
||||
protected DiskProfile toDiskProfile(VolumeVO vol, DiskOfferingVO offering) {
|
||||
return new DiskProfile(vol.getId(), vol.getVolumeType(), vol.getName(), offering.getId(), vol.getSize(), offering.getTagsArray(), offering.getUseLocalStorage(), offering.isRecreatable(),
|
||||
vol.getTemplateId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@ -2288,12 +2285,4 @@ public class StoragePoolManagerImpl implements StoragePoolManager, Manager, Clus
|
||||
StoragePool pool = _storagePoolDao.findById(id);
|
||||
return pool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean PrepareTemplateOnPool(VMTemplateVO template, StoragePool pool) {
|
||||
|
||||
}
|
||||
|
||||
@O
|
||||
|
||||
}
|
||||
|
||||
@ -8,8 +8,10 @@ import com.cloud.api.commands.ListVolumesCmd;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientStorageCapacityException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
@ -31,13 +33,6 @@ import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
public interface VolumeManager {
|
||||
/** Returns the absolute path of the specified ISO
|
||||
* @param templateId - the ID of the template that represents the ISO
|
||||
* @param datacenterId
|
||||
* @return absolute ISO path
|
||||
*/
|
||||
public Pair<String, String> getAbsoluteIsoPath(long templateId, long dataCenterId);
|
||||
|
||||
/**
|
||||
* Moves a volume from its current storage pool to a storage pool with enough capacity in the specified zone, pod, or cluster
|
||||
* @param volume
|
||||
@ -102,9 +97,6 @@ public interface VolumeManager {
|
||||
List<Pair<DiskOfferingVO, Long>> dataDiskOfferings, Long templateId, Account owner);
|
||||
|
||||
void cleanupVolumes(long vmId) throws ConcurrentOperationException;
|
||||
boolean StorageMigration(
|
||||
VirtualMachineProfile<? extends VirtualMachine> vm,
|
||||
StoragePool destPool) throws ConcurrentOperationException;
|
||||
|
||||
boolean processEvent(Volume vol, Event event)
|
||||
throws NoTransitionException;
|
||||
@ -123,14 +115,6 @@ public interface VolumeManager {
|
||||
String getVmNameOnVolume(VolumeVO volume);
|
||||
void expungeVolume(VolumeVO vol, boolean force);
|
||||
|
||||
Volume migrateVolume(Long volumeId, Long storagePoolId)
|
||||
throws ConcurrentOperationException;
|
||||
|
||||
void prepare(VirtualMachineProfile<? extends VirtualMachine> vm,
|
||||
DeployDestination dest, boolean recreate)
|
||||
throws StorageUnavailableException,
|
||||
InsufficientStorageCapacityException;
|
||||
|
||||
Volume copyVolume(Long volumeId, Long destStoragePoolId);
|
||||
|
||||
List<VolumeVO> searchForVolumes(ListVolumesCmd cmd);
|
||||
@ -138,5 +122,11 @@ public interface VolumeManager {
|
||||
VolumeVO allocateDiskVolume(String volumeName, long zoneId, long ownerId,
|
||||
long domainId, long diskOfferingId, long size);
|
||||
|
||||
Volume attachVolumeToVM(VolumeVO volume, UserVmVO vm, Long deviceId);
|
||||
Volume attachVolumeToVM(VolumeVO volume, UserVmVO vm, Long deviceId) throws StorageUnavailableException, ConcurrentOperationException, AgentUnavailableException, OperationTimedoutException;
|
||||
|
||||
boolean deleteVolume(long volumeId) throws ConcurrentOperationException;
|
||||
|
||||
void attachISOToVm(UserVmVO vm, VMTemplateVO iso);
|
||||
|
||||
void detachISOToVM(UserVmVO vm);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -17,6 +17,7 @@
|
||||
package com.cloud.template;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.exception.InternalErrorException;
|
||||
@ -93,4 +94,8 @@ public interface TemplateManager extends TemplateService{
|
||||
|
||||
String prepareTemplateOnPool(VMTemplateVO template, StoragePool pool);
|
||||
|
||||
Map<String, String> getAbsoluteIsoPath(VMTemplateVO iso, long dataCenterId);
|
||||
|
||||
boolean isTemplateReady(VMTemplateVO template, long dataCenterId);
|
||||
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -88,6 +89,7 @@ import com.cloud.hypervisor.HypervisorGuruManager;
|
||||
import com.cloud.org.Grouping;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.projects.ProjectManager;
|
||||
import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.storage.LaunchPermissionVO;
|
||||
import com.cloud.storage.SnapshotVO;
|
||||
import com.cloud.storage.StoragePoolHostVO;
|
||||
@ -158,13 +160,14 @@ import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
import com.cloud.host.Host;
|
||||
|
||||
|
||||
@Local(value={TemplateManager.class, TemplateService.class})
|
||||
public class TemplateManagerImpl implements TemplateManager, Manager, TemplateService {
|
||||
private final static Logger s_logger = Logger.getLogger(TemplateManagerImpl.class);
|
||||
String _name;
|
||||
@Inject VMTemplateDao _tmpltDao;
|
||||
@Inject VMTemplateDao _templateDao;
|
||||
@Inject VMTemplateHostDao _tmpltHostDao;
|
||||
@Inject VMTemplatePoolDao _tmpltPoolDao;
|
||||
@Inject VMTemplateZoneDao _tmpltZoneDao;
|
||||
@ -205,6 +208,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
@Inject SecondaryStorageVmManager _ssvmMgr;
|
||||
@Inject LaunchPermissionDao _launchPermissionDao;
|
||||
@Inject ProjectManager _projectMgr;
|
||||
@Inject ResourceManager _resourceMgr;
|
||||
|
||||
|
||||
int _primaryStorageDownloadWait;
|
||||
@ -310,7 +314,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
@Override
|
||||
public VirtualMachineTemplate prepareTemplate(long templateId, long zoneId) {
|
||||
|
||||
VMTemplateVO vmTemplate = _tmpltDao.findById(templateId);
|
||||
VMTemplateVO vmTemplate = _templateDao.findById(templateId);
|
||||
if(vmTemplate == null)
|
||||
throw new InvalidParameterValueException("Unable to find template id=" + templateId);
|
||||
|
||||
@ -331,7 +335,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
throw new PermissionDeniedException("Extraction has been disabled by admin");
|
||||
}
|
||||
|
||||
VMTemplateVO template = _tmpltDao.findById(templateId);
|
||||
VMTemplateVO template = _templateDao.findById(templateId);
|
||||
if (template == null || template.getRemoved() != null) {
|
||||
throw new InvalidParameterValueException("Unable to find " +desc+ " with id " + templateId);
|
||||
}
|
||||
@ -466,7 +470,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
}
|
||||
|
||||
String downloadTemplateFromSwiftToSecondaryStorage(long dcId, long templateId){
|
||||
VMTemplateVO template = _tmpltDao.findById(templateId);
|
||||
VMTemplateVO template = _templateDao.findById(templateId);
|
||||
if ( template == null ) {
|
||||
String errMsg = " Can not find template " + templateId;
|
||||
s_logger.warn(errMsg);
|
||||
@ -516,7 +520,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
|
||||
String uploadTemplateToSwiftFromSecondaryStorage(VMTemplateHostVO templateHostRef) {
|
||||
Long templateId = templateHostRef.getTemplateId();
|
||||
VMTemplateVO template = _tmpltDao.findById(templateId);
|
||||
VMTemplateVO template = _templateDao.findById(templateId);
|
||||
if (template == null) {
|
||||
String errMsg = " Can not find template " + templateId;
|
||||
s_logger.warn(errMsg);
|
||||
@ -570,7 +574,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
|
||||
@Override @DB
|
||||
public VMTemplateStoragePoolVO prepareTemplateForCreate(VMTemplateVO template, StoragePool pool) {
|
||||
template = _tmpltDao.findById(template.getId(), true);
|
||||
template = _templateDao.findById(template.getId(), true);
|
||||
|
||||
long poolId = pool.getId();
|
||||
long templateId = template.getId();
|
||||
@ -698,7 +702,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
@Override
|
||||
@DB
|
||||
public VMTemplateHostVO prepareISOForCreate(VMTemplateVO template, StoragePool pool) {
|
||||
template = _tmpltDao.findById(template.getId(), true);
|
||||
template = _templateDao.findById(template.getId(), true);
|
||||
|
||||
long poolId = pool.getId();
|
||||
long templateId = template.getId();
|
||||
@ -806,7 +810,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
}
|
||||
|
||||
if(_downloadMonitor.copyTemplate(template, srcSecHost, dstSecHost) ) {
|
||||
_tmpltDao.addTemplateToZone(template, dstZoneId);
|
||||
_templateDao.addTemplateToZone(template, dstZoneId);
|
||||
|
||||
if(account.getId() != Account.ACCOUNT_ID_SYSTEM){
|
||||
UsageEventVO usageEvent = new UsageEventVO(copyEventType, account.getId(), dstZoneId, tmpltId, null, null, null, srcTmpltHost.getSize());
|
||||
@ -846,7 +850,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
throw new InvalidParameterValueException("Please specify a valid destination zone.");
|
||||
}
|
||||
|
||||
VMTemplateVO template = _tmpltDao.findById(templateId);
|
||||
VMTemplateVO template = _templateDao.findById(templateId);
|
||||
if (template == null || template.getRemoved() != null) {
|
||||
throw new InvalidParameterValueException("Unable to find template with id");
|
||||
}
|
||||
@ -875,7 +879,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
|
||||
@Override
|
||||
public boolean delete(long userId, long templateId, Long zoneId) {
|
||||
VMTemplateVO template = _tmpltDao.findById(templateId);
|
||||
VMTemplateVO template = _templateDao.findById(templateId);
|
||||
if (template == null || template.getRemoved() != null) {
|
||||
throw new InvalidParameterValueException("Please specify a valid template.");
|
||||
}
|
||||
@ -890,7 +894,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
List<VMTemplateStoragePoolVO> allTemplatesInPool = _tmpltPoolDao.listByPoolId(pool.getId());
|
||||
|
||||
for (VMTemplateStoragePoolVO templatePoolVO : allTemplatesInPool) {
|
||||
VMTemplateVO template = _tmpltDao.findByIdIncludingRemoved(templatePoolVO.getTemplateId());
|
||||
VMTemplateVO template = _templateDao.findByIdIncludingRemoved(templatePoolVO.getTemplateId());
|
||||
|
||||
// If this is a routing template, consider it in use
|
||||
if (template.getTemplateType() == TemplateType.SYSTEM) {
|
||||
@ -913,7 +917,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
@Override
|
||||
public void evictTemplateFromStoragePool(VMTemplateStoragePoolVO templatePoolVO) {
|
||||
StoragePoolVO pool = _poolDao.findById(templatePoolVO.getPoolId());
|
||||
VMTemplateVO template = _tmpltDao.findByIdIncludingRemoved(templatePoolVO.getTemplateId());
|
||||
VMTemplateVO template = _templateDao.findByIdIncludingRemoved(templatePoolVO.getTemplateId());
|
||||
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
@ -945,7 +949,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
return;
|
||||
}
|
||||
List<HypervisorType> hypers = _clusterDao.getAvailableHypervisorInZone(null);
|
||||
List<VMTemplateVO> templates = _tmpltDao.listByHypervisorType(hypers);
|
||||
List<VMTemplateVO> templates = _templateDao.listByHypervisorType(hypers);
|
||||
List<Long> templateIds = new ArrayList<Long>();
|
||||
for (VMTemplateVO template : templates) {
|
||||
if (template.getTemplateType() != TemplateType.PERHOST) {
|
||||
@ -1057,7 +1061,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
|
||||
@Override
|
||||
public boolean templateIsDeleteable(VMTemplateHostVO templateHostRef) {
|
||||
VMTemplateVO template = _tmpltDao.findByIdIncludingRemoved(templateHostRef.getTemplateId());
|
||||
VMTemplateVO template = _templateDao.findByIdIncludingRemoved(templateHostRef.getTemplateId());
|
||||
long templateId = template.getId();
|
||||
HostVO secondaryStorageHost = _hostDao.findById(templateHostRef.getHostId());
|
||||
long zoneId = secondaryStorageHost.getDataCenterId();
|
||||
@ -1083,105 +1087,34 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_ISO_DETACH, eventDescription = "detaching ISO", async = true)
|
||||
public boolean detachIso(long vmId) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
Long userId = UserContext.current().getCallerUserId();
|
||||
|
||||
// Verify input parameters
|
||||
UserVmVO vmInstanceCheck = _userVmDao.findById(vmId);
|
||||
if (vmInstanceCheck == null) {
|
||||
throw new InvalidParameterValueException ("Unable to find a virtual machine with id " + vmId);
|
||||
}
|
||||
|
||||
UserVm userVM = _userVmDao.findById(vmId);
|
||||
if (userVM == null) {
|
||||
throw new InvalidParameterValueException("Please specify a valid VM.");
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, null, true, userVM);
|
||||
|
||||
Long isoId = userVM.getIsoId();
|
||||
if (isoId == null) {
|
||||
throw new InvalidParameterValueException("The specified VM has no ISO attached to it.");
|
||||
}
|
||||
UserContext.current().setEventDetails("Vm Id: " +vmId+ " ISO Id: "+isoId);
|
||||
|
||||
State vmState = userVM.getState();
|
||||
if (vmState != State.Running && vmState != State.Stopped) {
|
||||
throw new InvalidParameterValueException("Please specify a VM that is either Stopped or Running.");
|
||||
}
|
||||
|
||||
boolean result = attachISOToVM(vmId, userId, isoId, false); //attach=false => detach
|
||||
if (result){
|
||||
return result;
|
||||
}else {
|
||||
throw new CloudRuntimeException("Failed to detach iso");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_ISO_ATTACH, eventDescription = "attaching ISO", async = true)
|
||||
public boolean attachIso(long isoId, long vmId) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
Long userId = UserContext.current().getCallerUserId();
|
||||
|
||||
// Verify input parameters
|
||||
UserVmVO vm = _userVmDao.findById(vmId);
|
||||
if (vm == null) {
|
||||
throw new InvalidParameterValueException("Unable to find a virtual machine with id " + vmId);
|
||||
}
|
||||
|
||||
VMTemplateVO iso = _tmpltDao.findById(isoId);
|
||||
if (iso == null || iso.getRemoved() != null) {
|
||||
throw new InvalidParameterValueException("Unable to find an ISO with id " + isoId);
|
||||
}
|
||||
|
||||
//check permissions
|
||||
//check if caller has access to VM and ISO
|
||||
//and also check if the VM's owner has access to the ISO.
|
||||
|
||||
_accountMgr.checkAccess(caller, null, false, iso, vm);
|
||||
|
||||
Account vmOwner = _accountDao.findById(vm.getAccountId());
|
||||
_accountMgr.checkAccess(vmOwner, null, false, iso, vm);
|
||||
|
||||
State vmState = vm.getState();
|
||||
if (vmState != State.Running && vmState != State.Stopped) {
|
||||
throw new InvalidParameterValueException("Please specify a VM that is either Stopped or Running.");
|
||||
}
|
||||
|
||||
if ("xen-pv-drv-iso".equals(iso.getDisplayText()) && vm.getHypervisorType() != Hypervisor.HypervisorType.XenServer){
|
||||
throw new InvalidParameterValueException("Cannot attach Xenserver PV drivers to incompatible hypervisor " + vm.getHypervisorType());
|
||||
}
|
||||
|
||||
if("vmware-tools.iso".equals(iso.getName()) && vm.getHypervisorType() != Hypervisor.HypervisorType.VMware) {
|
||||
throw new InvalidParameterValueException("Cannot attach VMware tools drivers to incompatible hypervisor " + vm.getHypervisorType());
|
||||
}
|
||||
boolean result = attachISOToVM(vmId, userId, isoId, true);
|
||||
if (result){
|
||||
return result;
|
||||
}else {
|
||||
throw new CloudRuntimeException("Failed to attach iso");
|
||||
}
|
||||
public boolean isTemplateReady(VMTemplateVO template, long dataCenterId) {
|
||||
if (template.getTemplateType() == TemplateType.PERHOST) {
|
||||
return true;
|
||||
}
|
||||
List<VMTemplateHostVO> templateHosts = _tmpltHostDao.listByZoneTemplate(dataCenterId, template.getId(), true);
|
||||
return (templateHosts.size() > 0) ? true : false;
|
||||
}
|
||||
|
||||
private boolean attachISOToVM(long vmId, long userId, long isoId, boolean attach) {
|
||||
UserVmVO vm = _userVmDao.findById(vmId);
|
||||
VMTemplateVO iso = _tmpltDao.findById(isoId);
|
||||
@Override
|
||||
public Map<String, String> getAbsoluteIsoPath(VMTemplateVO iso, long dataCenterId) {
|
||||
Map<String, String> paths = new HashMap<String, String>();
|
||||
|
||||
boolean success = _vmMgr.attachISOToVM(vmId, isoId, attach);
|
||||
if ( success && attach) {
|
||||
vm.setIsoId(iso.getId());
|
||||
_userVmDao.update(vmId, vm);
|
||||
}
|
||||
if ( success && !attach ) {
|
||||
vm.setIsoId(null);
|
||||
_userVmDao.update(vmId, vm);
|
||||
}
|
||||
return success;
|
||||
//for pv driver iso
|
||||
if (iso.getTemplateType() == TemplateType.PERHOST) {
|
||||
paths.put("isoPath", iso.getName());
|
||||
} else {
|
||||
List<VMTemplateHostVO> templateHosts = _tmpltHostDao.listByZoneTemplate(dataCenterId, iso.getId(), true);
|
||||
if (templateHosts.size() > 0) {
|
||||
VMTemplateHostVO templateHost = templateHosts.get(0);
|
||||
HostVO storageHost = _hostDao.findById(templateHost.getHostId());
|
||||
String isoPath = storageHost.getStorageUrl() + "/" + templateHost.getInstallPath();
|
||||
paths.put("isoPath", isoPath);
|
||||
paths.put("secPath", storageHost.getStorageUrl());
|
||||
}
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1265,7 +1198,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
|
||||
@Override
|
||||
public VirtualMachineTemplate getTemplate(long templateId) {
|
||||
VMTemplateVO template = _tmpltDao.findById(templateId);
|
||||
VMTemplateVO template = _templateDao.findById(templateId);
|
||||
if (template != null && template.getRemoved() == null) {
|
||||
return template;
|
||||
}
|
||||
@ -1328,7 +1261,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
String operation = cmd.getOperation();
|
||||
String mediaType = "";
|
||||
|
||||
VMTemplateVO template = _tmpltDao.findById(id);
|
||||
VMTemplateVO template = _templateDao.findById(id);
|
||||
|
||||
if (template == null) {
|
||||
throw new InvalidParameterValueException("unable to find " + mediaType + " with id " + id);
|
||||
@ -1394,7 +1327,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
throw new InvalidParameterValueException("Update template permissions is an invalid operation on template " + template.getName());
|
||||
}
|
||||
|
||||
VMTemplateVO updatedTemplate = _tmpltDao.createForUpdate();
|
||||
VMTemplateVO updatedTemplate = _templateDao.createForUpdate();
|
||||
|
||||
if (isPublic != null) {
|
||||
updatedTemplate.setPublicTemplate(isPublic.booleanValue());
|
||||
@ -1410,7 +1343,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
throw new InvalidParameterValueException("Only ROOT admins are allowed to modify this attribute.");
|
||||
}
|
||||
|
||||
_tmpltDao.update(template.getId(), updatedTemplate);
|
||||
_templateDao.update(template.getId(), updatedTemplate);
|
||||
|
||||
Long domainId = caller.getDomainId();
|
||||
if ("add".equalsIgnoreCase(operation)) {
|
||||
@ -1445,10 +1378,10 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
} else if ("reset".equalsIgnoreCase(operation)) {
|
||||
// do we care whether the owning account is an admin? if the
|
||||
// owner is an admin, will we still set public to false?
|
||||
updatedTemplate = _tmpltDao.createForUpdate();
|
||||
updatedTemplate = _templateDao.createForUpdate();
|
||||
updatedTemplate.setPublicTemplate(false);
|
||||
updatedTemplate.setFeatured(false);
|
||||
_tmpltDao.update(template.getId(), updatedTemplate);
|
||||
_templateDao.update(template.getId(), updatedTemplate);
|
||||
_launchPermissionDao.removeAllPermissions(id);
|
||||
}
|
||||
return true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user