Search in sources :

Example 46 with GuestOSVO

use of com.cloud.storage.GuestOSVO in project cosmic by MissionCriticalCloud.

the class ConsoleProxyServlet method composeConsoleAccessUrl.

private String composeConsoleAccessUrl(final String rootUrl, final VirtualMachine vm, final HostVO hostVo) {
    final StringBuffer sb = new StringBuffer(rootUrl);
    final String host = hostVo.getPrivateIpAddress();
    final Pair<String, Integer> portInfo = _ms.getVncPort(vm);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Port info " + portInfo.first());
    }
    final Ternary<String, String, String> parsedHostInfo = parseHostInfo(portInfo.first());
    final int port = portInfo.second();
    final String sid = vm.getVncPassword();
    final UserVmDetailVO details = _userVmDetailsDao.findDetail(vm.getId(), "keyboard");
    final String tag = vm.getUuid();
    final String ticket = genAccessTicket(parsedHostInfo.first(), String.valueOf(port), sid, tag);
    final ConsoleProxyPasswordBasedEncryptor encryptor = new ConsoleProxyPasswordBasedEncryptor(getEncryptorPassword());
    final ConsoleProxyClientParam param = new ConsoleProxyClientParam();
    param.setClientHostAddress(parsedHostInfo.first());
    param.setClientHostPort(port);
    param.setClientHostPassword(sid);
    param.setClientTag(tag);
    param.setTicket(ticket);
    if (details != null) {
        param.setLocale(details.getValue());
    }
    if (portInfo.second() == -9) {
        param.setUsername(_ms.findDetail(hostVo.getId(), "username").getValue());
        param.setPassword(_ms.findDetail(hostVo.getId(), "password").getValue());
    }
    if (parsedHostInfo.second() != null && parsedHostInfo.third() != null) {
        param.setClientTunnelUrl(parsedHostInfo.second());
        param.setClientTunnelSession(parsedHostInfo.third());
    }
    sb.append("/ajax?token=" + encryptor.encryptObject(ConsoleProxyClientParam.class, param));
    // for console access, we need guest OS type to help implement keyboard
    final long guestOs = vm.getGuestOSId();
    final GuestOSVO guestOsVo = _ms.getGuestOs(guestOs);
    if (guestOsVo.getCategoryId() == 6) {
        sb.append("&guest=windows");
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Compose console url: " + sb.toString());
    }
    return sb.toString();
}
Also used : UserVmDetailVO(com.cloud.vm.UserVmDetailVO) GuestOSVO(com.cloud.storage.GuestOSVO)

Example 47 with GuestOSVO

use of com.cloud.storage.GuestOSVO in project cloudstack by apache.

the class LXCGuru method implement.

@Override
public VirtualMachineTO implement(VirtualMachineProfile vm) {
    VirtualMachineTO to = toVirtualMachineTO(vm);
    // Determine the VM's OS description
    GuestOSVO guestOS = _guestOsDao.findByIdIncludingRemoved(vm.getVirtualMachine().getGuestOSId());
    to.setOs(guestOS.getDisplayName());
    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("Other");
    } else {
        to.setPlatformEmulator(guestOsMapping.getGuestOsName());
    }
    return to;
}
Also used : GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) GuestOSVO(com.cloud.storage.GuestOSVO) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) HostVO(com.cloud.host.HostVO)

Example 48 with GuestOSVO

use of com.cloud.storage.GuestOSVO in project cloudstack by apache.

the class TemplateManagerImplTest method testCreatePrivateTemplateRecordForRegionStore.

