Search in sources :

Example 1 with DiskOffering

use of com.cloud.offering.DiskOffering in project CloudStack-archive by CloudStack-extras.

the class UpdateDiskOfferingCmd method execute.

@Override
public void execute() {
    DiskOffering result = _configService.updateDiskOffering(this);
    if (result != null) {
        DiskOfferingResponse response = _responseGenerator.createDiskOfferingResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update disk offering");
    }
}
Also used : DiskOffering(com.cloud.offering.DiskOffering) ServerApiException(com.cloud.api.ServerApiException) DiskOfferingResponse(com.cloud.api.response.DiskOfferingResponse)

Example 2 with DiskOffering

use of com.cloud.offering.DiskOffering in project CloudStack-archive by CloudStack-extras.

the class DeployVMCmd method create.

@Override
public void create() throws ResourceAllocationException {
    try {
        //Verify that all objects exist before passing them to the service
        Account owner = _accountService.getActiveAccountById(getEntityOwnerId());
        DataCenter zone = _configService.getZone(zoneId);
        if (zone == null) {
            throw new InvalidParameterValueException("Unable to find zone by id=" + zoneId);
        }
        ServiceOffering serviceOffering = _configService.getServiceOffering(serviceOfferingId);
        if (serviceOffering == null) {
            throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
        }
        VirtualMachineTemplate template = _templateService.getTemplate(templateId);
        // Make sure a valid template ID was specified
        if (template == null) {
            throw new InvalidParameterValueException("Unable to use template " + templateId);
        }
        if (diskOfferingId != null) {
            DiskOffering diskOffering = _configService.getDiskOffering(diskOfferingId);
            if (diskOffering == null) {
                throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
            }
        }
        UserVm vm = null;
        if (getHypervisor() == HypervisorType.BareMetal) {
            vm = _bareMetalVmService.createVirtualMachine(this);
        } else {
            if (zone.getNetworkType() == NetworkType.Basic) {
                if (getNetworkIds() != null) {
                    throw new InvalidParameterValueException("Can't specify network Ids in Basic zone");
                } else {
                    vm = _userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, getSecurityGroupIdList(), owner, name, displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress, keyboard);
                }
            } else {
                if (zone.isSecurityGroupEnabled()) {
                    vm = _userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, getNetworkIds(), getSecurityGroupIdList(), owner, name, displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress, keyboard);
                } else {
                    if (getSecurityGroupIdList() != null && !getSecurityGroupIdList().isEmpty()) {
                        throw new InvalidParameterValueException("Can't create vm with security groups; security group feature is not enabled per zone");
                    }
                    vm = _userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, getNetworkIds(), owner, name, displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress, keyboard);
                }
            }
        }
        if (vm != null) {
            setEntityId(vm.getId());
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm");
        }
    } catch (InsufficientCapacityException ex) {
        s_logger.info(ex);
        s_logger.trace(ex);
        throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    } catch (ResourceUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : Account(com.cloud.user.Account) UserVm(com.cloud.uservm.UserVm) DataCenter(com.cloud.dc.DataCenter) DiskOffering(com.cloud.offering.DiskOffering) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ServiceOffering(com.cloud.offering.ServiceOffering) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 3 with DiskOffering

use of com.cloud.offering.DiskOffering in project cloudstack by apache.

the class VolumeOrchestrator method recreateVolume.

private Pair<VolumeVO, DataStore> recreateVolume(VolumeVO vol, VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException {
    VolumeVO newVol;
    boolean recreate = RecreatableSystemVmEnabled.value();
    DataStore destPool = null;
    if (recreate && (dest.getStorageForDisks() == null || dest.getStorageForDisks().get(vol) == null)) {
        destPool = dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary);
        s_logger.debug("existing pool: " + destPool.getId());
    } else {
        StoragePool pool = dest.getStorageForDisks().get(vol);
        destPool = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
    }
    if (vol.getState() == Volume.State.Allocated || vol.getState() == Volume.State.Creating) {
        newVol = vol;
    } else {
        newVol = switchVolume(vol, vm);
        // changed
        if (dest.getStorageForDisks() != null && dest.getStorageForDisks().containsKey(vol)) {
            StoragePool poolWithOldVol = dest.getStorageForDisks().get(vol);
            dest.getStorageForDisks().put(newVol, poolWithOldVol);
            dest.getStorageForDisks().remove(vol);
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Created new volume " + newVol + " for old volume " + vol);
        }
    }
    VolumeInfo volume = volFactory.getVolume(newVol.getId(), destPool);
    Long templateId = newVol.getTemplateId();
    for (int i = 0; i < 2; i++) {
        // retry one more time in case of template reload is required for Vmware case
        AsyncCallFuture<VolumeApiResult> future = null;
        if (templateId == null) {
            DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
            HypervisorType hyperType = vm.getVirtualMachine().getHypervisorType();
            // update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
            volService.updateHypervisorSnapshotReserveForVolume(diskOffering, volume.getId(), hyperType);
            volume = volFactory.getVolume(newVol.getId(), destPool);
            future = volService.createVolumeAsync(volume, destPool);
        } else {
            TemplateInfo templ = tmplFactory.getReadyTemplateOnImageStore(templateId, dest.getDataCenter().getId());
            if (templ == null) {
                s_logger.debug("can't find ready template: " + templateId + " for data center " + dest.getDataCenter().getId());
                throw new CloudRuntimeException("can't find ready template: " + templateId + " for data center " + dest.getDataCenter().getId());
            }
            PrimaryDataStore primaryDataStore = (PrimaryDataStore) destPool;
            if (primaryDataStore.isManaged()) {
                DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
                HypervisorType hyperType = vm.getVirtualMachine().getHypervisorType();
                // update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
                volService.updateHypervisorSnapshotReserveForVolume(diskOffering, volume.getId(), hyperType);
                long hostId = vm.getVirtualMachine().getHostId();
                future = volService.createManagedStorageVolumeFromTemplateAsync(volume, destPool.getId(), templ, hostId);
            } else {
                future = volService.createVolumeFromTemplateAsync(volume, destPool.getId(), templ);
            }
        }
        VolumeApiResult result;
        try {
            result = future.get();
            if (result.isFailed()) {
                if (result.getResult().contains("request template reload") && (i == 0)) {
                    s_logger.debug("Retry template re-deploy for vmware");
                    continue;
                } else {
                    s_logger.debug("Unable to create " + newVol + ":" + result.getResult());
                    throw new StorageUnavailableException("Unable to create " + newVol + ":" + result.getResult(), destPool.getId());
                }
            }
            StoragePoolVO storagePool = _storagePoolDao.findById(destPool.getId());
            if (storagePool.isManaged()) {
                long hostId = vm.getVirtualMachine().getHostId();
                Host host = _hostDao.findById(hostId);
                volService.grantAccess(volFactory.getVolume(newVol.getId()), host, destPool);
            }
            newVol = _volsDao.findById(newVol.getId());
            //break out of template-redeploy retry loop
            break;
        } catch (InterruptedException | ExecutionException e) {
            s_logger.error("Unable to create " + newVol, e);
            throw new StorageUnavailableException("Unable to create " + newVol + ":" + e.toString(), destPool.getId());
        }
    }
    return new Pair<VolumeVO, DataStore>(newVol, destPool);
}
Also used : StoragePool(com.cloud.storage.StoragePool) DiskOffering(com.cloud.offering.DiskOffering) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) Host(com.cloud.host.Host) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) VolumeVO(com.cloud.storage.VolumeVO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ExecutionException(java.util.concurrent.ExecutionException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) Pair(com.cloud.utils.Pair)

Example 4 with DiskOffering

use of com.cloud.offering.DiskOffering in project cloudstack by apache.

the class ConfigurationManagerImpl method updateDiskOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_DISK_OFFERING_EDIT, eventDescription = "updating disk offering")
public DiskOffering updateDiskOffering(final UpdateDiskOfferingCmd cmd) {
    final Long diskOfferingId = cmd.getId();
    final String name = cmd.getDiskOfferingName();
    final String displayText = cmd.getDisplayText();
    final Integer sortKey = cmd.getSortKey();
    final Boolean displayDiskOffering = cmd.getDisplayOffering();
    // Check if diskOffering exists
    final DiskOffering diskOfferingHandle = _entityMgr.findById(DiskOffering.class, diskOfferingId);
    if (diskOfferingHandle == null) {
        throw new InvalidParameterValueException("Unable to find disk offering by id " + diskOfferingId);
    }
    Long userId = CallContext.current().getCallingUserId();
    if (userId == null) {
        userId = Long.valueOf(User.UID_SYSTEM);
    }
    final User user = _userDao.findById(userId);
    if (user == null || user.getRemoved() != null) {
        throw new InvalidParameterValueException("Unable to find active user by id " + userId);
    }
    final Account account = _accountDao.findById(user.getAccountId());
    if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
        if (diskOfferingHandle.getDomainId() == null) {
            throw new InvalidParameterValueException("Unable to update public disk offering by id " + userId + " because it is domain-admin");
        }
        if (!_domainDao.isChildDomain(account.getDomainId(), diskOfferingHandle.getDomainId())) {
            throw new InvalidParameterValueException("Unable to update disk offering by another domain admin with id " + userId);
        }
    } else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
        throw new InvalidParameterValueException("Unable to update disk offering by id " + userId + " because it is not root-admin or domain-admin");
    }
    final boolean updateNeeded = name != null || displayText != null || sortKey != null || displayDiskOffering != null;
    if (!updateNeeded) {
        return _diskOfferingDao.findById(diskOfferingId);
    }
    final DiskOfferingVO diskOffering = _diskOfferingDao.createForUpdate(diskOfferingId);
    if (name != null) {
        diskOffering.setName(name);
    }
    if (displayText != null) {
        diskOffering.setDisplayText(displayText);
    }
    if (sortKey != null) {
        diskOffering.setSortKey(sortKey);
    }
    if (displayDiskOffering != null) {
        diskOffering.setDisplayOffering(displayDiskOffering);
    }
    if (_diskOfferingDao.update(diskOfferingId, diskOffering)) {
        CallContext.current().setEventDetails("Disk offering id=" + diskOffering.getId());
        return _diskOfferingDao.findById(diskOfferingId);
    } else {
        return null;
    }
}
Also used : Account(com.cloud.user.Account) DiskOffering(com.cloud.offering.DiskOffering) User(com.cloud.user.User) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) ActionEvent(com.cloud.event.ActionEvent)

