Search in sources :

Example 76 with DataCenter

use of com.cloud.dc.DataCenter in project cloudstack by apache.

the class FirstFitPlanner method orderClusters.

@Override
public List<Long> orderClusters(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException {
    VirtualMachine vm = vmProfile.getVirtualMachine();
    DataCenter dc = dcDao.findById(vm.getDataCenterId());
    //check if datacenter is in avoid set
    if (avoid.shouldAvoid(dc)) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("DataCenter id = '" + dc.getId() + "' provided is in avoid set, DeploymentPlanner cannot allocate the VM, returning.");
        }
        return null;
    }
    List<Long> clusterList = new ArrayList<Long>();
    if (plan.getClusterId() != null) {
        Long clusterIdSpecified = plan.getClusterId();
        s_logger.debug("Searching resources only under specified Cluster: " + clusterIdSpecified);
        ClusterVO cluster = clusterDao.findById(plan.getClusterId());
        if (cluster != null) {
            if (avoid.shouldAvoid(cluster)) {
                s_logger.debug("The specified cluster is in avoid set, returning.");
            } else {
                clusterList.add(clusterIdSpecified);
                removeClustersCrossingThreshold(clusterList, avoid, vmProfile, plan);
            }
        } else {
            s_logger.debug("The specified cluster cannot be found, returning.");
            avoid.addCluster(plan.getClusterId());
            return null;
        }
    } else if (plan.getPodId() != null) {
        //consider clusters under this pod only
        Long podIdSpecified = plan.getPodId();
        s_logger.debug("Searching resources only under specified Pod: " + podIdSpecified);
        HostPodVO pod = podDao.findById(podIdSpecified);
        if (pod != null) {
            if (avoid.shouldAvoid(pod)) {
                s_logger.debug("The specified pod is in avoid set, returning.");
            } else {
                clusterList = scanClustersForDestinationInZoneOrPod(podIdSpecified, false, vmProfile, plan, avoid);
                if (clusterList == null) {
                    avoid.addPod(plan.getPodId());
                }
            }
        } else {
            s_logger.debug("The specified Pod cannot be found, returning.");
            avoid.addPod(plan.getPodId());
            return null;
        }
    } else {
        s_logger.debug("Searching all possible resources under this Zone: " + plan.getDataCenterId());
        boolean applyAllocationAtPods = Boolean.parseBoolean(configDao.getValue(Config.ApplyAllocationAlgorithmToPods.key()));
        if (applyAllocationAtPods) {
            //start scan at all pods under this zone.
            clusterList = scanPodsForDestination(vmProfile, plan, avoid);
        } else {
            //start scan at clusters under this zone.
            clusterList = scanClustersForDestinationInZoneOrPod(plan.getDataCenterId(), true, vmProfile, plan, avoid);
        }
    }
    if (clusterList != null && !clusterList.isEmpty()) {
        ServiceOffering offering = vmProfile.getServiceOffering();
        // In case of non-GPU VMs, protect GPU enabled Hosts and prefer VM deployment on non-GPU Hosts.
        if ((serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.vgpuType.toString()) == null) && !(hostGpuGroupsDao.listHostIds().isEmpty())) {
            int requiredCpu = offering.getCpu() * offering.getSpeed();
            long requiredRam = offering.getRamSize() * 1024L * 1024L;
            reorderClustersBasedOnImplicitTags(clusterList, requiredCpu, requiredRam);
        }
    }
    return clusterList;
}
Also used : DataCenter(com.cloud.dc.DataCenter) ClusterVO(com.cloud.dc.ClusterVO) ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) HostPodVO(com.cloud.dc.HostPodVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 77 with DataCenter

use of com.cloud.dc.DataCenter in project cloudstack by apache.

the class NuageVspGuestNetworkGuru method design.

@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
    PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId());
    DataCenter dc = _dcDao.findById(plan.getDataCenterId());
    if (!canHandle(offering, dc.getNetworkType(), physnet)) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Refusing to design network using network offering " + offering.getId() + (physnet != null ? " on physical network " + physnet.getId() : ""));
        }
        return null;
    }
    NetworkVO networkObject = (NetworkVO) super.design(offering, plan, userSpecified, owner);
    if (networkObject == null) {
        return null;
    }
    networkObject.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
    return networkObject;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) DataCenter(com.cloud.dc.DataCenter) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO)

