Search in sources :

Example 6 with HypervisorCapabilitiesVO

use of com.cloud.hypervisor.HypervisorCapabilitiesVO in project cloudstack by apache.

the class ManagementServerImpl method listHypervisorCapabilities.

@Override
public Pair<List<? extends HypervisorCapabilities>, Integer> listHypervisorCapabilities(final Long id, final HypervisorType hypervisorType, final String keyword, final Long startIndex, final Long pageSizeVal) {
    final Filter searchFilter = new Filter(HypervisorCapabilitiesVO.class, "id", true, startIndex, pageSizeVal);
    final SearchCriteria<HypervisorCapabilitiesVO> sc = _hypervisorCapabilitiesDao.createSearchCriteria();
    if (id != null) {
        sc.addAnd("id", SearchCriteria.Op.EQ, id);
    }
    if (hypervisorType != null) {
        sc.addAnd("hypervisorType", SearchCriteria.Op.EQ, hypervisorType);
    }
    if (keyword != null) {
        final SearchCriteria<HypervisorCapabilitiesVO> ssc = _hypervisorCapabilitiesDao.createSearchCriteria();
        ssc.addOr("hypervisorType", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("hypervisorType", SearchCriteria.Op.SC, ssc);
    }
    final Pair<List<HypervisorCapabilitiesVO>, Integer> result = _hypervisorCapabilitiesDao.searchAndCount(sc, searchFilter);
    return new Pair<List<? extends HypervisorCapabilities>, Integer>(result.first(), result.second());
}
Also used : HypervisorCapabilitiesVO(com.cloud.hypervisor.HypervisorCapabilitiesVO) Filter(com.cloud.utils.db.Filter) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) Pair(com.cloud.utils.Pair) SSHKeyPair(com.cloud.user.SSHKeyPair)

Example 7 with HypervisorCapabilitiesVO

use of com.cloud.hypervisor.HypervisorCapabilitiesVO 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 8 with HypervisorCapabilitiesVO

use of com.cloud.hypervisor.HypervisorCapabilitiesVO in project cloudstack by apache.

the class ManagementServerImpl method updateHypervisorCapabilities.

@Override
public HypervisorCapabilities updateHypervisorCapabilities(final Long id, final Long maxGuestsLimit, final Boolean securityGroupEnabled) {
    HypervisorCapabilitiesVO hpvCapabilities = _hypervisorCapabilitiesDao.findById(id, true);
    if (hpvCapabilities == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("unable to find the hypervisor capabilities for specified id");
        ex.addProxyObject(id.toString(), "Id");
        throw ex;
    }
    final boolean updateNeeded = maxGuestsLimit != null || securityGroupEnabled != null;
    if (!updateNeeded) {
        return hpvCapabilities;
    }
    hpvCapabilities = _hypervisorCapabilitiesDao.createForUpdate(id);
    if (maxGuestsLimit != null) {
        hpvCapabilities.setMaxGuestsLimit(maxGuestsLimit);
    }
    if (securityGroupEnabled != null) {
        hpvCapabilities.setSecurityGroupEnabled(securityGroupEnabled);
    }
    if (_hypervisorCapabilitiesDao.update(id, hpvCapabilities)) {
        hpvCapabilities = _hypervisorCapabilitiesDao.findById(id);
        CallContext.current().setEventDetails("Hypervisor Capabilities id=" + hpvCapabilities.getId());
        return hpvCapabilities;
    } else {
        return null;
    }
}
Also used : HypervisorCapabilitiesVO(com.cloud.hypervisor.HypervisorCapabilitiesVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Aggregations

HypervisorCapabilitiesVO (com.cloud.hypervisor.HypervisorCapabilitiesVO)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)6 HostVO (com.cloud.host.HostVO)4 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)3 ActionEvent (com.cloud.event.ActionEvent)3 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)3 VolumeVO (com.cloud.storage.VolumeVO)3 Account (com.cloud.user.Account)3 SSHKeyPair (com.cloud.user.SSHKeyPair)3 Pair (com.cloud.utils.Pair)3 VMInstanceVO (com.cloud.vm.VMInstanceVO)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)2 Host (com.cloud.host.Host)2 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)2 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)2 StoragePool (com.cloud.storage.StoragePool)2 DB (com.cloud.utils.db.DB)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2