Search in sources :

Example 1 with ServiceOfferingJoinVO

use of com.cloud.api.query.vo.ServiceOfferingJoinVO in project cloudstack by apache.

the class QueryManagerImpl method filterOfferingsOnCurrentTags.

private List<ServiceOfferingJoinVO> filterOfferingsOnCurrentTags(List<ServiceOfferingJoinVO> offerings, ServiceOfferingVO currentVmOffering) {
    if (currentVmOffering == null)
        return offerings;
    List<String> currentTagsList = StringUtils.csvTagsToList(currentVmOffering.getTags());
    // New service offering should have all the tags of the current service offering.
    List<ServiceOfferingJoinVO> filteredOfferings = new ArrayList<>();
    for (ServiceOfferingJoinVO offering : offerings) {
        List<String> newTagsList = StringUtils.csvTagsToList(offering.getTags());
        if (newTagsList.containsAll(currentTagsList)) {
            filteredOfferings.add(offering);
        }
    }
    return filteredOfferings;
}
Also used : ServiceOfferingJoinVO(com.cloud.api.query.vo.ServiceOfferingJoinVO) ArrayList(java.util.ArrayList)

Example 2 with ServiceOfferingJoinVO

use of com.cloud.api.query.vo.ServiceOfferingJoinVO in project cloudstack by apache.

the class VolumeApiServiceImpl method isNotPossibleToResize.

/**
 * A volume should not be resized if it covers ALL the following scenarios: <br>
 * 1 - Root volume <br>
 * 2 - && Current Disk Offering enforces a root disk size (in this case one can resize only by changing the Service Offering)
 */
protected boolean isNotPossibleToResize(VolumeVO volume, DiskOfferingVO diskOffering) {
    Long templateId = volume.getTemplateId();
    ImageFormat format = null;
    if (templateId != null) {
        VMTemplateVO template = _templateDao.findByIdIncludingRemoved(templateId);
        format = template.getFormat();
    }
    boolean isNotIso = format != null && format != ImageFormat.ISO;
    boolean isRoot = Volume.Type.ROOT.equals(volume.getVolumeType());
    ServiceOfferingJoinVO serviceOfferingView = serviceOfferingJoinDao.findById(diskOffering.getId());
    boolean isOfferingEnforcingRootDiskSize = serviceOfferingView != null && serviceOfferingView.getRootDiskSize() > 0;
    return isOfferingEnforcingRootDiskSize && isRoot && isNotIso;
}
Also used : ServiceOfferingJoinVO(com.cloud.api.query.vo.ServiceOfferingJoinVO) ImageFormat(com.cloud.storage.Storage.ImageFormat)

Example 3 with ServiceOfferingJoinVO

use of com.cloud.api.query.vo.ServiceOfferingJoinVO in project cloudstack by apache.

the class DomainManagerImpl method cleanupDomainOfferings.

protected void cleanupDomainOfferings(Long domainId) {
    if (domainId == null) {
        return;
    }
    String domainIdString = String.valueOf(domainId);
    List<Long> diskOfferingsDetailsToRemove = new ArrayList<>();
    List<Long> serviceOfferingsDetailsToRemove = new ArrayList<>();
    // delete the service and disk offerings associated with this domain
    List<DiskOfferingJoinVO> diskOfferingsForThisDomain = diskOfferingJoinDao.findByDomainId(domainId);
    for (DiskOfferingJoinVO diskOffering : diskOfferingsForThisDomain) {
        if (domainIdString.equals(diskOffering.getDomainId())) {
            diskOfferingDao.remove(diskOffering.getId());
        } else {
            diskOfferingsDetailsToRemove.add(diskOffering.getId());
        }
    }
    List<ServiceOfferingJoinVO> serviceOfferingsForThisDomain = serviceOfferingJoinDao.findByDomainId(domainId);
    for (ServiceOfferingJoinVO serviceOffering : serviceOfferingsForThisDomain) {
        if (domainIdString.equals(serviceOffering.getDomainId())) {
            serviceOfferingDao.remove(serviceOffering.getId());
        } else {
            serviceOfferingsDetailsToRemove.add(serviceOffering.getId());
        }
    }
    // Remove domain IDs for offerings which may be multi-domain
    for (final Long diskOfferingId : diskOfferingsDetailsToRemove) {
        diskOfferingDetailsDao.removeDetail(diskOfferingId, ApiConstants.DOMAIN_ID, domainIdString);
    }
    for (final Long serviceOfferingId : serviceOfferingsDetailsToRemove) {
        serviceOfferingDetailsDao.removeDetail(serviceOfferingId, ApiConstants.DOMAIN_ID, domainIdString);
    }
}
Also used : ServiceOfferingJoinVO(com.cloud.api.query.vo.ServiceOfferingJoinVO) ArrayList(java.util.ArrayList) DiskOfferingJoinVO(com.cloud.api.query.vo.DiskOfferingJoinVO)