Example 78 with DataCenter

use of com.cloud.dc.DataCenter in project cloudstack by apache.

the class NuageVspGuestNetworkGuru method reserve.

@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    boolean lockedNetwork = lockNetworkForUserVm(network, vm);
    if (lockedNetwork && s_logger.isDebugEnabled()) {
        s_logger.debug("Locked network " + network.getId() + " for creation of user VM " + vm.getInstanceName());
    }
    try {
        //We don't support a shared network with UserData and multiple IP ranges at the same time.
        checkMultipleSubnetsCombinedWithUseData(network);
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
        }
        DataCenter dc = _dcDao.findById(network.getDataCenterId());
        AccountVO neworkAccountDetails = _accountDao.findById(network.getAccountId());
        if (neworkAccountDetails.getType() == Account.ACCOUNT_TYPE_PROJECT) {
            throw new InsufficientVirtualNetworkCapacityException("CS project support is not yet implemented in NuageVsp", DataCenter.class, dc.getId());
        }
        if (Strings.isNullOrEmpty(network.getBroadcastUri().getPath()) || !network.getBroadcastUri().getPath().startsWith("/")) {
            throw new IllegalStateException("The broadcast URI path " + network.getBroadcastUri() + " is empty or in an incorrect format.");
        }
        HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(network.getPhysicalNetworkId());
        VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(vm.getVirtualMachine().getDomainId(), network);
        if (vspNetwork.isShared()) {
            vspNetwork = _nuageVspEntityBuilder.updateVspNetworkByPublicIp(vspNetwork, network, nic.getIPv4Address());
            if (VirtualMachine.Type.DomainRouter.equals(vm.getType()) && !nic.getIPv4Address().equals(vspNetwork.getVirtualRouterIp())) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("VR got spawned with a different IP, releasing the previously allocated public IP " + nic.getIPv4Address());
                }
                IPAddressVO oldIpAddress = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), nic.getIPv4Address());
                _ipAddressDao.unassignIpAddress(oldIpAddress.getId());
                _ipAddressDao.mark(network.getDataCenterId(), new Ip(vspNetwork.getVirtualRouterIp()));
            } else if (VirtualMachine.Type.User.equals(vm.getType()) && nic.getIPv4Address().equals(vspNetwork.getVirtualRouterIp())) {
                s_logger.error("Deploying a user VM with the same IP as the VR is not allowed.");
                throw new InsufficientVirtualNetworkCapacityException("Deploying a user VM with the same IP " + nic.getIPv4Address() + " as the VR is not allowed.", Network.class, network.getId());
            }
            // Make sure the shared network is present
            NetworkOffering offering = _ntwkOfferingDao.findById(network.getNetworkOfferingId());
            if (!implement(network.getPhysicalNetworkId(), vspNetwork, _nuageVspEntityBuilder.buildNetworkDhcpOption(network, offering))) {
                s_logger.error("Failed to implement shared network " + network.getUuid() + " under domain " + context.getDomain().getUuid());
                throw new InsufficientVirtualNetworkCapacityException("Failed to implement shared network " + network.getUuid() + " under domain " + context.getDomain().getUuid(), Network.class, network.getId());
            }
        }
        // Set flags for dhcp options
        boolean networkHasDns = networkHasDns(network);
        Map<Long, Boolean> networkHasDnsCache = Maps.newHashMap();
        networkHasDnsCache.put(network.getId(), networkHasDns);
        // Determine if dhcp options of the other nics in the network need to be updated
        if (vm.getType() == VirtualMachine.Type.DomainRouter && network.getState() != State.Implementing) {
            updateDhcpOptionsForExistingVms(network, nuageVspHost, vspNetwork, networkHasDns, networkHasDnsCache);
        }
        nic.setBroadcastUri(network.getBroadcastUri());
        nic.setIsolationUri(network.getBroadcastUri());
        //NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
        //that we create in VSP
        NicVO nicFromDb = _nicDao.findById(nic.getId());
        IPAddressVO staticNatIp = _ipAddressDao.findByVmIdAndNetworkId(network.getId(), vm.getId());
        VspVm vspVm = _nuageVspEntityBuilder.buildVspVm(vm.getVirtualMachine(), network);
        VspNic vspNic = _nuageVspEntityBuilder.buildVspNic(nicFromDb.getUuid(), nic);
        VspStaticNat vspStaticNat = null;
        if (staticNatIp != null) {
            VlanVO staticNatVlan = _vlanDao.findById(staticNatIp.getVlanId());
            vspStaticNat = _nuageVspEntityBuilder.buildVspStaticNat(null, staticNatIp, staticNatVlan, null);
        }
        boolean defaultHasDns = getDefaultHasDns(networkHasDnsCache, nicFromDb);
        VspDhcpVMOption dhcpOption = _nuageVspEntityBuilder.buildVmDhcpOption(nicFromDb, defaultHasDns, networkHasDns);
        ReserveVmInterfaceVspCommand cmd = new ReserveVmInterfaceVspCommand(vspNetwork, vspVm, vspNic, vspStaticNat, dhcpOption);
        Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("ReserveVmInterfaceNuageVspCommand failed for NIC " + nic.getId() + " attached to VM " + vm.getId() + " in network " + network.getId());
            if ((null != answer) && (null != answer.getDetails())) {
                s_logger.error(answer.getDetails());
            }
            throw new InsufficientVirtualNetworkCapacityException("Failed to reserve VM in Nuage VSP.", Network.class, network.getId());
        }
        if (vspVm.getDomainRouter() == Boolean.TRUE) {
            nic.setIPv4Address(vspVm.getDomainRouterIp());
        }
    } finally {
        if (network != null && lockedNetwork) {
            _networkDao.releaseFromLockTable(network.getId());
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Unlocked network " + network.getId() + " for creation of user VM " + vm.getInstanceName());
            }
        }
    }
}
Also used : NetworkOffering(com.cloud.offering.NetworkOffering) Ip(com.cloud.utils.net.Ip) VspStaticNat(net.nuage.vsp.acs.client.api.model.VspStaticNat) ReserveVmInterfaceVspCommand(com.cloud.agent.api.guru.ReserveVmInterfaceVspCommand) AccountVO(com.cloud.user.AccountVO) HostVO(com.cloud.host.HostVO) Answer(com.cloud.agent.api.Answer) DataCenter(com.cloud.dc.DataCenter) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) Network(com.cloud.network.Network) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) PhysicalNetwork(com.cloud.network.PhysicalNetwork) IPAddressVO(com.cloud.network.dao.IPAddressVO) VspVm(net.nuage.vsp.acs.client.api.model.VspVm) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) VspNic(net.nuage.vsp.acs.client.api.model.VspNic) VlanVO(com.cloud.dc.VlanVO) NicVO(com.cloud.vm.NicVO) VspDhcpVMOption(net.nuage.vsp.acs.client.api.model.VspDhcpVMOption)

