Search in sources :

Example 6 with RuleApplier

use of com.cloud.network.rules.RuleApplier in project cloudstack by apache.

the class BasicNetworkTopology method savePasswordToRouter.

@Override
public boolean savePasswordToRouter(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final VirtualRouter router) throws ResourceUnavailableException {
    s_logger.debug("SAVE PASSWORD TO ROUTE RULES");
    final String typeString = "save password entry";
    final boolean isPodLevelException = false;
    final boolean failWhenDisconnect = false;
    final Long podId = null;
    final PasswordToRouterRules routerRules = new PasswordToRouterRules(network, nic, profile);
    return applyRules(network, router, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(routerRules));
}
Also used : RuleApplier(com.cloud.network.rules.RuleApplier) PasswordToRouterRules(com.cloud.network.rules.PasswordToRouterRules)

Example 7 with RuleApplier

use of com.cloud.network.rules.RuleApplier in project cloudstack by apache.

the class BasicNetworkTopology method applyFirewallRules.

@Override
public boolean applyFirewallRules(final Network network, final List<? extends FirewallRule> rules, final VirtualRouter router) throws ResourceUnavailableException {
    if (rules == null || rules.isEmpty()) {
        s_logger.debug("No firewall rules to be applied for network " + network.getId());
        return true;
    }
    s_logger.debug("APPLYING FIREWALL RULES");
    final String typeString = "firewall rules";
    final boolean isPodLevelException = false;
    final boolean failWhenDisconnect = false;
    final Long podId = null;
    final FirewallRules firewallRules = new FirewallRules(network, rules);
    return applyRules(network, router, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(firewallRules));
}
Also used : RuleApplier(com.cloud.network.rules.RuleApplier) FirewallRules(com.cloud.network.rules.FirewallRules)

Example 8 with RuleApplier

use of com.cloud.network.rules.RuleApplier in project cosmic by MissionCriticalCloud.

the class BasicNetworkTopology method applyRules.

@Override
public boolean applyRules(final Network network, final VirtualRouter router, final String typeString, final boolean isPodLevelException, final Long podId, final boolean failWhenDisconnect, final RuleApplierWrapper<RuleApplier> ruleApplierWrapper) throws ResourceUnavailableException {
    if (router == null) {
        s_logger.warn("Unable to apply " + typeString + ", virtual router doesn't exist in the network " + network.getId());
        throw new ResourceUnavailableException("Unable to apply " + typeString, DataCenter.class, network.getDataCenterId());
    }
    final RuleApplier ruleApplier = ruleApplierWrapper.getRuleType();
    final DataCenter dc = _dcDao.findById(network.getDataCenterId());
    final boolean isZoneBasic = dc.getNetworkType() == NetworkType.Basic;
    // isPodLevelException and podId is only used for basic zone
    assert !(!isZoneBasic && isPodLevelException || isZoneBasic && isPodLevelException && podId == null);
    final List<VirtualRouter> connectedRouters = new ArrayList<>();
    final List<VirtualRouter> disconnectedRouters = new ArrayList<>();
    boolean result = true;
    final String msg = "Unable to apply " + typeString + " on disconnected router ";
    if (router.getState() == State.Running) {
        s_logger.debug("Applying " + typeString + " in network " + network);
        if (router.isStopPending()) {
            if (_hostDao.findById(router.getHostId()).getState() == Status.Up) {
                throw new ResourceUnavailableException("Unable to process due to the stop pending router " + router.getInstanceName() + " haven't been stopped after it's host coming back!", DataCenter.class, router.getDataCenterId());
            }
            s_logger.debug("Router " + router.getInstanceName() + " is stop pending, so not sending apply " + typeString + " commands to the backend");
            return false;
        }
        try {
            result = ruleApplier.accept(getVisitor(), router);
            connectedRouters.add(router);
        } catch (final AgentUnavailableException e) {
            s_logger.warn(msg + router.getInstanceName(), e);
            disconnectedRouters.add(router);
        }
        // disconnection, no need to proceed with the rest
        if (!result) {
            if (isZoneBasic && isPodLevelException) {
                throw new ResourceUnavailableException("Unable to apply " + typeString + " on router ", Pod.class, podId);
            }
            throw new ResourceUnavailableException("Unable to apply " + typeString + " on router ", DataCenter.class, router.getDataCenterId());
        }
    } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
        s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending apply " + typeString + " commands to the backend");
    } else {
        s_logger.warn("Unable to apply " + typeString + ", virtual router is not in the right state " + router.getState());
        if (isZoneBasic && isPodLevelException) {
            throw new ResourceUnavailableException("Unable to apply " + typeString + ", virtual router is not in the right state", Pod.class, podId);
        }
        throw new ResourceUnavailableException("Unable to apply " + typeString + ", virtual router is not in the right state", DataCenter.class, router.getDataCenterId());
    }
    if (!connectedRouters.isEmpty()) {
        // Shouldn't we include this check inside the method?
        if (!isZoneBasic && !disconnectedRouters.isEmpty()) {
            // now, stop them for synchronization
            for (final VirtualRouter virtualRouter : disconnectedRouters) {
                // If we have at least 1 disconnected redundant router, callhandleSingleWorkingRedundantRouter().
                if (virtualRouter.getIsRedundantRouter()) {
                    _networkHelper.handleSingleWorkingRedundantRouter(connectedRouters, disconnectedRouters, msg);
                    break;
                }
            }
        }
    } else if (!disconnectedRouters.isEmpty()) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug(msg + router.getInstanceName() + "(" + router.getId() + ")");
        }
        if (isZoneBasic && isPodLevelException) {
            throw new ResourceUnavailableException(msg, Pod.class, podId);
        }
        throw new ResourceUnavailableException(msg, DataCenter.class, disconnectedRouters.get(0).getDataCenterId());
    }
    result = true;
    if (failWhenDisconnect) {
        result = !connectedRouters.isEmpty();
    }
    return result;
}
Also used : DataCenter(com.cloud.dc.DataCenter) Pod(com.cloud.dc.Pod) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) RuleApplier(com.cloud.network.rules.RuleApplier) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ArrayList(java.util.ArrayList) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 9 with RuleApplier

