Search in sources :

Example 26 with VirtualMachine

use of com.cloud.vm.VirtualMachine in project cloudstack by apache.

the class ConsoleProxyServlet method handleAuthRequest.

private void handleAuthRequest(HttpServletRequest req, HttpServletResponse resp, long vmId) {
    // TODO authentication channel between console proxy VM and management server needs to be secured,
    // the data is now being sent through private network, but this is apparently not enough
    VirtualMachine vm = _vmMgr.findById(vmId);
    if (vm == null) {
        s_logger.warn("VM " + vmId + " does not exist, sending failed response for authentication request from console proxy");
        sendResponse(resp, "failed");
        return;
    }
    if (vm.getHostId() == null) {
        s_logger.warn("VM " + vmId + " lost host info, failed response for authentication request from console proxy");
        sendResponse(resp, "failed");
        return;
    }
    HostVO host = _ms.getHostBy(vm.getHostId());
    if (host == null) {
        s_logger.warn("VM " + vmId + "'s host does not exist, sending failed response for authentication request from console proxy");
        sendResponse(resp, "failed");
        return;
    }
    String sid = req.getParameter("sid");
    if (sid == null || !sid.equals(vm.getVncPassword())) {
        s_logger.warn("sid " + sid + " in url does not match stored sid.");
        sendResponse(resp, "failed");
        return;
    }
    sendResponse(resp, "success");
}
Also used : HostVO(com.cloud.host.HostVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 27 with VirtualMachine

use of com.cloud.vm.VirtualMachine in project cloudstack by apache.

the class DeploymentPlanningManagerImpl method checkForNonDedicatedResources.

private void checkForNonDedicatedResources(VirtualMachineProfile vmProfile, DataCenter dc, ExcludeList avoids) {
    boolean isExplicit = false;
    VirtualMachine vm = vmProfile.getVirtualMachine();
    // check if zone is dedicated. if yes check if vm owner has access to it.
    DedicatedResourceVO dedicatedZone = _dedicatedDao.findByZoneId(dc.getId());
    if (dedicatedZone != null && !_accountMgr.isRootAdmin(vmProfile.getOwner().getId())) {
        long accountDomainId = vmProfile.getOwner().getDomainId();
        long accountId = vmProfile.getOwner().getAccountId();
        // account will be to use explicit dedication affinity group.
        if (dedicatedZone.getAccountId() != null) {
            if (dedicatedZone.getAccountId().equals(accountId)) {
                return;
            } else {
                throw new CloudRuntimeException("Failed to deploy VM, Zone " + dc.getName() + " not available for the user account " + vmProfile.getOwner());
            }
        }
        // domain level dedication group
        if (!_affinityGroupService.isAffinityGroupAvailableInDomain(dedicatedZone.getAffinityGroupId(), accountDomainId)) {
            throw new CloudRuntimeException("Failed to deploy VM, Zone " + dc.getName() + " not available for the user domain " + vmProfile.getOwner());
        }
    }
    // check affinity group of type Explicit dedication exists. If No put
    // dedicated pod/cluster/host in avoid list
    List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), "ExplicitDedication");
    if (vmGroupMappings != null && !vmGroupMappings.isEmpty()) {
        isExplicit = true;
    }
    List<Long> allPodsInDc = _podDao.listAllPods(dc.getId());
    List<Long> allDedicatedPods = _dedicatedDao.listAllPods();
    allPodsInDc.retainAll(allDedicatedPods);
    List<Long> allClustersInDc = _clusterDao.listAllClusters(dc.getId());
    List<Long> allDedicatedClusters = _dedicatedDao.listAllClusters();
    allClustersInDc.retainAll(allDedicatedClusters);
    List<Long> allHostsInDc = _hostDao.listAllHosts(dc.getId());
    List<Long> allDedicatedHosts = _dedicatedDao.listAllHosts();
    allHostsInDc.retainAll(allDedicatedHosts);
    //Only when the type is instance VM and not explicitly dedicated.
    if (vm.getType() == VirtualMachine.Type.User && !isExplicit) {
        //add explicitly dedicated resources in avoidList
        avoids.addPodList(allPodsInDc);
        avoids.addClusterList(allClustersInDc);
        avoids.addHostList(allHostsInDc);
    }
    //No need to check the isExplicit. As both the cases are handled.
    if (vm.getType() == VirtualMachine.Type.DomainRouter) {
        long vmAccountId = vm.getAccountId();
        long vmDomainId = vm.getDomainId();
        //Lists all explicitly dedicated resources from vm account ID or domain ID.
        List<Long> allPodsFromDedicatedID = new ArrayList<Long>();
        List<Long> allClustersFromDedicatedID = new ArrayList<Long>();
        List<Long> allHostsFromDedicatedID = new ArrayList<Long>();
        //Whether the dedicated resources belong to Domain or not. If not, it may belongs to Account or no dedication.
        List<AffinityGroupDomainMapVO> domainGroupMappings = _affinityGroupDomainMapDao.listByDomain(vmDomainId);
        //For temporary storage and indexing.
        List<DedicatedResourceVO> tempStorage;
        if (domainGroupMappings == null || domainGroupMappings.isEmpty()) {
            //The dedicated resource belongs to VM Account ID.
            tempStorage = _dedicatedDao.searchDedicatedPods(null, vmDomainId, vmAccountId, null).first();
            for (DedicatedResourceVO vo : tempStorage) {
                allPodsFromDedicatedID.add(vo.getPodId());
            }
            tempStorage.clear();
            tempStorage = _dedicatedDao.searchDedicatedClusters(null, vmDomainId, vmAccountId, null).first();
            for (DedicatedResourceVO vo : tempStorage) {
                allClustersFromDedicatedID.add(vo.getClusterId());
            }
            tempStorage.clear();
            tempStorage = _dedicatedDao.searchDedicatedHosts(null, vmDomainId, vmAccountId, null).first();
            for (DedicatedResourceVO vo : tempStorage) {
                allHostsFromDedicatedID.add(vo.getHostId());
            }
            //Remove the dedicated ones from main list
            allPodsInDc.removeAll(allPodsFromDedicatedID);
            allClustersInDc.removeAll(allClustersFromDedicatedID);
            allHostsInDc.removeAll(allHostsFromDedicatedID);
        } else {
            //The dedicated resource belongs to VM Domain ID or No dedication.
            tempStorage = _dedicatedDao.searchDedicatedPods(null, vmDomainId, null, null).first();
            for (DedicatedResourceVO vo : tempStorage) {
                allPodsFromDedicatedID.add(vo.getPodId());
            }
            tempStorage.clear();
            tempStorage = _dedicatedDao.searchDedicatedClusters(null, vmDomainId, null, null).first();
            for (DedicatedResourceVO vo : tempStorage) {
                allClustersFromDedicatedID.add(vo.getClusterId());
            }
            tempStorage.clear();
            tempStorage = _dedicatedDao.searchDedicatedHosts(null, vmDomainId, null, null).first();
            for (DedicatedResourceVO vo : tempStorage) {
                allHostsFromDedicatedID.add(vo.getHostId());
            }
            //Remove the dedicated ones from main list
            allPodsInDc.removeAll(allPodsFromDedicatedID);
            allClustersInDc.removeAll(allClustersFromDedicatedID);
            allHostsInDc.removeAll(allHostsFromDedicatedID);
        }
        //Add in avoid list or no addition if no dedication
        avoids.addPodList(allPodsInDc);
        avoids.addClusterList(allClustersInDc);
        avoids.addHostList(allHostsInDc);
    }
}
Also used : AffinityGroupVMMapVO(org.apache.cloudstack.affinity.AffinityGroupVMMapVO) ArrayList(java.util.ArrayList) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) AffinityGroupDomainMapVO(org.apache.cloudstack.affinity.AffinityGroupDomainMapVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 28 with VirtualMachine

use of com.cloud.vm.VirtualMachine in project cloudstack by apache.

the class FirstFitPlanner method scanClustersForDestinationInZoneOrPod.

private List<Long> scanClustersForDestinationInZoneOrPod(long id, boolean isZone, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) {
    VirtualMachine vm = vmProfile.getVirtualMachine();
    ServiceOffering offering = vmProfile.getServiceOffering();
    DataCenter dc = dcDao.findById(vm.getDataCenterId());
    int requiredCpu = offering.getCpu() * offering.getSpeed();
    long requiredRam = offering.getRamSize() * 1024L * 1024L;
    //list clusters under this zone by cpu and ram capacity
    Pair<List<Long>, Map<Long, Double>> clusterCapacityInfo = listClustersByCapacity(id, requiredCpu, requiredRam, avoid, isZone);
    List<Long> prioritizedClusterIds = clusterCapacityInfo.first();
    if (!prioritizedClusterIds.isEmpty()) {
        if (avoid.getClustersToAvoid() != null) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Removing from the clusterId list these clusters from avoid set: " + avoid.getClustersToAvoid());
            }
            prioritizedClusterIds.removeAll(avoid.getClustersToAvoid());
        }
        if (!isRootAdmin(vmProfile)) {
            List<Long> disabledClusters = new ArrayList<Long>();
            if (isZone) {
                disabledClusters = listDisabledClusters(plan.getDataCenterId(), null);
            } else {
                disabledClusters = listDisabledClusters(plan.getDataCenterId(), id);
            }
            if (!disabledClusters.isEmpty()) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Removing from the clusterId list these clusters that are disabled/clusters under disabled pods: " + disabledClusters);
                }
                prioritizedClusterIds.removeAll(disabledClusters);
            }
        }
        removeClustersCrossingThreshold(prioritizedClusterIds, avoid, vmProfile, plan);
        String hostTagOnOffering = offering.getHostTag();
        if (hostTagOnOffering != null) {
            removeClustersWithoutMatchingTag(prioritizedClusterIds, hostTagOnOffering);
        }
    } else {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("No clusters found having a host with enough capacity, returning.");
        }
        return null;
    }
    if (!prioritizedClusterIds.isEmpty()) {
        List<Long> clusterList = reorderClusters(id, isZone, clusterCapacityInfo, vmProfile, plan);
        //return checkClustersforDestination(clusterList, vmProfile, plan, avoid, dc);
        return clusterList;
    } else {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("No clusters found after removing disabled clusters and clusters in avoid list, returning.");
        }
        return null;
    }
}
Also used : DataCenter(com.cloud.dc.DataCenter) ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 29 with VirtualMachine

