Search in sources :

Example 81 with DomainRouterVO

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

the class BasicNetworkTopology method configDhcpForSubnet.

@Override
public boolean configDhcpForSubnet(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest, final List<DomainRouterVO> routers) throws ResourceUnavailableException {
    s_logger.debug("CONFIG DHCP FOR SUBNETS RULES");
    // Assuming we have only one router per network For Now.
    final DomainRouterVO router = routers.get(0);
    if (router.getState() != State.Running) {
        s_logger.warn("Failed to configure dhcp: router not in running state");
        throw new ResourceUnavailableException("Unable to assign ip addresses, domR is not in right state " + router.getState(), DataCenter.class, network.getDataCenterId());
    }
    final DhcpSubNetRules subNetRules = new DhcpSubNetRules(network, nic, profile);
    return subNetRules.accept(_basicVisitor, router);
}
Also used : DhcpSubNetRules(com.cloud.network.rules.DhcpSubNetRules) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 82 with DomainRouterVO

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

the class OvsNetworkTopologyGuruImpl method getActiveVmsInNetworkOnHost.

/**
     * get the list of all Vm id's in the network that are running on the host
     */
@Override
public List<Long> getActiveVmsInNetworkOnHost(long networkId, long hostId, boolean includeVr) {
    List<Long> vmIds = new ArrayList<>();
    List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(networkId, VirtualMachine.State.Running, VirtualMachine.State.Migrating);
    // Find routers for the network
    List<DomainRouterVO> routers = _routerDao.findByNetwork(networkId);
    if (vms != null) {
        for (UserVmVO vm : vms) {
            if (vm.getHostId() == hostId)
                vmIds.add(vm.getId());
        }
    }
    if (routers.size() != 0 && includeVr) {
        for (DomainRouterVO router : routers) {
            if (router.getHostId() == hostId)
                vmIds.add(router.getId());
        }
    }
    return vmIds;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) ArrayList(java.util.ArrayList) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 83 with DomainRouterVO

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

the class OvsNetworkTopologyGuruImpl method getAllActiveVmsInNetwork.

/**
     * get the list of all active Vm id's in a network
     */
@Override
public List<Long> getAllActiveVmsInNetwork(long networkId) {
    List<Long> vmIds = new ArrayList<>();
    List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(networkId, VirtualMachine.State.Running, VirtualMachine.State.Starting, VirtualMachine.State.Stopping, VirtualMachine.State.Unknown, VirtualMachine.State.Migrating);
    // Find routers for the network
    List<DomainRouterVO> routers = _routerDao.findByNetwork(networkId);
    if (vms != null) {
        for (UserVmVO vm : vms) {
            vmIds.add(vm.getId());
        }
    }
    if (routers.size() != 0) {
        for (DomainRouterVO router : routers) {
            vmIds.add(router.getId());
        }
    }
    return vmIds;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) ArrayList(java.util.ArrayList) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 84 with DomainRouterVO

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

the class OvsElement method applyStaticNats.

@Override
public boolean applyStaticNats(final Network network, final List<? extends StaticNat> rules) throws ResourceUnavailableException {
    if (!canHandle(network, Service.StaticNat)) {
        return false;
    }
    final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
    if (routers == null || routers.isEmpty()) {
        s_logger.debug("Ovs element doesn't need to apply static nat on the backend; virtual " + "router doesn't exist in the network " + network.getId());
        return true;
    }
    final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
    final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(dcVO);
    boolean result = true;
    for (final DomainRouterVO domainRouterVO : routers) {
        result = result && networkTopology.applyStaticNats(network, rules, domainRouterVO);
    }
    return result;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 85 with DomainRouterVO

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

the class OvsNetworkTopologyGuruImpl method getNetworkSpanedHosts.

/**
     * get the list of hypervisor hosts on which VM's belonging to a network currently spans
     */
public List<Long> getNetworkSpanedHosts(long networkId) {
    List<Long> hostIds = new ArrayList<Long>();
    // Find active VMs with a NIC on the target network
    List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(networkId, VirtualMachine.State.Running, VirtualMachine.State.Starting, VirtualMachine.State.Stopping, VirtualMachine.State.Unknown, VirtualMachine.State.Migrating);
    // Find routers for the network
    List<DomainRouterVO> routers = _routerDao.findByNetwork(networkId);
    List<VMInstanceVO> ins = new ArrayList<VMInstanceVO>();
    if (vms != null) {
        ins.addAll(vms);
    }
    if (routers.size() != 0) {
        ins.addAll(routers);
    }
    for (VMInstanceVO v : ins) {
        Long rh = v.getHostId();
        if (rh == null) {
            continue;
        }
        if (!hostIds.contains(rh)) {
            hostIds.add(rh);
        }
    }
    return hostIds;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

DomainRouterVO (com.cloud.vm.DomainRouterVO)148 ArrayList (java.util.ArrayList)39 DataCenterVO (com.cloud.dc.DataCenterVO)33 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)33 NetworkTopology (org.apache.cloudstack.network.topology.NetworkTopology)27 Test (org.junit.Test)26 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)24 Network (com.cloud.network.Network)20 NicProfile (com.cloud.vm.NicProfile)17 Account (com.cloud.user.Account)12 NetworkVO (com.cloud.network.dao.NetworkVO)11 Answer (com.cloud.agent.api.Answer)10 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)10 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)10 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)10 UserVmVO (com.cloud.vm.UserVmVO)9 Vpc (com.cloud.network.vpc.Vpc)8 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)8 UserVO (com.cloud.user.UserVO)8 HashMap (java.util.HashMap)8