Search in sources :

Example 6 with TrafficType

use of com.cloud.model.enumeration.TrafficType in project cosmic by MissionCriticalCloud.

the class SystemVmManagerBase method getNetworkForBasicZone.

protected static NetworkVO getNetworkForBasicZone(final Zone zone, final NetworkDao _networkDao) {
    if (zone.getNetworkType() != NetworkType.Basic) {
        throw new CloudRuntimeException("Zone " + zone + " is not basic.");
    }
    final TrafficType defaultTrafficType = TrafficType.Guest;
    final List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(zone.getId(), defaultTrafficType);
    // api should never allow this situation to happen
    if (defaultNetworks.size() != 1) {
        throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
    }
    return defaultNetworks.get(0);
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) TrafficType(com.cloud.model.enumeration.TrafficType)

Example 7 with TrafficType

use of com.cloud.model.enumeration.TrafficType in project cosmic by MissionCriticalCloud.

the class DomainRouterJoinDaoImpl method newDomainRouterResponse.

@Override
public DomainRouterResponse newDomainRouterResponse(final DomainRouterJoinVO router, final Account caller) {
    final DomainRouterResponse routerResponse = new DomainRouterResponse();
    routerResponse.setId(router.getUuid());
    routerResponse.setZoneId(router.getDataCenterUuid());
    routerResponse.setName(router.getName());
    routerResponse.setTemplateId(router.getTemplateUuid());
    routerResponse.setCreated(router.getCreated());
    routerResponse.setState(router.getState());
    routerResponse.setIsRedundantRouter(router.isRedundantRouter());
    routerResponse.setRedundantState(router.getRedundantState().toString());
    if (router.getLastStartDateTime() != null) {
        routerResponse.setLastStartDateTime(router.getLastStartDateTime());
    }
    if (router.getLastStartVersion() != null) {
        routerResponse.setLastStartVersion(router.getLastStartVersion());
    }
    if (router.getRouterUnicastId() != null) {
        routerResponse.setRouterUnicastId(router.getRouterUnicastId());
    }
    if (router.getTemplateVersion() != null) {
        final String routerVersion = Version.trimRouterVersion(router.getTemplateVersion());
        routerResponse.setVersion(routerVersion);
        routerResponse.setRequiresUpgrade((Version.compare(routerVersion, NetworkOrchestrationService.MinVRVersion.valueIn(router.getDataCenterId())) < 0));
    } else {
        routerResponse.setVersion("UNKNOWN");
        routerResponse.setRequiresUpgrade(true);
    }
    if (_accountMgr.isRootAdmin(caller.getId()) || (_accountMgr.isDomainAdmin(caller.getId()))) {
        if (router.getHostId() != null) {
            routerResponse.setHostId(router.getHostUuid());
            routerResponse.setHostName(router.getHostName());
            routerResponse.setHypervisor(router.getHypervisorType().toString());
        }
        routerResponse.setPodId(router.getPodUuid());
        final long nic_id = router.getNicId();
        if (nic_id > 0) {
            final TrafficType ty = router.getTrafficType();
            if (ty != null) {
                // nics response object
                if (ty == TrafficType.Public) {
                    routerResponse.setPublicIp(router.getIpAddress());
                    routerResponse.setPublicMacAddress(router.getMacAddress());
                    routerResponse.setPublicNetmask(router.getNetmask());
                    routerResponse.setGateway(router.getGateway());
                    routerResponse.setPublicNetworkId(router.getNetworkUuid());
                } else if (ty == TrafficType.Control) {
                    routerResponse.setLinkLocalIp(router.getIpAddress());
                    routerResponse.setLinkLocalMacAddress(router.getMacAddress());
                    routerResponse.setLinkLocalNetmask(router.getNetmask());
                    routerResponse.setLinkLocalNetworkId(router.getNetworkUuid());
                } else if (ty == TrafficType.Guest) {
                    routerResponse.setGuestIpAddress(router.getIpAddress());
                    routerResponse.setGuestMacAddress(router.getMacAddress());
                    routerResponse.setGuestNetmask(router.getNetmask());
                    routerResponse.setGuestNetworkId(router.getNetworkUuid());
                    routerResponse.setGuestNetworkName(router.getNetworkName());
                    routerResponse.setNetworkDomain(router.getNetworkDomain());
                }
            }
            final NicResponse nicResponse = new NicResponse();
            nicResponse.setId(router.getNicUuid());
            nicResponse.setIpaddress(router.getIpAddress());
            nicResponse.setGateway(router.getGateway());
            nicResponse.setNetmask(router.getNetmask());
            nicResponse.setNetworkid(router.getNetworkUuid());
            nicResponse.setNetworkName(router.getNetworkName());
            nicResponse.setMacAddress(router.getMacAddress());
            nicResponse.setIp6Address(router.getIp6Address());
            nicResponse.setIp6Gateway(router.getIp6Gateway());
            nicResponse.setIp6Cidr(router.getIp6Cidr());
            if (router.getBroadcastUri() != null) {
                nicResponse.setBroadcastUri(router.getBroadcastUri().toString());
            }
            if (router.getIsolationUri() != null) {
                nicResponse.setIsolationUri(router.getIsolationUri().toString());
            }
            if (router.getTrafficType() != null) {
                nicResponse.setTrafficType(router.getTrafficType().toString());
            }
            if (router.getGuestType() != null) {
                nicResponse.setType(router.getGuestType().toString());
            }
            nicResponse.setIsDefault(router.isDefaultNic());
            nicResponse.setObjectName("nic");
            routerResponse.addNic(nicResponse);
        }
    }
    routerResponse.setServiceOfferingId(router.getServiceOfferingUuid());
    routerResponse.setServiceOfferingName(router.getServiceOfferingName());
    // populate owner.
    ApiResponseHelper.populateOwner(routerResponse, router);
    routerResponse.setDomainId(router.getDomainUuid());
    routerResponse.setDomainName(router.getDomainName());
    routerResponse.setZoneName(router.getDataCenterName());
    routerResponse.setDns1(router.getDns1());
    routerResponse.setDns2(router.getDns2());
    routerResponse.setIp6Dns1(router.getIp6Dns1());
    routerResponse.setIp6Dns2(router.getIp6Dns2());
    routerResponse.setVpcId(router.getVpcUuid());
    routerResponse.setVpcName(router.getVpcName());
    routerResponse.setRole(router.getRole().toString());
    // set async job
    if (router.getJobId() != null) {
        routerResponse.setJobId(router.getJobUuid());
        routerResponse.setJobStatus(router.getJobStatus());
    }
    routerResponse.setObjectName("router");
    return routerResponse;
}
Also used : DomainRouterResponse(com.cloud.api.response.DomainRouterResponse) TrafficType(com.cloud.model.enumeration.TrafficType) NicResponse(com.cloud.api.response.NicResponse)