use of com.cloud.vm.VirtualMachine in project cloudstack by apache.

the class FirstFitPlanner method removeClustersCrossingThreshold.

/**
     * This method should remove the clusters crossing capacity threshold to avoid further vm allocation on it.
     * @param clusterListForVmAllocation
     * @param avoid
     * @param vmProfile
     * @param plan
     */
protected void removeClustersCrossingThreshold(List<Long> clusterListForVmAllocation, ExcludeList avoid, VirtualMachineProfile vmProfile, DeploymentPlan plan) {
    // Check if cluster threshold for cpu/memory has to be checked or not. By default we
    // always check cluster threshold isn't crossed. However, the check may be skipped for
    // starting (not deploying) an instance.
    VirtualMachine vm = vmProfile.getVirtualMachine();
    Map<String, String> details = vmDetailsDao.listDetailsKeyPairs(vm.getId());
    Boolean isThresholdEnabled = ClusterThresholdEnabled.value();
    if (!(isThresholdEnabled || (details != null && details.containsKey("deployvm")))) {
        return;
    }
    List<Short> capacityList = getCapacitiesForCheckingThreshold();
    List<Long> clustersCrossingThreshold = new ArrayList<Long>();
    ServiceOffering offering = vmProfile.getServiceOffering();
    int cpu_requested = offering.getCpu() * offering.getSpeed();
    long ram_requested = offering.getRamSize() * 1024L * 1024L;
    // remove it from the clusterList that will be used for vm allocation.
    for (short capacity : capacityList) {
        if (clusterListForVmAllocation == null || clusterListForVmAllocation.size() == 0) {
            return;
        }
        if (capacity == Capacity.CAPACITY_TYPE_CPU) {
            clustersCrossingThreshold = capacityDao.listClustersCrossingThreshold(capacity, plan.getDataCenterId(), ClusterCPUCapacityDisableThreshold.key(), cpu_requested);
        } else if (capacity == Capacity.CAPACITY_TYPE_MEMORY) {
            clustersCrossingThreshold = capacityDao.listClustersCrossingThreshold(capacity, plan.getDataCenterId(), ClusterMemoryCapacityDisableThreshold.key(), ram_requested);
        }
        if (clustersCrossingThreshold != null && clustersCrossingThreshold.size() != 0) {
            // addToAvoid Set
            avoid.addClusterList(clustersCrossingThreshold);
            // Remove clusters crossing disabled threshold
            clusterListForVmAllocation.removeAll(clustersCrossingThreshold);
            s_logger.debug("Cannot allocate cluster list " + clustersCrossingThreshold.toString() + " for vm creation since their allocated percentage" + " crosses the disable capacity threshold defined at each cluster/ at global value for capacity Type : " + capacity + ", skipping these clusters");
        }
    }
}
Also used : ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 30 with VirtualMachine

