Search in sources :

Example 11 with GuestOSHypervisorVO

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

the class ManagementServerImpl method updateGuestOsMapping.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_MAPPING_UPDATE, eventDescription = "updating guest OS mapping", async = true)
public GuestOSHypervisor updateGuestOsMapping(final UpdateGuestOsMappingCmd cmd) {
    final Long id = cmd.getId();
    final String osNameForHypervisor = cmd.getOsNameForHypervisor();
    //check if mapping exists
    final GuestOSHypervisor guestOsHypervisorHandle = _guestOSHypervisorDao.findById(id);
    if (guestOsHypervisorHandle == null) {
        throw new InvalidParameterValueException("Guest OS Mapping not found. Please specify a valid ID for the Guest OS Mapping");
    }
    if (!guestOsHypervisorHandle.getIsUserDefined()) {
        throw new InvalidParameterValueException("Unable to modify system defined Guest OS mapping");
    }
    final GuestOSHypervisorVO guestOsHypervisor = _guestOSHypervisorDao.createForUpdate(id);
    guestOsHypervisor.setGuestOsName(osNameForHypervisor);
    if (_guestOSHypervisorDao.update(id, guestOsHypervisor)) {
        return _guestOSHypervisorDao.findById(id);
    } else {
        return null;
    }
}
Also used : GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) GuestOSHypervisor(com.cloud.storage.GuestOSHypervisor) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 12 with GuestOSHypervisorVO

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

the class ManagementServerImpl method addGuestOsMapping.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_MAPPING_ADD, eventDescription = "Adding new guest OS to hypervisor name mapping", create = true)
public GuestOSHypervisor addGuestOsMapping(final AddGuestOsMappingCmd cmd) {
    final Long osTypeId = cmd.getOsTypeId();
    final String osStdName = cmd.getOsStdName();
    final String hypervisor = cmd.getHypervisor();
    final String hypervisorVersion = cmd.getHypervisorVersion();
    final String osNameForHypervisor = cmd.getOsNameForHypervisor();
    GuestOS guestOs = null;
    if (osTypeId == null && (osStdName == null || osStdName.isEmpty())) {
        throw new InvalidParameterValueException("Please specify either a guest OS name or UUID");
    }
    final HypervisorType hypervisorType = HypervisorType.getType(hypervisor);
    if (!(hypervisorType == HypervisorType.KVM || hypervisorType == HypervisorType.XenServer || hypervisorType == HypervisorType.VMware)) {
        throw new InvalidParameterValueException("Please specify a valid hypervisor : XenServer, KVM or VMware");
    }
    final HypervisorCapabilitiesVO hypervisorCapabilities = _hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(hypervisorType, hypervisorVersion);
    if (hypervisorCapabilities == null) {
        throw new InvalidParameterValueException("Please specify a valid hypervisor and supported version");
    }
    //by this point either osTypeId or osStdType is non-empty. Find by either of them. ID takes preference if both are specified
    if (osTypeId != null) {
        guestOs = ApiDBUtils.findGuestOSById(osTypeId);
    } else if (osStdName != null) {
        guestOs = ApiDBUtils.findGuestOSByDisplayName(osStdName);
    }
    if (guestOs == null) {
        throw new InvalidParameterValueException("Unable to find the guest OS by name or UUID");
    }
    //check for duplicates
    final GuestOSHypervisorVO duplicate = _guestOSHypervisorDao.findByOsIdAndHypervisorAndUserDefined(guestOs.getId(), hypervisorType.toString(), hypervisorVersion, true);
    if (duplicate != null) {
        throw new InvalidParameterValueException("Mapping from hypervisor : " + hypervisorType.toString() + ", version : " + hypervisorVersion + " and guest OS : " + guestOs.getDisplayName() + " already exists!");
    }
    final GuestOSHypervisorVO guestOsMapping = new GuestOSHypervisorVO();
    guestOsMapping.setGuestOsId(guestOs.getId());
    guestOsMapping.setGuestOsName(osNameForHypervisor);
    guestOsMapping.setHypervisorType(hypervisorType.toString());
    guestOsMapping.setHypervisorVersion(hypervisorVersion);
    guestOsMapping.setIsUserDefined(true);
    return _guestOSHypervisorDao.persist(guestOsMapping);
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) HypervisorCapabilitiesVO(com.cloud.hypervisor.HypervisorCapabilitiesVO) GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) GuestOS(com.cloud.storage.GuestOS) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 13 with GuestOSHypervisorVO

use of com.cloud.storage.GuestOSHypervisorVO 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)

Example 14 with GuestOSHypervisorVO

use of com.cloud.storage.GuestOSHypervisorVO 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 15 with GuestOSHypervisorVO

use of com.cloud.storage.GuestOSHypervisorVO 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)

Aggregations

GuestOSHypervisorVO (com.cloud.storage.GuestOSHypervisorVO)15 HostVO (com.cloud.host.HostVO)10 GuestOSVO (com.cloud.storage.GuestOSVO)10 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)6 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)6 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)6 VMSnapshotTO (com.cloud.agent.api.VMSnapshotTO)5 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)5 UserVmVO (com.cloud.vm.UserVmVO)5 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)5 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)4 ArrayList (java.util.ArrayList)4 Command (com.cloud.agent.api.Command)3 CreateVMSnapshotAnswer (com.cloud.agent.api.CreateVMSnapshotAnswer)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)3 IOException (java.io.IOException)3 Date (java.util.Date)3 Test (org.junit.Test)3 CreateVMSnapshotCommand (com.cloud.agent.api.CreateVMSnapshotCommand)2