Example 79 with DataCenter

use of com.cloud.dc.DataCenter in project cloudstack by apache.

the class ConsoleProxyManagerImpl method finalizeDeployment.

@Override
public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
    finalizeCommandsOnStart(cmds, profile);
    ConsoleProxyVO proxy = _consoleProxyDao.findById(profile.getId());
    DataCenter dc = dest.getDataCenter();
    List<NicProfile> nics = profile.getNics();
    for (NicProfile nic : nics) {
        if ((nic.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced) || (nic.getTrafficType() == TrafficType.Guest && (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()))) {
            proxy.setPublicIpAddress(nic.getIPv4Address());
            proxy.setPublicNetmask(nic.getIPv4Netmask());
            proxy.setPublicMacAddress(nic.getMacAddress());
        } else if (nic.getTrafficType() == TrafficType.Management) {
            proxy.setPrivateIpAddress(nic.getIPv4Address());
            proxy.setPrivateMacAddress(nic.getMacAddress());
        }
    }
    _consoleProxyDao.update(proxy.getId(), proxy);
    return true;
}
Also used : DataCenter(com.cloud.dc.DataCenter) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) NicProfile(com.cloud.vm.NicProfile)

Example 80 with DataCenter

use of com.cloud.dc.DataCenter in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method startRouter.