use of com.cloud.vm.VirtualMachine in project cloudstack by apache.

the class SecurityGroupManagerImpl method isVmSecurityGroupEnabled.

@Override
public boolean isVmSecurityGroupEnabled(Long vmId) {
    VirtualMachine vm = _vmDao.findByIdIncludingRemoved(vmId);
    List<NicProfile> nics = _networkMgr.getNicProfiles(vm);
    for (NicProfile nic : nics) {
        Network network = _networkModel.getNetwork(nic.getNetworkId());
        if (_networkModel.isSecurityGroupSupportedInNetwork(network) && vm.getHypervisorType() != HypervisorType.VMware) {
            return true;
        }
    }
    return false;
}
Also used : Network(com.cloud.network.Network) NicProfile(com.cloud.vm.NicProfile) VirtualMachine(com.cloud.vm.VirtualMachine)

Aggregations

VirtualMachine (com.cloud.vm.VirtualMachine)65 ArrayList (java.util.ArrayList)17 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)16 HostVO (com.cloud.host.HostVO)15 DataCenter (com.cloud.dc.DataCenter)10 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)10 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)10 ServiceOffering (com.cloud.offering.ServiceOffering)9 HashMap (java.util.HashMap)9 List (java.util.List)9 ServerApiException (org.apache.cloudstack.api.ServerApiException)9 Test (org.junit.Test)9 Host (com.cloud.host.Host)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 ServerApiException (com.cloud.api.ServerApiException)7 NicProfile (com.cloud.vm.NicProfile)7 VMInstanceVO (com.cloud.vm.VMInstanceVO)7 SystemVmResponse (org.apache.cloudstack.api.response.SystemVmResponse)7 SystemVmResponse (com.cloud.api.response.SystemVmResponse)6 ManagementServerException (com.cloud.exception.ManagementServerException)6