use of com.cloud.storage.GuestOSVO in project cloudstack by apache.
the class OvmGuru method implement.
@Override
public VirtualMachineTO implement(VirtualMachineProfile vm) {
VirtualMachineTO to = toVirtualMachineTO(vm);
to.setBootloader(vm.getBootLoaderType());
// Determine the VM's OS description
GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId());
to.setOs(guestOS.getDisplayName());
return to;
}
use of com.cloud.storage.GuestOSVO in project cloudstack by apache.
the class ManagementServerImpl method updateGuestOs.
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_UPDATE, eventDescription = "updating guest OS type", async = true)
public GuestOS updateGuestOs(final UpdateGuestOsCmd cmd) {
final Long id = cmd.getId();
final String displayName = cmd.getOsDisplayName();
// check if guest OS exists
final GuestOS guestOsHandle = ApiDBUtils.findGuestOSById(id);
if (guestOsHandle == null) {
throw new InvalidParameterValueException("Guest OS not found. Please specify a valid ID for the Guest OS");
}
if (!guestOsHandle.getIsUserDefined()) {
throw new InvalidParameterValueException("Unable to modify system defined guest OS");
}
if (cmd.getDetails() != null && !cmd.getDetails().isEmpty()) {
Map<String, String> detailsMap = cmd.getDetails();
for (Object key : detailsMap.keySet()) {
_guestOsDetailsDao.addDetail(id, (String) key, detailsMap.get(key), false);
}
}
// Check if update is needed
if (displayName.equals(guestOsHandle.getDisplayName())) {
return guestOsHandle;
}
// Check if another Guest OS by same name exists
final GuestOS duplicate = ApiDBUtils.findGuestOSByDisplayName(displayName);
if (duplicate != null) {
throw new InvalidParameterValueException("The specified Guest OS name : " + displayName + " already exists. Please specify a unique guest OS name");
}
final GuestOSVO guestOs = _guestOSDao.createForUpdate(id);
guestOs.setDisplayName(displayName);
if (_guestOSDao.update(id, guestOs)) {
return _guestOSDao.findById(id);
} else {
return null;
}
}
use of com.cloud.storage.GuestOSVO in project cloudstack by apache.
the class ManagementServerImpl method listGuestOSByCriteria.
@Override
public Pair<List<? extends GuestOS>, Integer> listGuestOSByCriteria(final ListGuestOsCmd cmd) {
final Filter searchFilter = new Filter(GuestOSVO.class, "displayName", true, cmd.getStartIndex(), cmd.getPageSizeVal());
final Long id = cmd.getId();
final Long osCategoryId = cmd.getOsCategoryId();
final String description = cmd.getDescription();
final String keyword = cmd.getKeyword();
final SearchCriteria<GuestOSVO> sc = _guestOSDao.createSearchCriteria();
if (id != null) {
sc.addAnd("id", SearchCriteria.Op.EQ, id);
}
if (osCategoryId != null) {
sc.addAnd("categoryId", SearchCriteria.Op.EQ, osCategoryId);
}
if (description != null) {
sc.addAnd("displayName", SearchCriteria.Op.LIKE, "%" + description + "%");
}
if (keyword != null) {
sc.addAnd("displayName", SearchCriteria.Op.LIKE, "%" + keyword + "%");
}
final Pair<List<GuestOSVO>, Integer> result = _guestOSDao.searchAndCount(sc, searchFilter);
return new Pair<List<? extends GuestOS>, Integer>(result.first(), result.second());
}
use of com.cloud.storage.GuestOSVO in project cloudstack by apache.
the class GuestOsMapper method updateGuestOsNameFromMapping.
public void updateGuestOsNameFromMapping(String newDisplayName, GuestOSHypervisorMapping mapping) {
if (!isValidGuestOSHypervisorMapping(mapping)) {
return;
}
GuestOSHypervisorVO guestOSHypervisorVO = guestOSHypervisorDao.findByOsNameAndHypervisorOrderByCreatedDesc(mapping.getGuestOsName(), mapping.getHypervisorType(), mapping.getHypervisorVersion());
if (guestOSHypervisorVO == null) {
LOG.debug("Unable to update guest OS name, as there is no guest os hypervisor mapping");
return;
}
long guestOsId = guestOSHypervisorVO.getGuestOsId();
GuestOSVO guestOS = guestOSDao.findById(guestOsId);
if (guestOS != null) {
guestOS.setDisplayName(newDisplayName);
guestOSDao.update(guestOS.getId(), guestOS);
}
}
use of com.cloud.storage.GuestOSVO in project cloudstack by apache.
the class GuestOsMapper method updateGuestOsName.
public void updateGuestOsName(long categoryId, String oldDisplayName, String newDisplayName) {
GuestOSVO guestOS = guestOSDao.findByCategoryIdAndDisplayNameOrderByCreatedDesc(categoryId, oldDisplayName);
if (guestOS == null) {
LOG.debug("Unable to update guest OS name, as there is no guest OS with category id: " + categoryId + " and display name: " + oldDisplayName);
return;
}
guestOS.setDisplayName(newDisplayName);
guestOSDao.update(guestOS.getId(), guestOS);
}
Aggregations