@Test
public void testCreatePrivateTemplateRecordForRegionStore() throws ResourceAllocationException {
    CreateTemplateCmd mockCreateCmd = mock(CreateTemplateCmd.class);
    when(mockCreateCmd.getTemplateName()).thenReturn("test");
    when(mockCreateCmd.getTemplateTag()).thenReturn(null);
    when(mockCreateCmd.getBits()).thenReturn(64);
    when(mockCreateCmd.getRequiresHvm()).thenReturn(true);
    when(mockCreateCmd.isPasswordEnabled()).thenReturn(false);
    when(mockCreateCmd.isPublic()).thenReturn(false);
    when(mockCreateCmd.isFeatured()).thenReturn(false);
    when(mockCreateCmd.isDynamicallyScalable()).thenReturn(false);
    when(mockCreateCmd.getVolumeId()).thenReturn(null);
    when(mockCreateCmd.getSnapshotId()).thenReturn(1L);
    when(mockCreateCmd.getOsTypeId()).thenReturn(1L);
    when(mockCreateCmd.getEventDescription()).thenReturn("test");
    when(mockCreateCmd.getDetails()).thenReturn(null);
    Account mockTemplateOwner = mock(Account.class);
    SnapshotVO mockSnapshot = mock(SnapshotVO.class);
    when(snapshotDao.findById(anyLong())).thenReturn(mockSnapshot);
    when(mockSnapshot.getVolumeId()).thenReturn(1L);
    when(mockSnapshot.getState()).thenReturn(Snapshot.State.BackedUp);
    when(mockSnapshot.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.XenServer);
    doNothing().when(resourceLimitMgr).checkResourceLimit(any(Account.class), eq(Resource.ResourceType.template));
    doNothing().when(resourceLimitMgr).checkResourceLimit(any(Account.class), eq(Resource.ResourceType.secondary_storage), anyLong());
    GuestOSVO mockGuestOS = mock(GuestOSVO.class);
    when(guestOSDao.findById(anyLong())).thenReturn(mockGuestOS);
    when(tmpltDao.getNextInSequence(eq(Long.class), eq("id"))).thenReturn(1L);
    List<ImageStoreVO> mockRegionStores = new ArrayList<>();
    ImageStoreVO mockRegionStore = mock(ImageStoreVO.class);
    mockRegionStores.add(mockRegionStore);
    when(imgStoreDao.findRegionImageStores()).thenReturn(mockRegionStores);
    when(tmpltDao.persist(any(VMTemplateVO.class))).thenAnswer(new Answer<VMTemplateVO>() {

        @Override
        public VMTemplateVO answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            return (VMTemplateVO) args[0];
        }
    });
    VMTemplateVO template = templateManager.createPrivateTemplateRecord(mockCreateCmd, mockTemplateOwner);
    assertTrue("Template in a region store should have cross zones set", template.isCrossZones());
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) VMTemplateVO(com.cloud.storage.VMTemplateVO) GuestOSVO(com.cloud.storage.GuestOSVO) SnapshotVO(com.cloud.storage.SnapshotVO) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyLong(org.mockito.Matchers.anyLong) CreateTemplateCmd(org.apache.cloudstack.api.command.user.template.CreateTemplateCmd) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) Test(org.junit.Test)

Example 49 with GuestOSVO

use of com.cloud.storage.GuestOSVO in project cloudstack by apache.

the class Ovm3HypervisorGuru method implement.

@Override
public VirtualMachineTO implement(VirtualMachineProfile vm) {
    VirtualMachineTO to = toVirtualMachineTO(vm);
    to.setBootloader(vm.getBootLoaderType());
    GuestOSVO guestOS = guestOsDao.findById(vm.getVirtualMachine().getGuestOSId());
    to.setOs(guestOS.getDisplayName());
    return to;
}
Also used : GuestOSVO(com.cloud.storage.GuestOSVO) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO)

Example 50 with GuestOSVO

use of com.cloud.storage.GuestOSVO in project cloudstack by apache.

the class TemplateManagerImpl method prepareIsoForVmProfile.

@Override
public void prepareIsoForVmProfile(VirtualMachineProfile profile, DeployDestination dest) {
    UserVmVO vm = _userVmDao.findById(profile.getId());
    if (vm.getIsoId() != null) {
        Map<Volume, StoragePool> storageForDisks = dest.getStorageForDisks();
        Long poolId = null;
        TemplateInfo template;
        if (MapUtils.isNotEmpty(storageForDisks)) {
            for (StoragePool storagePool : storageForDisks.values()) {
                if (poolId != null && storagePool.getId() != poolId) {
                    throw new CloudRuntimeException("Cannot determine where to download iso");
                }
                poolId = storagePool.getId();
            }
        }
        template = prepareIso(vm.getIsoId(), vm.getDataCenterId(), dest.getHost().getId(), poolId);
        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.setDirectDownload(template.isDirectDownload());
        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);
    }
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) StoragePool(com.cloud.storage.StoragePool) Volume(com.cloud.storage.Volume) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) GuestOSVO(com.cloud.storage.GuestOSVO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) DiskTO(com.cloud.agent.api.to.DiskTO)

Aggregations

GuestOSVO (com.cloud.storage.GuestOSVO)62 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)26 GuestOSHypervisorVO (com.cloud.storage.GuestOSHypervisorVO)23 HostVO (com.cloud.host.HostVO)20 UserVmVO (com.cloud.vm.UserVmVO)20 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)17 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)17 VMSnapshotTO (com.cloud.agent.api.VMSnapshotTO)15 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)15 ArrayList (java.util.ArrayList)15 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)12 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)12 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)11 Test (org.junit.Test)11 Command (com.cloud.agent.api.Command)9 CreateVMSnapshotAnswer (com.cloud.agent.api.CreateVMSnapshotAnswer)9 IOException (java.io.IOException)9 HashMap (java.util.HashMap)9 RevertToVMSnapshotAnswer (com.cloud.agent.api.RevertToVMSnapshotAnswer)7 VMTemplateVO (com.cloud.storage.VMTemplateVO)7