use of com.cloud.network.rules.RuleApplier in project cloudstack by apache.

the class AdvancedNetworkTopology method removeDhcpEntry.

@Override
public boolean removeDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile profile, VirtualRouter virtualRouter) throws ResourceUnavailableException {
    s_logger.debug("REMOVE VPC DHCP ENTRY RULES");
    final String typeString = "dhcp entry";
    final Long podId = null;
    final boolean isPodLevelException = false;
    final boolean failWhenDisconnect = false;
    final DhcpEntryRules dhcpRules = new DhcpEntryRules(network, nic, profile, null);
    dhcpRules.setRemove(true);
    return applyRules(network, virtualRouter, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(dhcpRules));
}
Also used : RuleApplier(com.cloud.network.rules.RuleApplier) DhcpEntryRules(com.cloud.network.rules.DhcpEntryRules)

Example 10 with RuleApplier

use of com.cloud.network.rules.RuleApplier in project cloudstack by apache.

the class BasicNetworkTopology method applyDhcpEntry.

@Override
public boolean applyDhcpEntry(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest, final DomainRouterVO router) throws ResourceUnavailableException {
    s_logger.debug("APPLYING DHCP ENTRY RULES");
    final String typeString = "dhcp entry";
    final Long podId = dest.getPod().getId();
    boolean isPodLevelException = false;
    // scope
    if (podId != null && profile.getVirtualMachine().getType() == VirtualMachine.Type.User && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared) {
        isPodLevelException = true;
    }
    final boolean failWhenDisconnect = false;
    final DhcpEntryRules dhcpRules = new DhcpEntryRules(network, nic, profile, dest);
    return applyRules(network, router, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(dhcpRules));
}
Also used : RuleApplier(com.cloud.network.rules.RuleApplier) DhcpEntryRules(com.cloud.network.rules.DhcpEntryRules)

Aggregations

RuleApplier (com.cloud.network.rules.RuleApplier)17 DhcpEntryRules (com.cloud.network.rules.DhcpEntryRules)4 DataCenter (com.cloud.dc.DataCenter)2 Pod (com.cloud.dc.Pod)2 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 VirtualRouter (com.cloud.network.router.VirtualRouter)2 UserdataPwdRules (com.cloud.network.rules.UserdataPwdRules)2 ArrayList (java.util.ArrayList)2 FirewallRules (com.cloud.network.rules.FirewallRules)1 IpAssociationRules (com.cloud.network.rules.IpAssociationRules)1 LoadBalancingRules (com.cloud.network.rules.LoadBalancingRules)1 NetworkAclsRules (com.cloud.network.rules.NetworkAclsRules)1 NicPlugInOutRules (com.cloud.network.rules.NicPlugInOutRules)1 PasswordToRouterRules (com.cloud.network.rules.PasswordToRouterRules)1 SshKeyToRouterRules (com.cloud.network.rules.SshKeyToRouterRules)1 StaticNatRules (com.cloud.network.rules.StaticNatRules)1 UserdataToRouterRules (com.cloud.network.rules.UserdataToRouterRules)1 VpcIpAssociationRules (com.cloud.network.rules.VpcIpAssociationRules)1