Search in sources :

Example 1 with NetworkOverviewTO

use of com.cloud.legacymodel.to.NetworkOverviewTO in project cosmic by MissionCriticalCloud.

the class AdvancedNetworkVisitor method visit.

@Override
public boolean visit(final StaticRoutesRules staticRoutesRules) throws ResourceUnavailableException {
    final VirtualRouter router = staticRoutesRules.getRouter();
    final Commands cmds = new Commands(Command.OnError.Continue);
    final NetworkOverviewTO networkOverview = _commandSetupHelper.createNetworkOverviewFromRouter(router, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), null, null, null);
    final UpdateNetworkOverviewCommand updateNetworkOverviewCommand = _commandSetupHelper.createUpdateNetworkOverviewCommand(router, networkOverview);
    cmds.addCommand(updateNetworkOverviewCommand);
    return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
}
Also used : Commands(com.cloud.agent.manager.Commands) NetworkOverviewTO(com.cloud.legacymodel.to.NetworkOverviewTO) UpdateNetworkOverviewCommand(com.cloud.legacymodel.communication.command.UpdateNetworkOverviewCommand) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter)

Example 2 with NetworkOverviewTO

use of com.cloud.legacymodel.to.NetworkOverviewTO in project cosmic by MissionCriticalCloud.

the class AdvancedNetworkVisitor method visit.

@Override
public boolean visit(final PrivateGatewayRules privateGW) throws ResourceUnavailableException {
    final VirtualRouter router = privateGW.getRouter();
    final NicProfile nicProfile = privateGW.getNicProfile();
    final boolean add = privateGW.isAddOperation();
    if (router.getState() == State.Running) {
        final PrivateIpVO ipVO = privateGW.retrivePrivateIP(this);
        final Network network = privateGW.retrievePrivateNetwork(this);
        final String netmask = NetUtils.getCidrNetmask(network.getCidr());
        final PrivateIpAddress ip = new PrivateIpAddress(ipVO, network.getBroadcastUri().toString(), network.getGateway(), netmask, nicProfile.getMacAddress());
        final Commands cmds = new Commands(Command.OnError.Stop);
        final List<Ip> ipsToExclude = new ArrayList<>();
        if (!add) {
            ipsToExclude.add(new Ip(NetUtils.ip2Long(ip.getIpAddress())));
        }
        final NetworkOverviewTO networkOverview = _commandSetupHelper.createNetworkOverviewFromRouter(router, new ArrayList<>(), ipsToExclude, new ArrayList<>(), null, null, null);
        final UpdateNetworkOverviewCommand updateNetworkOverviewCommand = _commandSetupHelper.createUpdateNetworkOverviewCommand(router, networkOverview);
        cmds.addCommand(updateNetworkOverviewCommand);
        try {
            if (_networkGeneralHelper.sendCommandsToRouter(router, cmds)) {
                s_logger.debug("Successfully applied ip association for ip " + ip + " in vpc network " + network);
                return true;
            } else {
                s_logger.warn("Failed to associate ip address " + ip + " in vpc network " + network);
                return false;
            }
        } catch (final Exception ex) {
            s_logger.warn("Failed to send  " + (add ? "add " : "delete ") + " private network " + network + " commands to rotuer ");
            return false;
        }
    } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
        s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending setup private network command to the backend");
    } else {
        s_logger.warn("Unable to setup private gateway, virtual router " + router + " is not in the right state " + router.getState());
        throw new ResourceUnavailableException("Unable to setup Private gateway on the backend," + " virtual router " + router + " is not in the right state", DataCenter.class, router.getDataCenterId());
    }
    return true;
}
Also used : PrivateIpAddress(com.cloud.network.vpc.PrivateIpAddress) Ip(com.cloud.legacymodel.network.Ip) ArrayList(java.util.ArrayList) PrivateIpVO(com.cloud.network.vpc.PrivateIpVO) UpdateNetworkOverviewCommand(com.cloud.legacymodel.communication.command.UpdateNetworkOverviewCommand) NicProfile(com.cloud.vm.NicProfile) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) DataCenter(com.cloud.legacymodel.dc.DataCenter) Network(com.cloud.legacymodel.network.Network) Commands(com.cloud.agent.manager.Commands) NetworkOverviewTO(com.cloud.legacymodel.to.NetworkOverviewTO) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException)

Example 3 with NetworkOverviewTO

use of com.cloud.legacymodel.to.NetworkOverviewTO in project cosmic by MissionCriticalCloud.

the class AdvancedNetworkVisitor method visit.

@Override
public boolean visit(final VpcIpAssociationRules vpcip) throws ResourceUnavailableException {
    final VirtualRouter router = vpcip.getRouter();
    final Commands cmds = new Commands(Command.OnError.Continue);
    final List<PublicIpAddress> ipsToSend = vpcip.getIpsToSend();
    if (!ipsToSend.isEmpty()) {
        final List<Ip> ipsToExclude = new ArrayList<>();
        _commandSetupHelper.findIpsToExclude(ipsToSend, ipsToExclude);
        final NetworkOverviewTO networkOverview = _commandSetupHelper.createNetworkOverviewFromRouter(router, new ArrayList<>(), ipsToExclude, new ArrayList<>(), null, null, null);
        final UpdateNetworkOverviewCommand updateNetworkOverviewCommand = _commandSetupHelper.createUpdateNetworkOverviewCommand(router, networkOverview);
        updateNetworkOverviewCommand.setPlugNics(true);
        cmds.addCommand(updateNetworkOverviewCommand);
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    } else {
        return true;
    }
}
Also used : PublicIpAddress(com.cloud.network.PublicIpAddress) Ip(com.cloud.legacymodel.network.Ip) Commands(com.cloud.agent.manager.Commands) ArrayList(java.util.ArrayList) NetworkOverviewTO(com.cloud.legacymodel.to.NetworkOverviewTO) UpdateNetworkOverviewCommand(com.cloud.legacymodel.communication.command.UpdateNetworkOverviewCommand) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter)

