Search in sources :

Example 6 with GuestOSCategoryVO

use of com.cloud.storage.GuestOSCategoryVO in project cloudstack by apache.

the class ResourceManagerImpl method updateHost.

@Override
public Host updateHost(final UpdateHostCmd cmd) throws NoTransitionException {
    final Long hostId = cmd.getId();
    final Long guestOSCategoryId = cmd.getOsCategoryId();
    // Verify that the host exists
    final HostVO host = _hostDao.findById(hostId);
    if (host == null) {
        throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist");
    }
    if (cmd.getAllocationState() != null) {
        final ResourceState.Event resourceEvent = ResourceState.Event.toEvent(cmd.getAllocationState());
        if (resourceEvent != ResourceState.Event.Enable && resourceEvent != ResourceState.Event.Disable) {
            throw new CloudRuntimeException("Invalid allocation state:" + cmd.getAllocationState() + ", only Enable/Disable are allowed");
        }
        resourceStateTransitTo(host, resourceEvent, _nodeId);
    }
    if (guestOSCategoryId != null) {
        // Verify that the guest OS Category exists
        if (!(guestOSCategoryId > 0) || _guestOSCategoryDao.findById(guestOSCategoryId) == null) {
            throw new InvalidParameterValueException("Please specify a valid guest OS category.");
        }
        final GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId);
        final DetailVO guestOSDetail = _hostDetailsDao.findDetail(hostId, "guest.os.category.id");
        if (guestOSCategory != null && !GuestOSCategoryVO.CATEGORY_NONE.equalsIgnoreCase(guestOSCategory.getName())) {
            // Create/Update an entry for guest.os.category.id
            if (guestOSDetail != null) {
                guestOSDetail.setValue(String.valueOf(guestOSCategory.getId()));
                _hostDetailsDao.update(guestOSDetail.getId(), guestOSDetail);
            } else {
                final Map<String, String> detail = new HashMap<String, String>();
                detail.put("guest.os.category.id", String.valueOf(guestOSCategory.getId()));
                _hostDetailsDao.persist(hostId, detail);
            }
        } else {
            // Delete any existing entry for guest.os.category.id
            if (guestOSDetail != null) {
                _hostDetailsDao.remove(guestOSDetail.getId());
            }
        }
    }
    final List<String> hostTags = cmd.getHostTags();
    if (hostTags != null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Updating Host Tags to :" + hostTags);
        }
        _hostTagsDao.persist(hostId, hostTags);
    }
    final String url = cmd.getUrl();
    if (url != null) {
        _storageMgr.updateSecondaryStorage(cmd.getId(), cmd.getUrl());
    }
    final HostVO updatedHost = _hostDao.findById(hostId);
    return updatedHost;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DetailVO(com.cloud.host.DetailVO) HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) GuestOSCategoryVO(com.cloud.storage.GuestOSCategoryVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO)

Aggregations

GuestOSCategoryVO (com.cloud.storage.GuestOSCategoryVO)6 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 DetailVO (com.cloud.host.DetailVO)2 GuestOSVO (com.cloud.storage.GuestOSVO)2 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)1 ActionEvent (com.cloud.event.ActionEvent)1 HostVO (com.cloud.host.HostVO)1 GuestOS (com.cloud.storage.GuestOS)1 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)1 SSHKeyPair (com.cloud.user.SSHKeyPair)1 Pair (com.cloud.utils.Pair)1 DB (com.cloud.utils.db.DB)1 Filter (com.cloud.utils.db.Filter)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ConfigurationException (javax.naming.ConfigurationException)1 GuestOSResponse (org.apache.cloudstack.api.response.GuestOSResponse)1