Search in sources :

Example 11 with NetworkTopology

use of com.cloud.network.topology.NetworkTopology in project cosmic by MissionCriticalCloud.

the class VirtualNetworkApplianceManagerImpl method finalizeStart.

@Override
public boolean finalizeStart(final VirtualMachineProfile profile, final long hostId, final Commands cmds, final ReservationContext context) {
    final DomainRouterVO router = _routerDao.findById(profile.getId());
    // process all the answers
    for (final Answer answer : cmds.getAnswers()) {
        // handle any command failures
        if (!answer.getResult()) {
            final String cmdClassName = answer.getClass().getCanonicalName().replace("Answer", "Command");
            final String errorMessage = "Command: " + cmdClassName + " failed while starting virtual router";
            final String errorDetails = "Details: " + answer.getDetails() + " " + answer.toString();
            // add alerts for the failed commands
            _alertMgr.sendAlert(AlertService.AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), errorMessage, errorDetails);
            s_logger.error(answer.getDetails());
            s_logger.warn(errorMessage);
            // Stop the router if any of the commands failed
            return false;
        }
    }
    // at this point, all the router command are successful.
    boolean result = true;
    // Get guest networks info
    final List<Network> guestNetworks = new ArrayList<>();
    final List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
    for (final Nic nic : routerNics) {
        final Network network = _networkModel.getNetwork(nic.getNetworkId());
        final Zone zone = zoneRepository.findOne(network.getDataCenterId());
        if (network.getTrafficType() == TrafficType.Guest) {
            guestNetworks.add(network);
            if (nic.getBroadcastUri().getScheme().equals("pvlan")) {
                final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, "pvlan-nic");
                final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(zone);
                try {
                    result = networkTopology.setupDhcpForPvlan(true, router, router.getHostId(), nicProfile);
                } catch (final ResourceUnavailableException e) {
                    s_logger.debug("ERROR in finalizeStart: ", e);
                }
            }
        }
    }
    if (result) {
        final GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer) cmds.getAnswer("getDomRVersion");
        router.setTemplateVersion(versionAnswer.getTemplateVersion());
        router.setScriptsVersion(versionAnswer.getScriptsVersion());
        _routerDao.persist(router, guestNetworks);
    }
    final List<DomainRouterVO> routers = _routerDao.listByVpcId(router.getVpcId());
    for (final DomainRouterVO domainRouterVO : routers) {
        s_logger.info("Updating the redundant state of router " + domainRouterVO);
        updateRoutersRedundantState(domainRouterVO);
    }
    return result;
}
Also used : Zone(com.cloud.db.model.Zone) TimeZone(java.util.TimeZone) ArrayList(java.util.ArrayList) Nic(com.cloud.vm.Nic) NicProfile(com.cloud.vm.NicProfile) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) Network(com.cloud.network.Network) NetworkTopology(com.cloud.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 12 with NetworkTopology

use of com.cloud.network.topology.NetworkTopology in project cosmic by MissionCriticalCloud.

the class VirtualRouterElement method applyVpnUsers.

@Override
public String[] applyVpnUsers(final RemoteAccessVpn vpn, final List<? extends VpnUser> users) throws ResourceUnavailableException {
    if (vpn.getNetworkId() == null) {
        return null;
    }
    final Network network = _networksDao.findById(vpn.getNetworkId());
    if (canHandle(network, Service.Vpn)) {
        final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
        if (routers == null || routers.isEmpty()) {
            s_logger.debug("Virtual router elemnt doesn't need to apply vpn users on the backend; virtual router" + " doesn't exist in the network " + network.getId());
            return null;
        }
        final Zone zone = zoneRepository.findOne(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
        return networkTopology.applyVpnUsers(network, users, routers);
    } else {
        s_logger.debug("Element " + getName() + " doesn't handle applyVpnUsers command");
        return null;
    }
}
Also used : Zone(com.cloud.db.model.Zone) Network(com.cloud.network.Network) NetworkTopology(com.cloud.network.topology.NetworkTopology) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 13 with NetworkTopology

use of com.cloud.network.topology.NetworkTopology in project cosmic by MissionCriticalCloud.

the class VirtualRouterElement method prepareMigration.

@Override
public boolean prepareMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) {
    if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
        return true;
    }
    if (vm.getType() == VirtualMachine.Type.DomainRouter) {
        assert vm instanceof DomainRouterVO;
        final DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine();
        final Zone zone = zoneRepository.findOne(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
        try {
            networkTopology.setupDhcpForPvlan(false, router, router.getHostId(), nic);
        } catch (final ResourceUnavailableException e) {
            s_logger.warn("Timed Out", e);
        }
    } else if (vm.getType() == VirtualMachine.Type.User) {
        assert vm instanceof UserVmVO;
        final UserVmVO userVm = (UserVmVO) vm.getVirtualMachine();
        _userVmMgr.setupVmForPvlan(false, userVm.getHostId(), nic);
    }
    return true;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) Zone(com.cloud.db.model.Zone) NetworkTopology(com.cloud.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 14 with NetworkTopology

use of com.cloud.network.topology.NetworkTopology in project cosmic by MissionCriticalCloud.

the class VirtualRouterElement method applyLBRules.

@Override
public boolean applyLBRules(final Network network, final List<LoadBalancingRule> rules) throws ResourceUnavailableException {
    boolean result = true;
    if (canHandle(network, Service.Lb)) {
        if (!canHandleLbRules(rules)) {
            return false;
        }
        final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
        if (routers == null || routers.isEmpty()) {
            s_logger.debug("Virtual router elemnt doesn't need to apply lb rules on the backend; virtual " + "router doesn't exist in the network " + network.getId());
            return true;
        }
        final Zone zone = zoneRepository.findOne(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
        for (final DomainRouterVO domainRouterVO : routers) {
            result = result && networkTopology.applyLoadBalancingRules(network, rules, domainRouterVO);
        }
    }
    return result;
}
Also used : Zone(com.cloud.db.model.Zone) NetworkTopology(com.cloud.network.topology.NetworkTopology) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 15 with NetworkTopology

use of com.cloud.network.topology.NetworkTopology in project cosmic by MissionCriticalCloud.

the class VirtualRouterElement method applyPFRules.

@Override
public boolean applyPFRules(final Network network, final List<PortForwardingRule> rules) throws ResourceUnavailableException {
    boolean result = true;
    if (canHandle(network, Service.PortForwarding)) {
        final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
        if (routers == null || routers.isEmpty()) {
            s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual " + "router doesn't exist in the network " + network.getId());
            return true;
        }
        final Zone zone = zoneRepository.findOne(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
        for (final DomainRouterVO domainRouterVO : routers) {
            result = result && networkTopology.applyFirewallRules(network, rules, domainRouterVO);
        }
    }
    return result;
}
Also used : Zone(com.cloud.db.model.Zone) NetworkTopology(com.cloud.network.topology.NetworkTopology) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

Zone (com.cloud.db.model.Zone)23 NetworkTopology (com.cloud.network.topology.NetworkTopology)23 DomainRouterVO (com.cloud.vm.DomainRouterVO)23 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)9 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)6 Network (com.cloud.network.Network)5 UserVmVO (com.cloud.vm.UserVmVO)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 NicProfile (com.cloud.vm.NicProfile)3 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 IllegalVirtualMachineException (com.cloud.exception.IllegalVirtualMachineException)2 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)2 Service (com.cloud.network.Network.Service)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 NetworkUsageAnswer (com.cloud.agent.api.NetworkUsageAnswer)1