Example 4 with NetworkOverviewTO

use of com.cloud.legacymodel.to.NetworkOverviewTO in project cosmic by MissionCriticalCloud.

the class CommandSetupHelper method createNetworkOverviewFromRouter.

public NetworkOverviewTO createNetworkOverviewFromRouter(final VirtualRouter router, final List<Nic> nicsToExclude, final List<Ip> ipsToExclude, final List<StaticRouteProfile> staticRoutesToExclude, final RemoteAccessVpn remoteAccessVpnToExclude, final Site2SiteVpnConnection site2siteVpnToExclude, final LoadBalancer loadBalancerExclude) {
    final NetworkOverviewTO networkOverviewTO = new NetworkOverviewTO();
    final List<NetworkOverviewTO.InterfaceTO> interfacesTO = new ArrayList<>();
    final NetworkOverviewTO.ServiceTO servicesTO = new NetworkOverviewTO.ServiceTO();
    final List<NetworkOverviewTO.ServiceTO.ServiceSourceNatTO> serviceSourceNatsTO = new ArrayList<>();
    configureInterfacesAndIps(router, nicsToExclude, ipsToExclude, networkOverviewTO, interfacesTO, serviceSourceNatsTO);
    configureStaticRoutes(router, staticRoutesToExclude, networkOverviewTO);
    servicesTO.setSourceNat(serviceSourceNatsTO.toArray(new NetworkOverviewTO.ServiceTO.ServiceSourceNatTO[serviceSourceNatsTO.size()]));
    networkOverviewTO.setServices(servicesTO);
    final NetworkOverviewTO.VPNTO vpnTO = new NetworkOverviewTO.VPNTO();
    configureRemoteAccessVpn(router, remoteAccessVpnToExclude, vpnTO);
    configureSite2SiteVpn(router, site2siteVpnToExclude, vpnTO);
    networkOverviewTO.setVpn(vpnTO);
    configureSyslog(router, networkOverviewTO);
    final NetworkOverviewTO.LoadBalancerTO loadBalancerTO = new NetworkOverviewTO.LoadBalancerTO();
    configureLoadBalancer(router, loadBalancerTO);
    networkOverviewTO.setLoadbalancer(loadBalancerTO);
    return networkOverviewTO;
}
Also used : NetworkOverviewTO(com.cloud.legacymodel.to.NetworkOverviewTO) ArrayList(java.util.ArrayList) LoadBalancerTO(com.cloud.legacymodel.to.LoadBalancerTO)

Example 5 with NetworkOverviewTO

use of com.cloud.legacymodel.to.NetworkOverviewTO in project cosmic by MissionCriticalCloud.

the class CommandSetupHelper method configureSyslog.

private void configureSyslog(final VirtualRouter router, final NetworkOverviewTO networkOverviewTO) {
    final Vpc vpc = _vpcDao.findById(router.getVpcId());
    if (StringUtils.isNotBlank(vpc.getSyslogServerList())) {
        final NetworkOverviewTO.SyslogTO syslogTO = new NetworkOverviewTO.SyslogTO();
        syslogTO.setServers(vpc.getSyslogServerList().split(","));
        networkOverviewTO.setSyslog(syslogTO);
    }
}
Also used : Vpc(com.cloud.legacymodel.network.vpc.Vpc) NetworkOverviewTO(com.cloud.legacymodel.to.NetworkOverviewTO)

Aggregations

NetworkOverviewTO (com.cloud.legacymodel.to.NetworkOverviewTO)16 UpdateNetworkOverviewCommand (com.cloud.legacymodel.communication.command.UpdateNetworkOverviewCommand)14 Commands (com.cloud.agent.manager.Commands)13 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)9 ArrayList (java.util.ArrayList)8 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)6 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)6 ConfigurationException (javax.naming.ConfigurationException)6 DataCenter (com.cloud.legacymodel.dc.DataCenter)5 Ip (com.cloud.legacymodel.network.Ip)5 Network (com.cloud.legacymodel.network.Network)5 VirtualRouter (com.cloud.legacymodel.network.VirtualRouter)5 Vpc (com.cloud.legacymodel.network.vpc.Vpc)4 UpdateVmOverviewCommand (com.cloud.legacymodel.communication.command.UpdateVmOverviewCommand)2 Nic (com.cloud.legacymodel.network.Nic)2 LoadBalancerTO (com.cloud.legacymodel.to.LoadBalancerTO)2 PublicIpAddress (com.cloud.network.PublicIpAddress)2 PrivateIpAddress (com.cloud.network.vpc.PrivateIpAddress)2 PrivateIpVO (com.cloud.network.vpc.PrivateIpVO)2 DomainRouterVO (com.cloud.vm.DomainRouterVO)2