use of com.cloud.storage.GuestOS in project cosmic by MissionCriticalCloud.
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)) {
throw new InvalidParameterValueException("Please specify a valid hypervisor : XenServer or KVM");
}
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.storage.GuestOS in project cosmic by MissionCriticalCloud.
the class ManagementServerImpl method addGuestOs.
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_ADD, eventDescription = "Adding new guest OS type", create = true)
public GuestOS addGuestOs(final AddGuestOsCmd cmd) {
final Long categoryId = cmd.getOsCategoryId();
final String displayName = cmd.getOsDisplayName();
final String name = cmd.getOsName();
final GuestOSCategoryVO guestOsCategory = ApiDBUtils.findGuestOsCategoryById(categoryId);
if (guestOsCategory == null) {
throw new InvalidParameterValueException("Guest OS category not found. Please specify a valid Guest OS category");
}
final GuestOS guestOs = ApiDBUtils.findGuestOSByDisplayName(displayName);
if (guestOs != null) {
throw new InvalidParameterValueException("The specified Guest OS name : " + displayName + " already exists. Please specify a unique name");
}
final GuestOSVO guestOsVo = new GuestOSVO();
guestOsVo.setCategoryId(categoryId.longValue());
guestOsVo.setDisplayName(displayName);
guestOsVo.setName(name);
guestOsVo.setIsUserDefined(true);
return _guestOSDao.persist(guestOsVo);
}
use of com.cloud.storage.GuestOS in project cosmic by MissionCriticalCloud.
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");
}
// 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.GuestOS in project cosmic by MissionCriticalCloud.
the class ManagementServerImpl method removeGuestOs.
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_REMOVE, eventDescription = "removing guest OS type", async = true)
public boolean removeGuestOs(final RemoveGuestOsCmd cmd) {
final Long id = cmd.getId();
// check if guest OS exists
final GuestOS guestOs = ApiDBUtils.findGuestOSById(id);
if (guestOs == null) {
throw new InvalidParameterValueException("Guest OS not found. Please specify a valid ID for the Guest OS");
}
if (!guestOs.getIsUserDefined()) {
throw new InvalidParameterValueException("Unable to remove system defined guest OS");
}
return _guestOSDao.remove(id);
}
use of com.cloud.storage.GuestOS in project CloudStack-archive by CloudStack-extras.
the class ListGuestOsCmd method execute.
@Override
public void execute() {
List<? extends GuestOS> result = _mgr.listGuestOSByCriteria(this);
ListResponse<GuestOSResponse> response = new ListResponse<GuestOSResponse>();
List<GuestOSResponse> osResponses = new ArrayList<GuestOSResponse>();
for (GuestOS guestOS : result) {
GuestOSResponse guestOSResponse = new GuestOSResponse();
guestOSResponse.setDescription(guestOS.getDisplayName());
guestOSResponse.setId(guestOS.getId());
guestOSResponse.setOsCategoryId(guestOS.getCategoryId());
guestOSResponse.setObjectName("ostype");
osResponses.add(guestOSResponse);
}
response.setResponses(osResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
Aggregations