Search in sources :

Example 1 with NetworkOverviewTO

use of com.cloud.agent.api.to.overviews.NetworkOverviewTO in project cosmic by MissionCriticalCloud.

the class CommandSetupHelper method configureInterfacesAndIps.

private void configureInterfacesAndIps(final VirtualRouter router, final List<Nic> nicsToExclude, final List<Ip> ipsToExclude, final NetworkOverviewTO networkOverviewTO, final List<NetworkOverviewTO.InterfaceTO> interfacesTO, final List<NetworkOverviewTO.ServiceTO.ServiceSourceNatTO> serviceSourceNatsTO) {
    final List<NicVO> nics = _nicDao.listByVmId(router.getId());
    nics.stream().filter(nic -> !nicsToExclude.contains(nic)).forEach(nic -> {
        final NetworkOverviewTO.InterfaceTO interfaceTO = new NetworkOverviewTO.InterfaceTO();
        interfaceTO.setMacAddress(nic.getMacAddress());
        final List<NetworkOverviewTO.InterfaceTO.IPv4AddressTO> ipv4Addresses = new ArrayList<>();
        if (StringUtils.isNotBlank(nic.getIPv4Address()) && StringUtils.isNotBlank(nic.getIPv4Netmask())) {
            ipv4Addresses.add(new NetworkOverviewTO.InterfaceTO.IPv4AddressTO(NetUtils.getIpv4AddressWithCidrSize(nic.getIPv4Address(), nic.getIPv4Netmask()), nic.getIPv4Gateway()));
        }
        final NetworkVO network = _networkDao.findById(nic.getNetworkId());
        if (network != null) {
            final TrafficType trafficType = network.getTrafficType();
            if (TrafficType.Public.equals(trafficType)) {
                ipv4Addresses.addAll(_ipAddressDao.listByVpc(router.getVpcId(), false).stream().filter(ipAddressVO -> !ipsToExclude.contains(ipAddressVO.getAddress()) && ipAddressVO.getAssociatedWithNetworkId() != null).map(ipAddressVO -> {
                    final Ip ip = ipAddressVO.getAddress();
                    final VlanVO vlanVO = _vlanDao.findById(ipAddressVO.getVlanId());
                    return new NetworkOverviewTO.InterfaceTO.IPv4AddressTO(NetUtils.getIpv4AddressWithCidrSize(ip.addr(), vlanVO.getVlanNetmask()), nic.getIPv4Gateway());
                }).collect(Collectors.toList()));
                serviceSourceNatsTO.addAll(_ipAddressDao.listByVpc(router.getVpcId(), true).stream().map(IPAddressVO::getAddress).filter(ip -> !ipsToExclude.contains(ip)).map(Ip::addr).map(ip -> new NetworkOverviewTO.ServiceTO.ServiceSourceNatTO(ip, nic.getIPv4Gateway())).collect(Collectors.toList()));
            }
            interfaceTO.setMetadata(new NetworkOverviewTO.InterfaceTO.MetadataTO(network));
        }
        interfaceTO.setIpv4Addresses(ipv4Addresses.toArray(new NetworkOverviewTO.InterfaceTO.IPv4AddressTO[ipv4Addresses.size()]));
        interfacesTO.add(interfaceTO);
    });
    networkOverviewTO.setInterfaces(interfacesTO.toArray(new NetworkOverviewTO.InterfaceTO[interfacesTO.size()]));
}
Also used : NetworkModel(com.cloud.network.NetworkModel) Site2SiteVpnGatewayDao(com.cloud.network.dao.Site2SiteVpnGatewayDao) NetworkACLTO(com.cloud.agent.api.to.NetworkACLTO) SetPortForwardingRulesVpcCommand(com.cloud.agent.api.routing.SetPortForwardingRulesVpcCommand) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) UpdateNetworkOverviewCommand(com.cloud.agent.api.UpdateNetworkOverviewCommand) Site2SiteVpnGatewayVO(com.cloud.network.dao.Site2SiteVpnGatewayVO) StaticRouteProfile(com.cloud.network.vpc.StaticRouteProfile) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) ServiceOfferingDao(com.cloud.service.dao.ServiceOfferingDao) VlanDao(com.cloud.dc.dao.VlanDao) Map(java.util.Map) TrafficType(com.cloud.network.Networks.TrafficType) ZoneRepository(com.cloud.db.repository.ZoneRepository) StaticNatRule(com.cloud.network.rules.StaticNatRule) NetworkACLItem(com.cloud.network.vpc.NetworkACLItem) URI(java.net.URI) Ip(com.cloud.utils.net.Ip) StaticNatRuleTO(com.cloud.agent.api.to.StaticNatRuleTO) Config(com.cloud.configuration.Config) StringUtils(com.cloud.utils.StringUtils) SavePasswordCommand(com.cloud.agent.api.routing.SavePasswordCommand) NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO) Network(com.cloud.network.Network) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) RemoteAccessVpnVO(com.cloud.network.dao.RemoteAccessVpnVO) Commands(com.cloud.agent.manager.Commands) IpAddress(com.cloud.network.IpAddress) NicVO(com.cloud.vm.NicVO) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) Site2SiteCustomerGatewayVO(com.cloud.network.dao.Site2SiteCustomerGatewayVO) Collectors(java.util.stream.Collectors) SetPublicIpACLCommand(com.cloud.agent.api.routing.SetPublicIpACLCommand) List(java.util.List) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) FirewallRuleTO(com.cloud.agent.api.to.FirewallRuleTO) VpcGateway(com.cloud.network.vpc.VpcGateway) RemoteAccessVpnDao(com.cloud.network.dao.RemoteAccessVpnDao) VirtualMachineManager(com.cloud.vm.VirtualMachineManager) PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) VpnUserDao(com.cloud.network.dao.VpnUserDao) NetUtils(com.cloud.utils.net.NetUtils) NetworkOverviewTO(com.cloud.agent.api.to.overviews.NetworkOverviewTO) NumbersUtil(com.cloud.utils.NumbersUtil) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) VirtualMachine(com.cloud.vm.VirtualMachine) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) StaticNat(com.cloud.network.rules.StaticNat) NetworkElementCommand(com.cloud.agent.api.routing.NetworkElementCommand) BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) FirewallRule(com.cloud.network.rules.FirewallRule) Zone(com.cloud.db.model.Zone) HashMap(java.util.HashMap) SetupVRCommand(com.cloud.agent.api.SetupVRCommand) NetworkDao(com.cloud.network.dao.NetworkDao) Purpose(com.cloud.network.rules.FirewallRule.Purpose) Nic(com.cloud.vm.Nic) NicProfile(com.cloud.vm.NicProfile) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand) VlanVO(com.cloud.dc.VlanVO) ConfigurationDao(com.cloud.framework.config.dao.ConfigurationDao) IPAddressVO(com.cloud.network.dao.IPAddressVO) DomainRouterVO(com.cloud.vm.DomainRouterVO) VMOverviewTO(com.cloud.agent.api.to.overviews.VMOverviewTO) NetworkVO(com.cloud.network.dao.NetworkVO) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) Qualifier(org.springframework.beans.factory.annotation.Qualifier) SetFirewallRulesCommand(com.cloud.agent.api.routing.SetFirewallRulesCommand) Site2SiteVpnConnection(com.cloud.network.Site2SiteVpnConnection) IPAddressDao(com.cloud.network.dao.IPAddressDao) DomainRouterDao(com.cloud.vm.dao.DomainRouterDao) FirewallRulesDao(com.cloud.network.dao.FirewallRulesDao) Site2SiteVpnConnectionDao(com.cloud.network.dao.Site2SiteVpnConnectionDao) NicTO(com.cloud.agent.api.to.NicTO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) NetworkACLItemDao(com.cloud.network.vpc.NetworkACLItemDao) Vpc(com.cloud.network.vpc.Vpc) UpdateVmOverviewCommand(com.cloud.agent.api.UpdateVmOverviewCommand) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) UserVmDao(com.cloud.vm.dao.UserVmDao) NicDao(com.cloud.vm.dao.NicDao) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn) Site2SiteCustomerGatewayDao(com.cloud.network.dao.Site2SiteCustomerGatewayDao) StaticRouteDao(com.cloud.network.vpc.dao.StaticRouteDao) PublicIpAddress(com.cloud.network.PublicIpAddress) NetworkOffering(com.cloud.offering.NetworkOffering) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) UserVmVO(com.cloud.vm.UserVmVO) SetNetworkACLCommand(com.cloud.agent.api.routing.SetNetworkACLCommand) PublicIpACLTO(com.cloud.agent.api.to.PublicIpACLTO) VpcDao(com.cloud.network.vpc.dao.VpcDao) NetworkOfferingDao(com.cloud.offerings.dao.NetworkOfferingDao) VpnUser(com.cloud.network.VpnUser) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) NetworkVO(com.cloud.network.dao.NetworkVO) Ip(com.cloud.utils.net.Ip) ArrayList(java.util.ArrayList) NetworkOverviewTO(com.cloud.agent.api.to.overviews.NetworkOverviewTO) VlanVO(com.cloud.dc.VlanVO) NicVO(com.cloud.vm.NicVO) TrafficType(com.cloud.network.Networks.TrafficType)

