use of com.cloud.storage.GuestOSVO in project cloudstack by apache.
the class TemplateManagerImpl method prepareIsoForVmProfile.
@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);
}
}
use of com.cloud.storage.GuestOSVO in project cosmic by MissionCriticalCloud.
the class ManagementServerImpl method listGuestOSByCriteria.
@Override
public Pair<List<? extends GuestOS>, Integer> listGuestOSByCriteria(final ListGuestOsCmd cmd) {
final Filter searchFilter = new Filter(GuestOSVO.class, "displayName", true, cmd.getStartIndex(), cmd.getPageSizeVal());
final Long id = cmd.getId();
final Long osCategoryId = cmd.getOsCategoryId();
final String description = cmd.getDescription();
final String keyword = cmd.getKeyword();
final SearchCriteria<GuestOSVO> sc = _guestOSDao.createSearchCriteria();
if (id != null) {
sc.addAnd("id", SearchCriteria.Op.EQ, id);
}
if (osCategoryId != null) {
sc.addAnd("categoryId", SearchCriteria.Op.EQ, osCategoryId);
}
if (description != null) {
sc.addAnd("displayName", SearchCriteria.Op.LIKE, "%" + description + "%");
}
if (keyword != null) {
sc.addAnd("displayName", SearchCriteria.Op.LIKE, "%" + keyword + "%");
}
final Pair<List<GuestOSVO>, Integer> result = _guestOSDao.searchAndCount(sc, searchFilter);
return new Pair<>(result.first(), result.second());
}
use of com.cloud.storage.GuestOSVO in project cosmic by MissionCriticalCloud.
the class XenServerGuru method implement.
@Override
public VirtualMachineTO implement(final VirtualMachineProfile vm) {
BootloaderType bt = BootloaderType.PyGrub;
if (vm.getBootLoaderType() == BootloaderType.CD) {
bt = vm.getBootLoaderType();
}
final VirtualMachineTO to = toVirtualMachineTO(vm);
final UserVmVO userVmVO = _userVmDao.findById(vm.getId());
if (userVmVO != null) {
final HostVO host = hostDao.findById(userVmVO.getHostId());
if (host != null) {
to.setVcpuMaxLimit(MaxNumberOfVCPUSPerVM.valueIn(host.getClusterId()));
}
}
to.setBootloader(bt);
// Determine the VM's OS description
final GuestOSVO guestOS = _guestOsDao.findByIdIncludingRemoved(vm.getVirtualMachine().getGuestOSId());
to.setOs(guestOS.getDisplayName());
final HostVO host = hostDao.findById(vm.getVirtualMachine().getHostId());
GuestOSHypervisorVO guestOsMapping = null;
if (host != null) {
guestOsMapping = _guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), getHypervisorType().toString(), host.getHypervisorVersion());
}
if (guestOsMapping == null || host == null) {
to.setPlatformEmulator(null);
} else {
to.setPlatformEmulator(guestOsMapping.getGuestOsName());
}
return to;
}
use of com.cloud.storage.GuestOSVO in project cosmic by MissionCriticalCloud.
the class DefaultVMSnapshotStrategy method takeVMSnapshot.
@Override
public VMSnapshot takeVMSnapshot(final VMSnapshot vmSnapshot) {
final Long hostId = vmSnapshotHelper.pickRunningHost(vmSnapshot.getVmId());
final UserVm userVm = userVmDao.findById(vmSnapshot.getVmId());
final VMSnapshotVO vmSnapshotVO = (VMSnapshotVO) vmSnapshot;
try {
vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshotVO, VMSnapshot.Event.CreateRequested);
} catch (final NoTransitionException e) {
throw new CloudRuntimeException(e.getMessage());
}
CreateVMSnapshotAnswer answer = null;
boolean result = false;
try {
final GuestOSVO guestOS = guestOSDao.findById(userVm.getGuestOSId());
final List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(userVm.getId());
VMSnapshotTO current = null;
final VMSnapshotVO currentSnapshot = vmSnapshotDao.findCurrentSnapshotByVmId(userVm.getId());
if (currentSnapshot != null) {
current = vmSnapshotHelper.getSnapshotWithParents(currentSnapshot);
}
final VMSnapshotOptions options = ((VMSnapshotVO) vmSnapshot).getOptions();
boolean quiescevm = true;
if (options != null) {
quiescevm = options.needQuiesceVM();
}
final VMSnapshotTO target = new VMSnapshotTO(vmSnapshot.getId(), vmSnapshot.getName(), vmSnapshot.getType(), null, vmSnapshot.getDescription(), false, current, quiescevm);
if (current == null) {
vmSnapshotVO.setParent(null);
} else {
vmSnapshotVO.setParent(current.getId());
}
final HostVO host = hostDao.findById(hostId);
final GuestOSHypervisorVO guestOsMapping = guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), host.getHypervisorType().toString(), host.getHypervisorVersion());
final CreateVMSnapshotCommand ccmd = new CreateVMSnapshotCommand(userVm.getInstanceName(), userVm.getUuid(), target, volumeTOs, guestOS.getDisplayName());
if (guestOsMapping == null) {
ccmd.setPlatformEmulator(null);
} else {
ccmd.setPlatformEmulator(guestOsMapping.getGuestOsName());
}
ccmd.setWait(_wait);
answer = (CreateVMSnapshotAnswer) agentMgr.send(hostId, ccmd);
if (answer != null && answer.getResult()) {
processAnswer(vmSnapshotVO, userVm, answer, hostId);
s_logger.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName());
result = true;
return vmSnapshot;
} else {
String errMsg = "Creating VM snapshot: " + vmSnapshot.getName() + " failed";
if (answer != null && answer.getDetails() != null) {
errMsg = errMsg + " due to " + answer.getDetails();
}
s_logger.error(errMsg);
throw new CloudRuntimeException(errMsg);
}
} catch (final OperationTimedoutException e) {
s_logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString());
throw new CloudRuntimeException("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString());
} catch (final AgentUnavailableException e) {
s_logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed", e);
throw new CloudRuntimeException("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString());
} finally {
if (!result) {
try {
vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed);
} catch (final NoTransitionException e1) {
s_logger.error("Cannot set vm snapshot state due to: " + e1.getMessage());
}
}
}
}
use of com.cloud.storage.GuestOSVO in project cosmic by MissionCriticalCloud.
the class VMSnapshotStrategyTest method testCreateVMSnapshot.
@Test
public void testCreateVMSnapshot() throws AgentUnavailableException, OperationTimedoutException {
final Long hostId = 1L;
final Long vmId = 1L;
final Long guestOsId = 1L;
final HypervisorType hypervisorType = HypervisorType.Any;
final String hypervisorVersion = "default";
final String guestOsName = "Other";
final List<VolumeObjectTO> volumeObjectTOs = new ArrayList<>();
final VMSnapshotVO vmSnapshot = Mockito.mock(VMSnapshotVO.class);
final UserVmVO userVmVO = Mockito.mock(UserVmVO.class);
Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId);
Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId);
Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId);
Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs);
Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO);
final GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class);
Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO);
final GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class);
Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName);
Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO);
Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO);
Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null);
final HostVO hostVO = Mockito.mock(HostVO.class);
Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO);
Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType);
Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion);
Exception e = null;
try {
vmSnapshotStrategy.takeVMSnapshot(vmSnapshot);
} catch (final CloudRuntimeException e1) {
e = e1;
}
assertNotNull(e);
final CreateVMSnapshotAnswer answer = Mockito.mock(CreateVMSnapshotAnswer.class);
Mockito.when(answer.getResult()).thenReturn(true);
Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer);
Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot);
VMSnapshot snapshot = null;
snapshot = vmSnapshotStrategy.takeVMSnapshot(vmSnapshot);
assertNotNull(snapshot);
}
Aggregations