Search in sources :

Example 16 with IPAddressVO

use of com.cloud.network.dao.IPAddressVO in project cloudstack by apache.

the class ContrailManagerImpl method findManagedPublicIps.

/*
     * Returns list of public ip addresses managed by Juniper VRouter
     */
@Override
public List<IPAddressVO> findManagedPublicIps() {
    List<NetworkVO> dbNets = findManagedNetworks(null);
    if (dbNets == null || dbNets.isEmpty()) {
        s_logger.debug("Juniper managed networks is empty");
        return null;
    }
    SearchBuilder<IPAddressVO> searchBuilder = _ipAddressDao.createSearchBuilder();
    searchBuilder.and("sourceNat", searchBuilder.entity().isSourceNat(), Op.EQ);
    searchBuilder.and("network", searchBuilder.entity().getAssociatedWithNetworkId(), Op.IN);
    searchBuilder.and("oneToOneNat", searchBuilder.entity().isOneToOneNat(), Op.EQ);
    searchBuilder.and("associatedWithVmId", searchBuilder.entity().getAssociatedWithVmId(), Op.NNULL);
    List<Long> netIds = new ArrayList<Long>();
    for (NetworkVO net : dbNets) {
        netIds.add(net.getId());
    }
    SearchCriteria<IPAddressVO> sc = searchBuilder.create();
    sc.setParameters("oneToOneNat", true);
    sc.setParameters("sourceNat", false);
    sc.setParameters("network", netIds.toArray());
    List<IPAddressVO> publicIps = _ipAddressDao.search(sc, null);
    if (publicIps == null) {
        s_logger.debug("no public ips");
        return null;
    }
    return publicIps;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) ArrayList(java.util.ArrayList) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Example 17 with IPAddressVO

use of com.cloud.network.dao.IPAddressVO in project cloudstack by apache.

the class NuageVspElement method applyStaticNats.

@Override
public boolean applyStaticNats(Network config, List<? extends StaticNat> rules) throws ResourceUnavailableException {
    List<VspStaticNat> vspStaticNatDetails = new ArrayList<VspStaticNat>();
    for (StaticNat staticNat : rules) {
        IPAddressVO sourceNatIp = _ipAddressDao.findById(staticNat.getSourceIpAddressId());
        VlanVO sourceNatVlan = _vlanDao.findById(sourceNatIp.getVlanId());
        checkVlanUnderlayCompatibility(sourceNatVlan);
        NicVO nicVO = _nicDao.findByIp4AddressAndNetworkId(staticNat.getDestIpAddress(), staticNat.getNetworkId());
        VspStaticNat vspStaticNat = _nuageVspEntityBuilder.buildVspStaticNat(staticNat.isForRevoke(), sourceNatIp, sourceNatVlan, nicVO);
        vspStaticNatDetails.add(vspStaticNat);
    }
    VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(config);
    HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(config.getPhysicalNetworkId());
    ApplyStaticNatVspCommand cmd = new ApplyStaticNatVspCommand(vspNetwork, vspStaticNatDetails);
    Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("ApplyStaticNatNuageVspCommand for network " + config.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
        if ((null != answer) && (null != answer.getDetails())) {
            throw new ResourceUnavailableException(answer.getDetails(), Network.class, config.getId());
        }
    }
    return true;
}
Also used : Answer(com.cloud.agent.api.Answer) ApplyStaticNatVspCommand(com.cloud.agent.api.element.ApplyStaticNatVspCommand) ArrayList(java.util.ArrayList) VspStaticNat(net.nuage.vsp.acs.client.api.model.VspStaticNat) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IPAddressVO(com.cloud.network.dao.IPAddressVO) VlanVO(com.cloud.dc.VlanVO) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) NicVO(com.cloud.vm.NicVO) HostVO(com.cloud.host.HostVO) VspStaticNat(net.nuage.vsp.acs.client.api.model.VspStaticNat) StaticNat(com.cloud.network.rules.StaticNat)

Example 18 with IPAddressVO

use of com.cloud.network.dao.IPAddressVO in project cloudstack by apache.

the class NuageVspElement method implement.

@Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Entering NuageElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")");
    }
    if (network.getVpcId() != null) {
        return applyACLRulesForVpc(network, offering);
    }
    if (!canHandle(network, offering, Service.Connectivity)) {
        return false;
    }
    if (network.getBroadcastUri() == null) {
        s_logger.error("Nic has no broadcast Uri with the virtual router IP");
        return false;
    }
    VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network);
    List<VspAclRule> ingressFirewallRules = getFirewallRulesToApply(network, FirewallRule.TrafficType.Ingress);
    List<VspAclRule> egressFirewallRules = getFirewallRulesToApply(network, FirewallRule.TrafficType.Egress);
    List<IPAddressVO> ips = _ipAddressDao.listStaticNatPublicIps(network.getId());
    List<String> floatingIpUuids = new ArrayList<String>();
    for (IPAddressVO ip : ips) {
        floatingIpUuids.add(ip.getUuid());
    }
    VspDhcpDomainOption vspDhcpOptions = _nuageVspEntityBuilder.buildNetworkDhcpOption(network, offering);
    HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(network.getPhysicalNetworkId());
    ImplementVspCommand cmd = new ImplementVspCommand(vspNetwork, ingressFirewallRules, egressFirewallRules, floatingIpUuids, vspDhcpOptions);
    Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("ImplementVspCommand for network " + network.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
        if ((null != answer) && (null != answer.getDetails())) {
            throw new ResourceUnavailableException(answer.getDetails(), Network.class, network.getId());
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) VspDhcpDomainOption(net.nuage.vsp.acs.client.api.model.VspDhcpDomainOption) HostVO(com.cloud.host.HostVO) Answer(com.cloud.agent.api.Answer) VspAclRule(net.nuage.vsp.acs.client.api.model.VspAclRule) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IPAddressVO(com.cloud.network.dao.IPAddressVO) ImplementVspCommand(com.cloud.agent.api.element.ImplementVspCommand) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork)

