Search in sources :

Example 11 with GuestOS

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);
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) HypervisorCapabilitiesVO(com.cloud.hypervisor.HypervisorCapabilitiesVO) GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) GuestOS(com.cloud.storage.GuestOS) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 12 with GuestOS

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);
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) GuestOSCategoryVO(com.cloud.storage.GuestOSCategoryVO) GuestOS(com.cloud.storage.GuestOS) GuestOSVO(com.cloud.storage.GuestOSVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 13 with GuestOS

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;
    }
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) GuestOS(com.cloud.storage.GuestOS) GuestOSVO(com.cloud.storage.GuestOSVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 14 with GuestOS

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);
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) GuestOS(com.cloud.storage.GuestOS) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 15 with GuestOS

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);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) GuestOS(com.cloud.storage.GuestOS) GuestOSResponse(com.cloud.api.response.GuestOSResponse)

Aggregations

GuestOS (com.cloud.storage.GuestOS)26 ActionEvent (com.cloud.event.ActionEvent)8 DB (com.cloud.utils.db.DB)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 ArrayList (java.util.ArrayList)6 Account (com.cloud.user.Account)5 GuestOSResponse (com.cloud.api.response.GuestOSResponse)4 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)4 GuestOSVO (com.cloud.storage.GuestOSVO)4 VMTemplateVO (com.cloud.storage.VMTemplateVO)4 UserVO (com.cloud.user.UserVO)4 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)4 ServerApiException (org.apache.cloudstack.api.ServerApiException)4 ServerApiException (com.cloud.api.ServerApiException)3 DataCenter (com.cloud.dc.DataCenter)3 DataCenterVO (com.cloud.dc.DataCenterVO)3 ImageFormat (com.cloud.storage.Storage.ImageFormat)3 TemplateProfile (com.cloud.storage.TemplateProfile)3 ListResponse (com.cloud.api.response.ListResponse)2 HostVO (com.cloud.host.HostVO)2