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());
}
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);
}
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;
}
}
Aggregations