Example 19 with IPAddressVO

use of com.cloud.network.dao.IPAddressVO in project cloudstack by apache.

the class NuageVspElementTest method testImplement.

@Test
public void testImplement() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, URISyntaxException {
    final Network network = mock(Network.class);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vsp);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getVpcId()).thenReturn(null);
    when(network.getBroadcastUri()).thenReturn(new URI(""));
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getDomainId()).thenReturn(NETWORK_ID);
    when(network.getDataCenterId()).thenReturn(NETWORK_ID);
    when(_networkModel.isProviderForNetwork(Provider.NuageVsp, NETWORK_ID)).thenReturn(true);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    DeployDestination deployDest = mock(DeployDestination.class);
    final DomainVO dom = mock(DomainVO.class);
    when(dom.getName()).thenReturn("domain");
    when(_domainDao.findById(NETWORK_ID)).thenReturn(dom);
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext context = mock(ReservationContext.class);
    when(context.getDomain()).thenReturn(dom);
    when(context.getAccount()).thenReturn(acc);
    final HostVO host = mock(HostVO.class);
    when(host.getId()).thenReturn(NETWORK_ID);
    final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
    when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
    when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[] { nuageVspDevice }));
    when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
    when(_nuageVspManager.getNuageVspHost(NETWORK_ID)).thenReturn(host);
    when(_firewallRulesDao.listByNetworkPurposeTrafficType(NETWORK_ID, FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Ingress)).thenReturn(new ArrayList<FirewallRuleVO>());
    when(_firewallRulesDao.listByNetworkPurposeTrafficType(NETWORK_ID, FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Egress)).thenReturn(new ArrayList<FirewallRuleVO>());
    when(_ipAddressDao.listStaticNatPublicIps(NETWORK_ID)).thenReturn(new ArrayList<IPAddressVO>());
    when(_nuageVspManager.getDnsDetails(network.getDataCenterId())).thenReturn(new ArrayList<String>());
    assertTrue(_nuageVspElement.implement(network, offering, deployDest, context));
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) Account(com.cloud.user.Account) NetworkOffering(com.cloud.offering.NetworkOffering) URI(java.net.URI) HostVO(com.cloud.host.HostVO) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) ReservationContext(com.cloud.vm.ReservationContext) DomainVO(com.cloud.domain.DomainVO) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) IPAddressVO(com.cloud.network.dao.IPAddressVO) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 20 with IPAddressVO

use of com.cloud.network.dao.IPAddressVO in project cloudstack by apache.

the class NuageVspEntityBuilder method buildVspAclRule.

public VspAclRule buildVspAclRule(FirewallRule firewallRule, Network network) {
    VspAclRule.Builder vspAclRuleBuilder = new VspAclRule.Builder().uuid(firewallRule.getUuid()).protocol(firewallRule.getProtocol()).startPort(firewallRule.getSourcePortStart()).endPort(firewallRule.getSourcePortEnd()).sourceCidrList(firewallRule.getSourceCidrList()).priority(-1).type(VspAclRule.ACLType.Firewall);
    switch(firewallRule.getState()) {
        case Active:
            vspAclRuleBuilder.state(VspAclRule.ACLState.Active);
            break;
        case Add:
            vspAclRuleBuilder.state(VspAclRule.ACLState.Add);
            break;
        case Revoke:
            vspAclRuleBuilder.state(VspAclRule.ACLState.Revoke);
    }
    switch(firewallRule.getTrafficType()) {
        case Ingress:
            vspAclRuleBuilder.trafficType(VspAclRule.ACLTrafficType.Ingress);
            break;
        case Egress:
            vspAclRuleBuilder.trafficType(VspAclRule.ACLTrafficType.Egress);
    }
    NetworkOfferingVO networkOffering = _networkOfferingDao.findById(network.getNetworkOfferingId());
    if (firewallRule.getTrafficType() == FirewallRule.TrafficType.Egress && networkOffering.getEgressDefaultPolicy()) {
        vspAclRuleBuilder.action(VspAclRule.ACLAction.Deny);
    } else {
        vspAclRuleBuilder.action(VspAclRule.ACLAction.Allow);
    }
    if (firewallRule.getSourceIpAddressId() != null) {
        IPAddressVO ipAddress = _ipAddressDao.findById(firewallRule.getSourceIpAddressId());
        if (ipAddress != null) {
            vspAclRuleBuilder.sourceIpAddress(ipAddress.getVmIp() + "/32");
        }
    }
    return vspAclRuleBuilder.build();
}
Also used : VspAclRule(net.nuage.vsp.acs.client.api.model.VspAclRule) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Aggregations

IPAddressVO (com.cloud.network.dao.IPAddressVO)109 ArrayList (java.util.ArrayList)43 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)42 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)39 Account (com.cloud.user.Account)37 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)32 DB (com.cloud.utils.db.DB)28 TransactionStatus (com.cloud.utils.db.TransactionStatus)26 Network (com.cloud.network.Network)25 PublicIp (com.cloud.network.addr.PublicIp)22 DataCenter (com.cloud.dc.DataCenter)17 VlanVO (com.cloud.dc.VlanVO)16 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)16 List (java.util.List)15 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)14 Ip (com.cloud.utils.net.Ip)14 NetworkOffering (com.cloud.offering.NetworkOffering)13 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)13 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)12 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)11