Example 8 with TrafficType

use of com.cloud.model.enumeration.TrafficType 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 : LbStickinessPolicy(com.cloud.legacymodel.network.LoadBalancingRule.LbStickinessPolicy) NetworkModel(com.cloud.network.NetworkModel) VpnUser(com.cloud.legacymodel.network.VpnUser) Nic(com.cloud.legacymodel.network.Nic) StaticRouteProfile(com.cloud.legacymodel.network.vpc.StaticRouteProfile) NetworkACLTO(com.cloud.legacymodel.to.NetworkACLTO) ServiceOfferingDao(com.cloud.service.dao.ServiceOfferingDao) VlanDao(com.cloud.dc.dao.VlanDao) Map(java.util.Map) ZoneRepository(com.cloud.db.repository.ZoneRepository) LoadBalancerVMMapDao(com.cloud.network.dao.LoadBalancerVMMapDao) FirewallRule(com.cloud.legacymodel.network.FirewallRule) NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO) NicTO(com.cloud.legacymodel.to.NicTO) LoadBalancingRule(com.cloud.legacymodel.network.LoadBalancingRule) RemoteAccessVpnVO(com.cloud.network.dao.RemoteAccessVpnVO) StaticNatRule(com.cloud.legacymodel.network.StaticNatRule) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) SetPublicIpACLCommand(com.cloud.legacymodel.communication.command.SetPublicIpACLCommand) VpcGateway(com.cloud.legacymodel.network.vpc.VpcGateway) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) SetStaticNatRulesCommand(com.cloud.legacymodel.communication.command.SetStaticNatRulesCommand) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) VpnUserDao(com.cloud.network.dao.VpnUserDao) NumbersUtil(com.cloud.utils.NumbersUtil) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine) Ip(com.cloud.legacymodel.network.Ip) Zone(com.cloud.db.model.Zone) UpdateVmOverviewCommand(com.cloud.legacymodel.communication.command.UpdateVmOverviewCommand) NicProfile(com.cloud.vm.NicProfile) ArrayList(java.util.ArrayList) Purpose(com.cloud.legacymodel.network.FirewallRule.Purpose) VlanVO(com.cloud.dc.VlanVO) ConfigurationDao(com.cloud.framework.config.dao.ConfigurationDao) DomainRouterVO(com.cloud.vm.DomainRouterVO) UpdateNetworkOverviewCommand(com.cloud.legacymodel.communication.command.UpdateNetworkOverviewCommand) BroadcastDomainType(com.cloud.model.enumeration.BroadcastDomainType) Site2SiteVpnConnection(com.cloud.network.Site2SiteVpnConnection) PortForwardingRule(com.cloud.legacymodel.network.PortForwardingRule) DomainRouterDao(com.cloud.vm.dao.DomainRouterDao) SavePasswordCommand(com.cloud.legacymodel.communication.command.SavePasswordCommand) LbDestination(com.cloud.legacymodel.network.LoadBalancingRule.LbDestination) PublicIpACLTO(com.cloud.legacymodel.to.PublicIpACLTO) Site2SiteVpnConnectionDao(com.cloud.network.dao.Site2SiteVpnConnectionDao) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) UserVmDao(com.cloud.vm.dao.UserVmDao) NetworkElementCommand(com.cloud.legacymodel.communication.command.NetworkElementCommand) NicDao(com.cloud.vm.dao.NicDao) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn) Site2SiteCustomerGatewayDao(com.cloud.network.dao.Site2SiteCustomerGatewayDao) StaticRouteDao(com.cloud.network.vpc.dao.StaticRouteDao) SetPortForwardingRulesVpcCommand(com.cloud.legacymodel.communication.command.SetPortForwardingRulesVpcCommand) FirewallRuleTO(com.cloud.legacymodel.to.FirewallRuleTO) PortForwardingRuleTO(com.cloud.legacymodel.to.PortForwardingRuleTO) SetPortForwardingRulesCommand(com.cloud.legacymodel.communication.command.SetPortForwardingRulesCommand) Site2SiteVpnGatewayDao(com.cloud.network.dao.Site2SiteVpnGatewayDao) Site2SiteVpnGatewayVO(com.cloud.network.dao.Site2SiteVpnGatewayVO) StaticNatRuleTO(com.cloud.legacymodel.to.StaticNatRuleTO) URI(java.net.URI) Config(com.cloud.configuration.Config) SetFirewallRulesCommand(com.cloud.legacymodel.communication.command.SetFirewallRulesCommand) StringUtils(com.cloud.utils.StringUtils) SetNetworkACLCommand(com.cloud.legacymodel.communication.command.SetNetworkACLCommand) TrafficType(com.cloud.model.enumeration.TrafficType) LBStickinessPolicyDao(com.cloud.network.dao.LBStickinessPolicyDao) Commands(com.cloud.agent.manager.Commands) IpAddress(com.cloud.network.IpAddress) LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) NicVO(com.cloud.vm.NicVO) Site2SiteCustomerGatewayVO(com.cloud.network.dao.Site2SiteCustomerGatewayVO) Collectors(java.util.stream.Collectors) NetworkOverviewTO(com.cloud.legacymodel.to.NetworkOverviewTO) List(java.util.List) LoadBalancerTO(com.cloud.legacymodel.to.LoadBalancerTO) NetworkACLItem(com.cloud.legacymodel.network.vpc.NetworkACLItem) RemoteAccessVpnDao(com.cloud.network.dao.RemoteAccessVpnDao) VirtualMachineManager(com.cloud.vm.VirtualMachineManager) Optional(java.util.Optional) NetUtils(com.cloud.utils.net.NetUtils) LoadBalancerConfigCommand(com.cloud.legacymodel.communication.command.LoadBalancerConfigCommand) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) StaticNat(com.cloud.network.rules.StaticNat) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter) HashMap(java.util.HashMap) NetworkDao(com.cloud.network.dao.NetworkDao) Inject(javax.inject.Inject) IPAddressVO(com.cloud.network.dao.IPAddressVO) NetworkVO(com.cloud.network.dao.NetworkVO) Qualifier(org.springframework.beans.factory.annotation.Qualifier) IPAddressDao(com.cloud.network.dao.IPAddressDao) VMOverviewTO(com.cloud.legacymodel.to.VMOverviewTO) GuestType(com.cloud.model.enumeration.GuestType) FirewallRulesDao(com.cloud.network.dao.FirewallRulesDao) Network(com.cloud.legacymodel.network.Network) NetworkACLItemDao(com.cloud.network.vpc.NetworkACLItemDao) SetupVRCommand(com.cloud.legacymodel.communication.command.SetupVRCommand) PublicIpAddress(com.cloud.network.PublicIpAddress) NetworkOffering(com.cloud.offering.NetworkOffering) UserVmVO(com.cloud.vm.UserVmVO) VpcDao(com.cloud.network.vpc.dao.VpcDao) NetworkOfferingDao(com.cloud.offerings.dao.NetworkOfferingDao) LoadBalancer(com.cloud.legacymodel.network.LoadBalancer) Vpc(com.cloud.legacymodel.network.vpc.Vpc) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) NetworkVO(com.cloud.network.dao.NetworkVO) Ip(com.cloud.legacymodel.network.Ip) ArrayList(java.util.ArrayList) NetworkOverviewTO(com.cloud.legacymodel.to.NetworkOverviewTO) VlanVO(com.cloud.dc.VlanVO) NicVO(com.cloud.vm.NicVO) TrafficType(com.cloud.model.enumeration.TrafficType)