Example 4 with ServiceOfferingJoinVO

use of com.cloud.api.query.vo.ServiceOfferingJoinVO in project cloudstack by apache.

the class QueryManagerImpl method searchForServiceOfferingsInternal.

private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInternal(ListServiceOfferingsCmd cmd) {
    // Note
    // The filteredOfferings method for offerings is being modified in accordance with
    // discussion with Will/Kevin
    // For now, we will be listing the following based on the usertype
    // 1. For root, we will filteredOfferings all offerings
    // 2. For domainAdmin and regular users, we will filteredOfferings everything in
    // their domains+parent domains ... all the way
    // till
    // root
    Filter searchFilter = new Filter(ServiceOfferingJoinVO.class, "sortKey", SortKeyAscending.value(), cmd.getStartIndex(), cmd.getPageSizeVal());
    searchFilter.addOrderBy(ServiceOfferingJoinVO.class, "id", true);
    Account caller = CallContext.current().getCallingAccount();
    Object name = cmd.getServiceOfferingName();
    Object id = cmd.getId();
    Object keyword = cmd.getKeyword();
    Long vmId = cmd.getVirtualMachineId();
    Long domainId = cmd.getDomainId();
    Boolean isSystem = cmd.getIsSystem();
    String vmTypeStr = cmd.getSystemVmType();
    ServiceOfferingVO currentVmOffering = null;
    Boolean isRecursive = cmd.isRecursive();
    Long zoneId = cmd.getZoneId();
    Integer cpuNumber = cmd.getCpuNumber();
    Integer memory = cmd.getMemory();
    Integer cpuSpeed = cmd.getCpuSpeed();
    SearchCriteria<ServiceOfferingJoinVO> sc = _srvOfferingJoinDao.createSearchCriteria();
    if (!_accountMgr.isRootAdmin(caller.getId()) && isSystem) {
        throw new InvalidParameterValueException("Only ROOT admins can access system's offering");
    }
    // domain
    if (domainId != null && !_accountMgr.isRootAdmin(caller.getId())) {
        // child of so's domain
        if (!isPermissible(caller.getDomainId(), domainId)) {
            throw new PermissionDeniedException("The account:" + caller.getAccountName() + " does not fall in the same domain hierarchy as the service offering");
        }
    }
    if (vmId != null) {
        VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId);
        if ((vmInstance == null) || (vmInstance.getRemoved() != null)) {
            InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a virtual machine with specified id");
            ex.addProxyObject(vmId.toString(), "vmId");
            throw ex;
        }
        _accountMgr.checkAccess(caller, null, true, vmInstance);
        currentVmOffering = _srvOfferingDao.findByIdIncludingRemoved(vmInstance.getId(), vmInstance.getServiceOfferingId());
        if (!currentVmOffering.isDynamic()) {
            sc.addAnd("id", SearchCriteria.Op.NEQ, currentVmOffering.getId());
        }
        if (currentVmOffering.getDiskOfferingStrictness()) {
            sc.addAnd("diskOfferingId", Op.EQ, currentVmOffering.getDiskOfferingId());
            sc.addAnd("diskOfferingStrictness", Op.EQ, true);
        } else {
            sc.addAnd("diskOfferingStrictness", Op.EQ, false);
        }
        boolean isRootVolumeUsingLocalStorage = virtualMachineManager.isRootVolumeOnLocalStorage(vmId);
        // 1. Only return offerings with the same storage type than the storage pool where the VM's root volume is allocated
        sc.addAnd("useLocalStorage", SearchCriteria.Op.EQ, isRootVolumeUsingLocalStorage);
        // 2.In case vm is running return only offerings greater than equal to current offering compute and offering's dynamic scalability should match
        if (vmInstance.getState() == VirtualMachine.State.Running) {
            Integer vmCpu = currentVmOffering.getCpu();
            Integer vmMemory = currentVmOffering.getRamSize();
            Integer vmSpeed = currentVmOffering.getSpeed();
            if ((vmCpu == null || vmMemory == null || vmSpeed == null) && VirtualMachine.Type.User.equals(vmInstance.getType())) {
                UserVmVO userVmVO = _userVmDao.findById(vmId);
                _userVmDao.loadDetails(userVmVO);
                Map<String, String> details = userVmVO.getDetails();
                vmCpu = NumbersUtil.parseInt(details.get(ApiConstants.CPU_NUMBER), 0);
                if (vmSpeed == null) {
                    vmSpeed = NumbersUtil.parseInt(details.get(ApiConstants.CPU_SPEED), 0);
                }
                vmMemory = NumbersUtil.parseInt(details.get(ApiConstants.MEMORY), 0);
            }
            if (vmCpu != null && vmCpu > 0) {
                sc.addAnd("cpu", Op.SC, getMinimumCpuServiceOfferingJoinSearchCriteria(vmCpu));
            }
            if (vmSpeed != null && vmSpeed > 0) {
                sc.addAnd("speed", Op.SC, getMinimumCpuSpeedServiceOfferingJoinSearchCriteria(vmSpeed));
            }
            if (vmMemory != null && vmMemory > 0) {
                sc.addAnd("ramSize", Op.SC, getMinimumMemoryServiceOfferingJoinSearchCriteria(vmMemory));
            }
            sc.addAnd("dynamicScalingEnabled", Op.EQ, currentVmOffering.isDynamicScalingEnabled());
        }
    }
    // boolean includePublicOfferings = false;
    if ((_accountMgr.isNormalUser(caller.getId()) || _accountMgr.isDomainAdmin(caller.getId())) || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
        // For non-root users.
        if (isSystem) {
            throw new InvalidParameterValueException("Only root admins can access system's offering");
        }
        if (isRecursive) {
            // domain + all sub-domains
            if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
                throw new InvalidParameterValueException("Only ROOT admins and Domain admins can list service offerings with isrecursive=true");
            }
        }
    } else {
        // for root users
        if (caller.getDomainId() != 1 && isSystem) {
            // NON ROOT admin
            throw new InvalidParameterValueException("Non ROOT admins cannot access system's offering");
        }
        if (domainId != null) {
            sc.addAnd("domainId", Op.FIND_IN_SET, String.valueOf(domainId));
        }
    }
    if (keyword != null) {
        SearchCriteria<ServiceOfferingJoinVO> ssc = _srvOfferingJoinDao.createSearchCriteria();
        ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("name", SearchCriteria.Op.SC, ssc);
    }
    if (id != null) {
        sc.addAnd("id", SearchCriteria.Op.EQ, id);
    }
    if (isSystem != null) {
        // note that for non-root users, isSystem is always false when
        // control comes to here
        sc.addAnd("systemUse", SearchCriteria.Op.EQ, isSystem);
    }
    if (name != null) {
        sc.addAnd("name", SearchCriteria.Op.EQ, name);
    }
    if (vmTypeStr != null) {
        sc.addAnd("vmType", SearchCriteria.Op.EQ, vmTypeStr);
    }
    if (zoneId != null) {
        SearchBuilder<ServiceOfferingJoinVO> sb = _srvOfferingJoinDao.createSearchBuilder();
        sb.and("zoneId", sb.entity().getZoneId(), Op.FIND_IN_SET);
        sb.or("zId", sb.entity().getZoneId(), Op.NULL);
        sb.done();
        SearchCriteria<ServiceOfferingJoinVO> zoneSC = sb.create();
        zoneSC.setParameters("zoneId", String.valueOf(zoneId));
        sc.addAnd("zoneId", SearchCriteria.Op.SC, zoneSC);
    }
    if (cpuNumber != null) {
        SearchCriteria<ServiceOfferingJoinVO> cpuConstraintSearchCriteria = _srvOfferingJoinDao.createSearchCriteria();
        cpuConstraintSearchCriteria.addAnd("minCpu", Op.LTEQ, cpuNumber);
        cpuConstraintSearchCriteria.addAnd("maxCpu", Op.GTEQ, cpuNumber);
        SearchCriteria<ServiceOfferingJoinVO> cpuSearchCriteria = _srvOfferingJoinDao.createSearchCriteria();
        cpuSearchCriteria.addOr("minCpu", Op.NULL);
        cpuSearchCriteria.addOr("constraints", Op.SC, cpuConstraintSearchCriteria);
        cpuSearchCriteria.addOr("minCpu", Op.GTEQ, cpuNumber);
        sc.addAnd("cpuConstraints", SearchCriteria.Op.SC, cpuSearchCriteria);
    }
    if (memory != null) {
        SearchCriteria<ServiceOfferingJoinVO> memoryConstraintSearchCriteria = _srvOfferingJoinDao.createSearchCriteria();
        memoryConstraintSearchCriteria.addAnd("minMemory", Op.LTEQ, memory);
        memoryConstraintSearchCriteria.addAnd("maxMemory", Op.GTEQ, memory);
        SearchCriteria<ServiceOfferingJoinVO> memSearchCriteria = _srvOfferingJoinDao.createSearchCriteria();
        memSearchCriteria.addOr("minMemory", Op.NULL);
        memSearchCriteria.addOr("memconstraints", Op.SC, memoryConstraintSearchCriteria);
        memSearchCriteria.addOr("minMemory", Op.GTEQ, memory);
        sc.addAnd("memoryConstraints", SearchCriteria.Op.SC, memSearchCriteria);
    }
    if (cpuSpeed != null) {
        SearchCriteria<ServiceOfferingJoinVO> cpuSpeedSearchCriteria = _srvOfferingJoinDao.createSearchCriteria();
        cpuSpeedSearchCriteria.addOr("speed", Op.NULL);
        cpuSpeedSearchCriteria.addOr("speed", Op.GTEQ, cpuSpeed);
        sc.addAnd("cpuspeedconstraints", SearchCriteria.Op.SC, cpuSpeedSearchCriteria);
    }
    // Fetch the offering ids from the details table since theres no smart way to filter them in the join ... yet!
    if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
        Domain callerDomain = _domainDao.findById(caller.getDomainId());
        List<Long> domainIds = findRelatedDomainIds(callerDomain, isRecursive);
        List<Long> ids = _srvOfferingDetailsDao.findOfferingIdsByDomainIds(domainIds);
        SearchBuilder<ServiceOfferingJoinVO> sb = _srvOfferingJoinDao.createSearchBuilder();
        if (ids != null && !ids.isEmpty()) {
            sb.and("id", sb.entity().getId(), Op.IN);
        }
        sb.or("domainId", sb.entity().getDomainId(), Op.NULL);
        sb.done();
        SearchCriteria<ServiceOfferingJoinVO> scc = sb.create();
        if (ids != null && !ids.isEmpty()) {
            scc.setParameters("id", ids.toArray());
        }
        sc.addAnd("domainId", SearchCriteria.Op.SC, scc);
    }
    if (currentVmOffering != null) {
        DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(currentVmOffering.getDiskOfferingId());
        List<String> storageTags = com.cloud.utils.StringUtils.csvTagsToList(diskOffering.getTags());
        if (!storageTags.isEmpty() && VolumeApiServiceImpl.MatchStoragePoolTagsWithDiskOffering.value()) {
            SearchBuilder<ServiceOfferingJoinVO> sb = _srvOfferingJoinDao.createSearchBuilder();
            for (String tag : storageTags) {
                sb.and(tag, sb.entity().getTags(), Op.FIND_IN_SET);
            }
            sb.done();
            SearchCriteria<ServiceOfferingJoinVO> scc = sb.create();
            for (String tag : storageTags) {
                scc.setParameters(tag, tag);
            }
            sc.addAnd("storageTags", SearchCriteria.Op.SC, scc);
        }
        List<String> hostTags = com.cloud.utils.StringUtils.csvTagsToList(currentVmOffering.getHostTag());
        if (!hostTags.isEmpty()) {
            SearchBuilder<ServiceOfferingJoinVO> sb = _srvOfferingJoinDao.createSearchBuilder();
            for (String tag : hostTags) {
                sb.and(tag, sb.entity().getHostTag(), Op.FIND_IN_SET);
            }
            sb.done();
            SearchCriteria<ServiceOfferingJoinVO> scc = sb.create();
            for (String tag : hostTags) {
                scc.setParameters(tag, tag);
            }
            sc.addAnd("hostTags", SearchCriteria.Op.SC, scc);
        }
    }
    return _srvOfferingJoinDao.searchAndCount(sc, searchFilter);
}
Also used : Account(com.cloud.user.Account) UserVmVO(com.cloud.vm.UserVmVO) ServiceOfferingJoinVO(com.cloud.api.query.vo.ServiceOfferingJoinVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) Domain(com.cloud.domain.Domain)

