Search in sources :

Example 21 with NetworkTopology

use of org.apache.cloudstack.network.topology.NetworkTopology in project cloudstack by apache.

the class VpcVirtualRouterElement method applyVpnUsers.

@Override
public String[] applyVpnUsers(final RemoteAccessVpn vpn, final List<? extends VpnUser> users) throws ResourceUnavailableException {
    final Long vpcId = vpn.getVpcId();
    if (vpcId == null) {
        return null;
    }
    final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(vpcId);
    if (routers == null) {
        s_logger.debug("Cannot apply vpn users on the backend; virtual router doesn't exist in the network " + vpcId);
        return null;
    }
    final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId);
    final DataCenterVO dcVO = _dcDao.findById(vpc.getZoneId());
    final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
    String[] result = null;
    final List<String> combinedResults = new ArrayList<String>();
    for (final DomainRouterVO domainRouterVO : routers) {
        result = networkTopology.applyVpnUsers(vpn, users, domainRouterVO);
        combinedResults.addAll(Arrays.asList(result));
    }
    result = new String[combinedResults.size()];
    final Object[] resultCast = combinedResults.toArray();
    System.arraycopy(resultCast, 0, result, 0, resultCast.length);
    return result;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) Vpc(com.cloud.network.vpc.Vpc) ArrayList(java.util.ArrayList) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 22 with NetworkTopology

use of org.apache.cloudstack.network.topology.NetworkTopology in project cloudstack by apache.

the class VirtualRouterElement method applyDhcpEntries.

protected boolean applyDhcpEntries(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final Network.Service service) throws ResourceUnavailableException {
    boolean result = true;
    if (canHandle(network, service)) {
        if (vm.getType() != VirtualMachine.Type.User) {
            return false;
        }
        final VirtualMachineProfile uservm = vm;
        final List<DomainRouterVO> routers = getRouters(network, dest);
        if (routers == null || routers.size() == 0) {
            throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
        }
        final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
        for (final DomainRouterVO domainRouterVO : routers) {
            result = result && networkTopology.applyDhcpEntry(network, nic, uservm, dest, domainRouterVO);
        }
    }
    return result;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 23 with NetworkTopology

use of org.apache.cloudstack.network.topology.NetworkTopology in project cloudstack by apache.

the class VirtualRouterElement method saveSSHKey.

@Override
public boolean saveSSHKey(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final String sshPublicKey) throws ResourceUnavailableException {
    if (!canHandle(network, null)) {
        return false;
    }
    final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
    if (routers == null || routers.isEmpty()) {
        s_logger.debug("Can't find virtual router element in network " + network.getId());
        return true;
    }
    final VirtualMachineProfile uservm = vm;
    final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
    final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
    boolean result = true;
    for (final DomainRouterVO domainRouterVO : routers) {
        result = result && networkTopology.saveSSHPublicKeyToRouter(network, nic, uservm, domainRouterVO, sshPublicKey);
    }
    return result;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 24 with NetworkTopology

use of org.apache.cloudstack.network.topology.NetworkTopology in project cloudstack by apache.

the class VpcVirtualRouterElement method applyACLItemsToPrivateGw.

@Override
public boolean applyACLItemsToPrivateGw(final PrivateGateway gateway, final List<? extends NetworkACLItem> rules) throws ResourceUnavailableException {
    final Network network = _networkDao.findById(gateway.getNetworkId());
    final boolean isPrivateGateway = true;
    final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(gateway.getVpcId());
    if (routers == null || routers.isEmpty()) {
        s_logger.debug("Virtual router element doesn't need to apply network acl rules 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);
    final Network privateNetwork = _networkModel.getNetwork(gateway.getNetworkId());
    boolean result = true;
    for (final DomainRouterVO domainRouterVO : routers) {
        final NicProfile nicProfile = _networkModel.getNicProfile(domainRouterVO, privateNetwork.getId(), null);
        if (nicProfile != null) {
            result = result && networkTopology.applyNetworkACLs(network, rules, domainRouterVO, isPrivateGateway);
        } else {
            s_logger.warn("Nic Profile for router '" + domainRouterVO + "' has already been removed. Router is redundant = " + domainRouterVO.getIsRedundantRouter());
        }
    }
    return result;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Network(com.cloud.network.Network) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) NicProfile(com.cloud.vm.NicProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 25 with NetworkTopology

use of org.apache.cloudstack.network.topology.NetworkTopology in project cloudstack by apache.

the class OvsElement method applyPFRules.

@Override
public boolean applyPFRules(final Network network, final List<PortForwardingRule> rules) throws ResourceUnavailableException {
    if (!canHandle(network, Service.PortForwarding)) {
        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 firewall rules on the backend; virtual " + "router doesn't exist in the network " + network.getId());
        return true;
    }
    boolean result = true;
    final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
    final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(dcVO);
    for (final DomainRouterVO domainRouterVO : routers) {
        result = result && networkTopology.applyFirewallRules(network, rules, domainRouterVO);
    }
    return result;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

DataCenterVO (com.cloud.dc.DataCenterVO)27 DomainRouterVO (com.cloud.vm.DomainRouterVO)27 NetworkTopology (org.apache.cloudstack.network.topology.NetworkTopology)27 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)10 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)6 Network (com.cloud.network.Network)5 UserVmVO (com.cloud.vm.UserVmVO)4 Service (com.cloud.network.Network.Service)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 NicProfile (com.cloud.vm.NicProfile)3 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)2 Nic (com.cloud.vm.Nic)2 ArrayList (java.util.ArrayList)2 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1 Answer (com.cloud.agent.api.Answer)1 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)1 CheckS2SVpnConnectionsAnswer (com.cloud.agent.api.CheckS2SVpnConnectionsAnswer)1 GetDomRVersionAnswer (com.cloud.agent.api.GetDomRVersionAnswer)1 GetRouterAlertsAnswer (com.cloud.agent.api.GetRouterAlertsAnswer)1