Example 9 with TrafficType

use of com.cloud.model.enumeration.TrafficType in project cosmic by MissionCriticalCloud.

the class LibvirtVifDriverTest method testEmptyTrafficType.

@Test
public void testEmptyTrafficType() throws ConfigurationException {
    final Map<String, Object> params = new HashMap<>();
    params.put(this.LibVirtVifDriver + ".", this.FakeVifDriverClassName);
    this.res.setBridgeType(BridgeType.NATIVE);
    configure(params);
    // Set all traffic types to use default, because bad traffic type should be ignored
    for (final TrafficType trafficType : TrafficType.values()) {
        this.assertions.put(trafficType, this.bridgeVifDriver);
    }
    checkAssertions();
}
Also used : HashMap(java.util.HashMap) TrafficType(com.cloud.model.enumeration.TrafficType) Test(org.junit.Test)

Example 10 with TrafficType

use of com.cloud.model.enumeration.TrafficType in project cosmic by MissionCriticalCloud.

the class LibvirtVifDriverTest method testOverrideSomeTrafficTypes.

@Test
public void testOverrideSomeTrafficTypes() throws ConfigurationException {
    final Map<String, Object> params = new HashMap<>();
    params.put(this.LibVirtVifDriver + "." + "Public", this.FakeVifDriverClassName);
    params.put(this.LibVirtVifDriver + "." + "Guest", LibvirtComputingResource.DEFAULT_OVS_VIF_DRIVER_CLASS);
    this.res.setBridgeType(BridgeType.NATIVE);
    configure(params);
    // Initially, set all traffic types to use default
    for (final TrafficType trafficType : TrafficType.values()) {
        this.assertions.put(trafficType, this.bridgeVifDriver);
    }
    this.assertions.put(TrafficType.Public, this.fakeVifDriver);
    this.assertions.put(TrafficType.Guest, this.ovsVifDriver);
    checkAssertions();
}
Also used : HashMap(java.util.HashMap) TrafficType(com.cloud.model.enumeration.TrafficType) Test(org.junit.Test)

Aggregations

TrafficType (com.cloud.model.enumeration.TrafficType)14 HashMap (java.util.HashMap)7 NetworkVO (com.cloud.network.dao.NetworkVO)6 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)3 NetworkOffering (com.cloud.offering.NetworkOffering)3 NicResponse (com.cloud.api.response.NicResponse)2 ActionEvent (com.cloud.event.ActionEvent)2 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)2 Network (com.cloud.legacymodel.network.Network)2 BroadcastDomainType (com.cloud.model.enumeration.BroadcastDomainType)2 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)2 Map (java.util.Map)2 Test (org.junit.Test)2 AffinityGroupService (com.cloud.affinity.AffinityGroupService)1 Commands (com.cloud.agent.manager.Commands)1 DomainRouterResponse (com.cloud.api.response.DomainRouterResponse)1 Config (com.cloud.configuration.Config)1 Zone (com.cloud.db.model.Zone)1 ZoneRepository (com.cloud.db.repository.ZoneRepository)1 DataCenterVO (com.cloud.dc.DataCenterVO)1