Search in sources :

Example 16 with GuestOSVO

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

the class BareMetalGuru method implement.

@Override
public VirtualMachineTO implement(VirtualMachineProfile vm) {
    VirtualMachineTO to = toVirtualMachineTO(vm);
    VMInstanceVO vo = _vmDao.findById(vm.getId());
    if (vo.getLastHostId() == null) {
        to.setBootArgs(BaremetalManager.DO_PXE);
    }
    Map<String, String> details = new HashMap<String, String>();
    details.put("template", vm.getTemplate().getUrl());
    to.setDetails(details);
    // Determine the VM's OS description
    GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId());
    to.setOs(guestOS.getDisplayName());
    return to;
}
Also used : HashMap(java.util.HashMap) VMInstanceVO(com.cloud.vm.VMInstanceVO) GuestOSVO(com.cloud.storage.GuestOSVO) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO)

Example 17 with GuestOSVO

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

the class KVMGuru 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 18 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 19 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 20 with GuestOSVO

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

the class VMwareGuru method implement.

@Override
public VirtualMachineTO implement(VirtualMachineProfile vm) {
    VirtualMachineTO to = toVirtualMachineTO(vm);
    to.setBootloader(BootloaderType.HVM);
    Map<String, String> details = to.getDetails();
    if (details == null)
        details = new HashMap<String, String>();
    Type vmType = vm.getType();
    boolean userVm = !(vmType.equals(VirtualMachine.Type.DomainRouter) || vmType.equals(VirtualMachine.Type.ConsoleProxy) || vmType.equals(VirtualMachine.Type.SecondaryStorageVm));
    String nicDeviceType = details.get(VmDetailConstants.NIC_ADAPTER);
    if (!userVm) {
        if (nicDeviceType == null) {
            details.put(VmDetailConstants.NIC_ADAPTER, _vmwareMgr.getSystemVMDefaultNicAdapterType());
        } else {
            try {
                VirtualEthernetCardType.valueOf(nicDeviceType);
            } catch (Exception e) {
                s_logger.warn("Invalid NIC device type " + nicDeviceType + " is specified in VM details, switch to default E1000");
                details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString());
            }
        }
    } else {
        // for user-VM, use E1000 as default
        if (nicDeviceType == null) {
            details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString());
        } else {
            try {
                VirtualEthernetCardType.valueOf(nicDeviceType);
            } catch (Exception e) {
                s_logger.warn("Invalid NIC device type " + nicDeviceType + " is specified in VM details, switch to default E1000");
                details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString());
            }
        }
    }
    String diskDeviceType = details.get(VmDetailConstants.ROOT_DISK_CONTROLLER);
    if (userVm) {
        if (diskDeviceType == null) {
            details.put(VmDetailConstants.ROOT_DISK_CONTROLLER, _vmwareMgr.getRootDiskController());
        }
    }
    String diskController = details.get(VmDetailConstants.DATA_DISK_CONTROLLER);
    if (userVm) {
        if (diskController == null) {
            details.put(VmDetailConstants.DATA_DISK_CONTROLLER, DiskControllerType.lsilogic.toString());
        }
    }
    List<NicProfile> nicProfiles = vm.getNics();
    for (NicProfile nicProfile : nicProfiles) {
        if (nicProfile.getTrafficType() == TrafficType.Guest) {
            if (_networkMgr.isProviderSupportServiceInNetwork(nicProfile.getNetworkId(), Service.Firewall, Provider.CiscoVnmc)) {
                details.put("ConfigureVServiceInNexus", Boolean.TRUE.toString());
            }
            break;
        }
    }
    long clusterId = getClusterId(vm.getId());
    details.put(VmwareReserveCpu.key(), VmwareReserveCpu.valueIn(clusterId).toString());
    details.put(VmwareReserveMemory.key(), VmwareReserveMemory.valueIn(clusterId).toString());
    to.setDetails(details);
    if (vmType.equals(VirtualMachine.Type.DomainRouter)) {
        NicProfile publicNicProfile = null;
        for (NicProfile nicProfile : nicProfiles) {
            if (nicProfile.getTrafficType() == TrafficType.Public) {
                publicNicProfile = nicProfile;
                break;
            }
        }
        if (publicNicProfile != null) {
            NicTO[] nics = to.getNics();
            // reserve extra NICs
            NicTO[] expandedNics = new NicTO[nics.length + _vmwareMgr.getRouterExtraPublicNics()];
            int i = 0;
            int deviceId = -1;
            for (i = 0; i < nics.length; i++) {
                expandedNics[i] = nics[i];
                if (nics[i].getDeviceId() > deviceId)
                    deviceId = nics[i].getDeviceId();
            }
            deviceId++;
            long networkId = publicNicProfile.getNetworkId();
            NetworkVO network = _networkDao.findById(networkId);
            for (; i < nics.length + _vmwareMgr.getRouterExtraPublicNics(); i++) {
                NicTO nicTo = new NicTO();
                nicTo.setDeviceId(deviceId++);
                nicTo.setBroadcastType(publicNicProfile.getBroadcastType());
                nicTo.setType(publicNicProfile.getTrafficType());
                nicTo.setIp("0.0.0.0");
                nicTo.setNetmask("255.255.255.255");
                try {
                    String mac = _networkMgr.getNextAvailableMacAddressInNetwork(networkId);
                    nicTo.setMac(mac);
                } catch (InsufficientAddressCapacityException e) {
                    throw new CloudRuntimeException("unable to allocate mac address on network: " + networkId);
                }
                nicTo.setDns1(publicNicProfile.getIPv4Dns1());
                nicTo.setDns2(publicNicProfile.getIPv4Dns2());
                if (publicNicProfile.getIPv4Gateway() != null) {
                    nicTo.setGateway(publicNicProfile.getIPv4Gateway());
                } else {
                    nicTo.setGateway(network.getGateway());
                }
                nicTo.setDefaultNic(false);
                nicTo.setBroadcastUri(publicNicProfile.getBroadCastUri());
                nicTo.setIsolationuri(publicNicProfile.getIsolationUri());
                Integer networkRate = _networkMgr.getNetworkRate(network.getId(), null);
                nicTo.setNetworkRateMbps(networkRate);
                expandedNics[i] = nicTo;
            }
            to.setNics(expandedNics);
        }
        StringBuffer sbMacSequence = new StringBuffer();
        for (NicTO nicTo : sortNicsByDeviceId(to.getNics())) {
            sbMacSequence.append(nicTo.getMac()).append("|");
        }
        if (!sbMacSequence.toString().isEmpty()) {
            sbMacSequence.deleteCharAt(sbMacSequence.length() - 1);
            String bootArgs = to.getBootArgs();
            to.setBootArgs(bootArgs + " nic_macs=" + sbMacSequence.toString());
        }
    }
    // Should only be done on user machines
    if (userVm) {
        configureNestedVirtualization(details, to);
    }
    // Determine the VM's OS description
    GuestOSVO guestOS = _guestOsDao.findByIdIncludingRemoved(vm.getVirtualMachine().getGuestOSId());
    to.setOs(guestOS.getDisplayName());
    to.setHostName(vm.getHostName());
    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;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) HashMap(java.util.HashMap) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) GuestOSVO(com.cloud.storage.GuestOSVO) NicProfile(com.cloud.vm.NicProfile) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HostVO(com.cloud.host.HostVO) GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) TrafficType(com.cloud.network.Networks.TrafficType) Type(com.cloud.vm.VirtualMachine.Type) DiskControllerType(com.cloud.hypervisor.vmware.mo.DiskControllerType) BootloaderType(com.cloud.template.VirtualMachineTemplate.BootloaderType) DataObjectType(com.cloud.agent.api.to.DataObjectType) BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) VirtualEthernetCardType(com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NicTO(com.cloud.agent.api.to.NicTO)

Aggregations

GuestOSVO (com.cloud.storage.GuestOSVO)28 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)12 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)10 HostVO (com.cloud.host.HostVO)10 GuestOSHypervisorVO (com.cloud.storage.GuestOSHypervisorVO)10 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)9 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)8 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)8 UserVmVO (com.cloud.vm.UserVmVO)8 VMSnapshotTO (com.cloud.agent.api.VMSnapshotTO)7 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)6 ArrayList (java.util.ArrayList)6 CreateVMSnapshotAnswer (com.cloud.agent.api.CreateVMSnapshotAnswer)5 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)5 HashMap (java.util.HashMap)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 Answer (com.cloud.agent.api.Answer)3 Command (com.cloud.agent.api.Command)3 RevertToVMSnapshotAnswer (com.cloud.agent.api.RevertToVMSnapshotAnswer)3 ActionEvent (com.cloud.event.ActionEvent)3