Example 5 with ServiceOfferingJoinVO

use of com.cloud.api.query.vo.ServiceOfferingJoinVO in project cloudstack by apache.

the class UserVmManagerImpl method createVirtualMachine.

@Override
public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, StorageUnavailableException, ResourceAllocationException {
    // Verify that all objects exist before passing them to the service
    Account owner = _accountService.getActiveAccountById(cmd.getEntityOwnerId());
    verifyDetails(cmd.getDetails());
    Long zoneId = cmd.getZoneId();
    DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
    if (zone == null) {
        throw new InvalidParameterValueException("Unable to find zone by id=" + zoneId);
    }
    Long serviceOfferingId = cmd.getServiceOfferingId();
    Long overrideDiskOfferingId = cmd.getOverrideDiskOfferingId();
    ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
    if (serviceOffering == null) {
        throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
    }
    if (serviceOffering.getDiskOfferingStrictness() && overrideDiskOfferingId != null) {
        throw new InvalidParameterValueException(String.format("Cannot override disk offering id %d since provided service offering is strictly mapped to its disk offering", overrideDiskOfferingId));
    }
    if (!serviceOffering.isDynamic()) {
        for (String detail : cmd.getDetails().keySet()) {
            if (detail.equalsIgnoreCase(VmDetailConstants.CPU_NUMBER) || detail.equalsIgnoreCase(VmDetailConstants.CPU_SPEED) || detail.equalsIgnoreCase(VmDetailConstants.MEMORY)) {
                throw new InvalidParameterValueException("cpuNumber or cpuSpeed or memory should not be specified for static service offering");
            }
        }
    }
    Long templateId = cmd.getTemplateId();
    boolean dynamicScalingEnabled = cmd.isDynamicScalingEnabled();
    VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
    // Make sure a valid template ID was specified
    if (template == null) {
        throw new InvalidParameterValueException("Unable to use template " + templateId);
    }
    ServiceOfferingJoinVO svcOffering = serviceOfferingJoinDao.findById(serviceOfferingId);
    if (template.isDeployAsIs()) {
        if (svcOffering != null && svcOffering.getRootDiskSize() != null && svcOffering.getRootDiskSize() > 0) {
            throw new InvalidParameterValueException("Failed to deploy Virtual Machine as a service offering with root disk size specified cannot be used with a deploy as-is template");
        }
        if (cmd.getDetails().get("rootdisksize") != null) {
            throw new InvalidParameterValueException("Overriding root disk size isn't supported for VMs deployed from deploy as-is templates");
        }
        // Bootmode and boottype are not supported on VMWare dpeloy-as-is templates (since 4.15)
        if ((cmd.getBootMode() != null || cmd.getBootType() != null)) {
            throw new InvalidParameterValueException("Boot type and boot mode are not supported on VMware, as we honour what is defined in the template.");
        }
    }
    Long diskOfferingId = cmd.getDiskOfferingId();
    DiskOffering diskOffering = null;
    if (diskOfferingId != null) {
        diskOffering = _entityMgr.findById(DiskOffering.class, diskOfferingId);
        if (diskOffering == null) {
            throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
        }
        if (diskOffering.isComputeOnly()) {
            throw new InvalidParameterValueException(String.format("The disk offering id %d provided is directly mapped to a service offering, please provide an individual disk offering", diskOfferingId));
        }
    }
    if (!zone.isLocalStorageEnabled()) {
        DiskOffering diskOfferingMappedInServiceOffering = _entityMgr.findById(DiskOffering.class, serviceOffering.getDiskOfferingId());
        if (diskOfferingMappedInServiceOffering.isUseLocalStorage()) {
            throw new InvalidParameterValueException("Zone is not configured to use local storage but disk offering " + diskOfferingMappedInServiceOffering.getName() + " mapped in service offering uses it");
        }
        if (diskOffering != null && diskOffering.isUseLocalStorage()) {
            throw new InvalidParameterValueException("Zone is not configured to use local storage but disk offering " + diskOffering.getName() + " uses it");
        }
    }
    List<Long> networkIds = cmd.getNetworkIds();
    LinkedHashMap<Integer, Long> userVmNetworkMap = getVmOvfNetworkMapping(zone, owner, template, cmd.getVmNetworkMap());
    if (MapUtils.isNotEmpty(userVmNetworkMap)) {
        networkIds = new ArrayList<>(userVmNetworkMap.values());
    }
    Account caller = CallContext.current().getCallingAccount();
    Long callerId = caller.getId();
    boolean isRootAdmin = _accountService.isRootAdmin(callerId);
    Long hostId = cmd.getHostId();
    getDestinationHost(hostId, isRootAdmin, true);
    String ipAddress = cmd.getIpAddress();
    String ip6Address = cmd.getIp6Address();
    String macAddress = cmd.getMacAddress();
    String name = cmd.getName();
    String displayName = cmd.getDisplayName();
    UserVm vm = null;
    IpAddresses addrs = new IpAddresses(ipAddress, ip6Address, macAddress);
    Long size = cmd.getSize();
    String group = cmd.getGroup();
    String userData = cmd.getUserData();
    String sshKeyPairName = cmd.getSSHKeyPairName();
    Boolean displayVm = cmd.isDisplayVm();
    String keyboard = cmd.getKeyboard();
    Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap = cmd.getDataDiskTemplateToDiskOfferingMap();
    Map<String, String> userVmOVFProperties = cmd.getVmProperties();
    if (zone.getNetworkType() == NetworkType.Basic) {
        if (networkIds != null) {
            throw new InvalidParameterValueException("Can't specify network Ids in Basic zone");
        } else {
            vm = createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, getSecurityGroupIdList(cmd), owner, name, displayName, diskOfferingId, size, group, cmd.getHypervisor(), cmd.getHttpMethod(), userData, sshKeyPairName, cmd.getIpToNetworkMap(), addrs, displayVm, keyboard, cmd.getAffinityGroupIdList(), cmd.getDetails(), cmd.getCustomId(), cmd.getDhcpOptionsMap(), dataDiskTemplateToDiskOfferingMap, userVmOVFProperties, dynamicScalingEnabled, overrideDiskOfferingId);
        }
    } else {
        if (zone.isSecurityGroupEnabled()) {
            vm = createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, networkIds, getSecurityGroupIdList(cmd), owner, name, displayName, diskOfferingId, size, group, cmd.getHypervisor(), cmd.getHttpMethod(), userData, sshKeyPairName, cmd.getIpToNetworkMap(), addrs, displayVm, keyboard, cmd.getAffinityGroupIdList(), cmd.getDetails(), cmd.getCustomId(), cmd.getDhcpOptionsMap(), dataDiskTemplateToDiskOfferingMap, userVmOVFProperties, dynamicScalingEnabled, overrideDiskOfferingId);
        } else {
            if (cmd.getSecurityGroupIdList() != null && !cmd.getSecurityGroupIdList().isEmpty()) {
                throw new InvalidParameterValueException("Can't create vm with security groups; security group feature is not enabled per zone");
            }
            vm = createAdvancedVirtualMachine(zone, serviceOffering, template, networkIds, owner, name, displayName, diskOfferingId, size, group, cmd.getHypervisor(), cmd.getHttpMethod(), userData, sshKeyPairName, cmd.getIpToNetworkMap(), addrs, displayVm, keyboard, cmd.getAffinityGroupIdList(), cmd.getDetails(), cmd.getCustomId(), cmd.getDhcpOptionsMap(), dataDiskTemplateToDiskOfferingMap, userVmOVFProperties, dynamicScalingEnabled, null, overrideDiskOfferingId);
        }
    }
    // check if this templateId has a child ISO
    List<VMTemplateVO> child_templates = _templateDao.listByParentTemplatetId(templateId);
    for (VMTemplateVO tmpl : child_templates) {
        if (tmpl.getFormat() == Storage.ImageFormat.ISO) {
            s_logger.info("MDOV trying to attach disk to the VM " + tmpl.getId() + " vmid=" + vm.getId());
            _tmplService.attachIso(tmpl.getId(), vm.getId(), true);
        }
    }
    // Add extraConfig to user_vm_details table
    String extraConfig = cmd.getExtraConfig();
    if (StringUtils.isNotBlank(extraConfig)) {
        if (EnableAdditionalVmConfig.valueIn(callerId)) {
            s_logger.info("Adding extra configuration to user vm: " + vm.getUuid());
            addExtraConfig(vm, extraConfig);
        } else {
            throw new InvalidParameterValueException("attempted setting extraconfig but enable.additional.vm.configuration is disabled");
        }
    }
    if (cmd.getCopyImageTags()) {
        VMTemplateVO templateOrIso = _templateDao.findById(templateId);
        if (templateOrIso != null) {
            final ResourceTag.ResourceObjectType templateType = (templateOrIso.getFormat() == ImageFormat.ISO) ? ResourceTag.ResourceObjectType.ISO : ResourceTag.ResourceObjectType.Template;
            final List<? extends ResourceTag> resourceTags = resourceTagDao.listBy(templateId, templateType);
            for (ResourceTag resourceTag : resourceTags) {
                final ResourceTagVO copyTag = new ResourceTagVO(resourceTag.getKey(), resourceTag.getValue(), resourceTag.getAccountId(), resourceTag.getDomainId(), vm.getId(), ResourceTag.ResourceObjectType.UserVm, resourceTag.getCustomer(), vm.getUuid());
                resourceTagDao.persist(copyTag);
            }
        }
    }
    return vm;
}
Also used : Account(com.cloud.user.Account) DiskOffering(com.cloud.offering.DiskOffering) VMTemplateVO(com.cloud.storage.VMTemplateVO) UserVm(com.cloud.uservm.UserVm) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceTagVO(com.cloud.tags.ResourceTagVO) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServiceOfferingJoinVO(com.cloud.api.query.vo.ServiceOfferingJoinVO) ServiceOffering(com.cloud.offering.ServiceOffering) IpAddresses(com.cloud.network.Network.IpAddresses) DataCenter(com.cloud.dc.DataCenter) ResourceTag(com.cloud.server.ResourceTag)

Aggregations

ServiceOfferingJoinVO (com.cloud.api.query.vo.ServiceOfferingJoinVO)7 Account (com.cloud.user.Account)3 ArrayList (java.util.ArrayList)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)2 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)2 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)2 Filter (com.cloud.utils.db.Filter)2 UserVmVO (com.cloud.vm.UserVmVO)2 VMInstanceVO (com.cloud.vm.VMInstanceVO)2 DiskOfferingJoinVO (com.cloud.api.query.vo.DiskOfferingJoinVO)1 DataCenter (com.cloud.dc.DataCenter)1 Domain (com.cloud.domain.Domain)1 DomainVO (com.cloud.domain.DomainVO)1 CloudAuthenticationException (com.cloud.exception.CloudAuthenticationException)1 IpAddresses (com.cloud.network.Network.IpAddresses)1 DiskOffering (com.cloud.offering.DiskOffering)1 ServiceOffering (com.cloud.offering.ServiceOffering)1 ResourceTag (com.cloud.server.ResourceTag)1 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)1