Example 2 with NetworkOverviewTO

use of com.cloud.agent.api.to.overviews.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.network.vpc.Vpc) NetworkOverviewTO(com.cloud.agent.api.to.overviews.NetworkOverviewTO)

Example 3 with NetworkOverviewTO

use of com.cloud.agent.api.to.overviews.NetworkOverviewTO in project cosmic by MissionCriticalCloud.

the class VpcVirtualNetworkApplianceManagerImpl method setupVpcPrivateNetwork.

/**
 * @param router
 * @param add
 * @param privateNic
 * @return
 * @throws ResourceUnavailableException
 */
protected boolean setupVpcPrivateNetwork(final VirtualRouter router, final boolean add, final NicProfile privateNic) throws ResourceUnavailableException {
    if (router.getState() == State.Running) {
        final PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(privateNic.getNetworkId(), privateNic.getIPv4Address());
        final Network network = _networkDao.findById(privateNic.getNetworkId());
        final String netmask = NetUtils.getCidrNetmask(network.getCidr());
        String broadcastUri = "";
        if (network.getBroadcastUri() != null) {
            broadcastUri = network.getBroadcastUri().toString();
        }
        final PrivateIpAddress ip = new PrivateIpAddress(ipVO, broadcastUri, network.getGateway(), netmask, privateNic.getMacAddress());
        final Commands cmds = new Commands(Command.OnError.Stop);
        final List<Ip> ipsToExclude = new ArrayList<>();
        if (!add) {
            ipsToExclude.add(new Ip(ip.getIpAddress()));
        }
        final NetworkOverviewTO networkOverview = _commandSetupHelper.createNetworkOverviewFromRouter(router, new ArrayList<>(), ipsToExclude, new ArrayList<>(), null, null);
        final UpdateNetworkOverviewCommand updateNetworkOverviewCommand = _commandSetupHelper.createUpdateNetworkOverviewCommand(router, networkOverview);
        cmds.addCommand(updateNetworkOverviewCommand);
        try {
            if (_nwHelper.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.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) ArrayList(java.util.ArrayList) PrivateIpVO(com.cloud.network.vpc.PrivateIpVO) UpdateNetworkOverviewCommand(com.cloud.agent.api.UpdateNetworkOverviewCommand) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataCenter(com.cloud.dc.DataCenter) Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands) NetworkOverviewTO(com.cloud.agent.api.to.overviews.NetworkOverviewTO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 4 with NetworkOverviewTO

use of com.cloud.agent.api.to.overviews.NetworkOverviewTO in project cosmic by MissionCriticalCloud.

the class VpcVirtualNetworkApplianceManagerImpl method stopRemoteAccessVpn.

@Override
public boolean stopRemoteAccessVpn(final RemoteAccessVpn vpn, final VirtualRouter router) throws ResourceUnavailableException {
    if (router.getState() == State.Running) {
        final Commands cmds = new Commands(Command.OnError.Continue);
        final NetworkOverviewTO networkOverview = _commandSetupHelper.createNetworkOverviewFromRouter(router, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), vpn, null);
        final UpdateNetworkOverviewCommand updateNetworkOverviewCommand = _commandSetupHelper.createUpdateNetworkOverviewCommand(router, networkOverview);
        cmds.addCommand(updateNetworkOverviewCommand);
        try {
            return _nwHelper.sendCommandsToRouter(router, cmds);
        } catch (final Exception ex) {
            return false;
        }
    } else if (router.getState() == State.Stopped) {
        s_logger.debug("Router " + router + " is in Stopped state, not sending deleteRemoteAccessVpn command to it");
    } else {
        s_logger.warn("Failed to delete remote access VPN: domR " + router + " is not in right state " + router.getState());
        throw new ResourceUnavailableException("Failed to delete remote access VPN: domR is not in right state " + router.getState(), DataCenter.class, router.getDataCenterId());
    }
    return true;
}
Also used : DataCenter(com.cloud.dc.DataCenter) Commands(com.cloud.agent.manager.Commands) NetworkOverviewTO(com.cloud.agent.api.to.overviews.NetworkOverviewTO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) UpdateNetworkOverviewCommand(com.cloud.agent.api.UpdateNetworkOverviewCommand) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 5 with NetworkOverviewTO

use of com.cloud.agent.api.to.overviews.NetworkOverviewTO in project cosmic by MissionCriticalCloud.

the class VpcVirtualNetworkApplianceManagerImpl method updateVR.

@Override
public boolean updateVR(final Vpc vpc, final DomainRouterVO router) {
    Commands commands = new Commands(Command.OnError.Stop);
    final NetworkOverviewTO networkOverview = _commandSetupHelper.createNetworkOverviewFromRouter(router, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), null, null);
    final UpdateNetworkOverviewCommand updateNetworkOverviewCommand = _commandSetupHelper.createUpdateNetworkOverviewCommand(router, networkOverview);
    commands.addCommand(updateNetworkOverviewCommand);
    _commandSetupHelper.createVRConfigCommands(vpc, router, commands);
    try {
        if (_nwHelper.sendCommandsToRouter(router, commands)) {
            s_logger.debug("Successfully applied source NAT list on the vpc " + router.getHostName());
            return true;
        } else {
            s_logger.warn("Failed to apply source NAT list on vpc " + router.getHostName());
            return false;
        }
    } catch (final Exception ex) {
        s_logger.warn("Failed to send config update to router " + router.getHostName());
        return false;
    }
}
Also used : Commands(com.cloud.agent.manager.Commands) NetworkOverviewTO(com.cloud.agent.api.to.overviews.NetworkOverviewTO) UpdateNetworkOverviewCommand(com.cloud.agent.api.UpdateNetworkOverviewCommand) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

NetworkOverviewTO (com.cloud.agent.api.to.overviews.NetworkOverviewTO)15 UpdateNetworkOverviewCommand (com.cloud.agent.api.UpdateNetworkOverviewCommand)13 Commands (com.cloud.agent.manager.Commands)12 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)8 ArrayList (java.util.ArrayList)7 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)5 Network (com.cloud.network.Network)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 Ip (com.cloud.utils.net.Ip)5 ConfigurationException (javax.naming.ConfigurationException)5 DataCenter (com.cloud.dc.DataCenter)4 VirtualRouter (com.cloud.network.router.VirtualRouter)4 PrivateIpVO (com.cloud.network.vpc.PrivateIpVO)3 Vpc (com.cloud.network.vpc.Vpc)3 NicProfile (com.cloud.vm.NicProfile)3 UpdateVmOverviewCommand (com.cloud.agent.api.UpdateVmOverviewCommand)2 VMOverviewTO (com.cloud.agent.api.to.overviews.VMOverviewTO)2 PublicIpAddress (com.cloud.network.PublicIpAddress)2 PrivateIpAddress (com.cloud.network.vpc.PrivateIpAddress)2 Nic (com.cloud.vm.Nic)2