@Override
public VirtualRouter startRouter(final long routerId, final boolean reprogramNetwork) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException {
    final Account caller = CallContext.current().getCallingAccount();
    final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
    // verify parameters
    DomainRouterVO router = _routerDao.findById(routerId);
    //clean up the update_state feild
    if (router.getUpdateState() == VirtualRouter.UpdateState.UPDATE_FAILED) {
        router.setUpdateState(null);
        _routerDao.update(router.getId(), router);
    }
    if (router == null) {
        throw new InvalidParameterValueException("Unable to find router by id " + routerId + ".");
    }
    _accountMgr.checkAccess(caller, null, true, router);
    final Account owner = _accountMgr.getAccount(router.getAccountId());
    // Check if all networks are implemented for the domR; if not -
    // implement them
    final DataCenter dc = _dcDao.findById(router.getDataCenterId());
    HostPodVO pod = null;
    if (router.getPodIdToDeployIn() != null) {
        pod = _podDao.findById(router.getPodIdToDeployIn());
    }
    final DeployDestination dest = new DeployDestination(dc, pod, null, null);
    final ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
    final List<NicVO> nics = _nicDao.listByVmId(routerId);
    for (final NicVO nic : nics) {
        if (!_networkMgr.startNetwork(nic.getNetworkId(), dest, context)) {
            s_logger.warn("Failed to start network id=" + nic.getNetworkId() + " as a part of domR start");
            throw new CloudRuntimeException("Failed to start network id=" + nic.getNetworkId() + " as a part of domR start");
        }
    }
    // After start network, check if it's already running
    router = _routerDao.findById(routerId);
    if (router.getState() == VirtualMachine.State.Running) {
        return router;
    }
    final UserVO user = _userDao.findById(CallContext.current().getCallingUserId());
    final Map<Param, Object> params = new HashMap<Param, Object>();
    if (reprogramNetwork) {
        params.put(Param.ReProgramGuestNetworks, true);
    } else {
        params.put(Param.ReProgramGuestNetworks, false);
    }
    final VirtualRouter virtualRouter = _nwHelper.startVirtualRouter(router, user, caller, params);
    if (virtualRouter == null) {
        throw new CloudRuntimeException("Failed to start router with id " + routerId);
    }
    return virtualRouter;
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) HashMap(java.util.HashMap) HostPodVO(com.cloud.dc.HostPodVO) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext) DataCenter(com.cloud.dc.DataCenter) UserVO(com.cloud.user.UserVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DeployDestination(com.cloud.deploy.DeployDestination) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Param(com.cloud.vm.VirtualMachineProfile.Param) NicVO(com.cloud.vm.NicVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

DataCenter (com.cloud.dc.DataCenter)144 Account (com.cloud.user.Account)50 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)37 NetworkVO (com.cloud.network.dao.NetworkVO)33 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)32 Network (com.cloud.network.Network)30 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)27 ArrayList (java.util.ArrayList)27 DeployDestination (com.cloud.deploy.DeployDestination)25 NetworkOffering (com.cloud.offering.NetworkOffering)23 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)17 IPAddressVO (com.cloud.network.dao.IPAddressVO)17 DB (com.cloud.utils.db.DB)17 Domain (com.cloud.domain.Domain)16 ReservationContext (com.cloud.vm.ReservationContext)16 HostVO (com.cloud.host.HostVO)15 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)13 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)13 PhysicalNetwork (com.cloud.network.PhysicalNetwork)11 ServiceOffering (com.cloud.offering.ServiceOffering)11