Example 5 with DiskOffering

use of com.cloud.offering.DiskOffering in project cloudstack by apache.

the class UpdateDiskOfferingCmd method execute.

@Override
public void execute() {
    DiskOffering result = _configService.updateDiskOffering(this);
    if (result != null) {
        DiskOfferingResponse response = _responseGenerator.createDiskOfferingResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update disk offering");
    }
}
Also used : DiskOffering(com.cloud.offering.DiskOffering) ServerApiException(org.apache.cloudstack.api.ServerApiException) DiskOfferingResponse(org.apache.cloudstack.api.response.DiskOfferingResponse)

Aggregations

DiskOffering (com.cloud.offering.DiskOffering)14 DataCenter (com.cloud.dc.DataCenter)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 ServiceOffering (com.cloud.offering.ServiceOffering)4 StoragePool (com.cloud.storage.StoragePool)4 VolumeVO (com.cloud.storage.VolumeVO)4 Account (com.cloud.user.Account)4 ServerApiException (com.cloud.api.ServerApiException)3 DiskOfferingResponse (com.cloud.api.response.DiskOfferingResponse)3 Pod (com.cloud.dc.Pod)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)3 ArrayList (java.util.ArrayList)3 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)3 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)3 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 Host (com.cloud.host.Host)2 Volume (com.cloud.storage.Volume)2 UserVm (com.cloud.uservm.UserVm)2