@Override public String getVmIp() { return _addr.getVmIp(); }
public VspStaticNat buildVspStaticNat(Boolean forRevoke, IPAddressVO staticNatIp, VlanVO staticNatVlan, NicVO nic) { NicSecondaryIpVO nicSecondaryIp = null; if (nic == null && staticNatIp.getAssociatedWithVmId() != null && staticNatIp.getVmIp() != null) { nicSecondaryIp = _nicSecondaryIpDao.findByIp4AddressAndInstanceId(staticNatIp.getAssociatedWithVmId(), staticNatIp.getVmIp()); if (nicSecondaryIp != null) { nic = _nicDao.findById(nicSecondaryIp.getNicId()); } } VspNic vspNic = (nic != null) ? buildVspNic(nic, nicSecondaryIp) : null; return buildVspStaticNat(forRevoke, staticNatIp, staticNatVlan, vspNic); }
@Override public boolean applyStaticNatsForNetwork(long networkId, boolean continueOnError, Account caller) { List<IPAddressVO> ips = _ipAddressDao.listStaticNatPublicIps(networkId); if (ips.isEmpty()) { s_logger.debug("There are no static nat to apply for network id=" + networkId); return true; } if (caller != null) { _accountMgr.checkAccess(caller, null, true, ips.toArray(new IPAddressVO[ips.size()])); } List<StaticNat> staticNats = new ArrayList<StaticNat>(); for (IPAddressVO ip : ips) { // Get nic IP4 address //String dstIp = _networkModel.getIpInNetwork(ip.getAssociatedWithVmId(), networkId); StaticNatImpl staticNat = new StaticNatImpl(ip.getAllocatedToAccountId(), ip.getAllocatedInDomainId(), networkId, ip.getId(), ip.getVmIp(), false); staticNats.add(staticNat); } try { if (!_ipAddrMgr.applyStaticNats(staticNats, continueOnError, false)) { return false; } } catch (ResourceUnavailableException ex) { s_logger.warn("Failed to create static nat for network due to ", ex); return false; } return true; }
public VspStaticNat buildVspStaticNat(Boolean forRevoke, IPAddressVO staticNatIp, VlanVO staticNatVlan, VspNic vspNic) { VspStaticNat.Builder vspStaticNatBuilder = new VspStaticNat.Builder() .ipUuid(staticNatIp.getUuid()) .ipAddress(staticNatIp.getAddress().addr()) .revoke(forRevoke) .oneToOneNat(staticNatIp.isOneToOneNat()) .state(getEnumValue(staticNatIp.getState(), VspStaticNat.State.class)) .vlanUuid(staticNatVlan.getUuid()) .vlanGateway(staticNatVlan.getVlanGateway()) .vlanNetmask(staticNatVlan.getVlanNetmask()) .vlanUnderlay(NuageVspUtil.isUnderlayEnabledForVlan(_vlanDetailsDao, staticNatVlan)); if (staticNatIp.getVmIp() != null) { vspStaticNatBuilder.destinationIp(staticNatIp.getVmIp() + "/32"); } if (vspNic != null) { vspStaticNatBuilder.nic(vspNic); } return vspStaticNatBuilder.build(); }
public VspAclRule buildVspAclRule(FirewallRule firewallRule, Network network, IPAddressVO staticNat) { 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) .state(getEnumValue(firewallRule.getState(), VspAclRule.ACLState.class)) .trafficType(getEnumValue(firewallRule.getTrafficType(), VspAclRule.ACLTrafficType.class)); NetworkOfferingVO networkOffering = _networkOfferingDao.findById(network.getNetworkOfferingId()); if (firewallRule.getTrafficType() == FirewallRule.TrafficType.Egress && networkOffering.isEgressDefaultPolicy()) { vspAclRuleBuilder.deny(); } else { vspAclRuleBuilder.allow(); } if (staticNat == null && firewallRule.getSourceIpAddressId() != null) { IPAddressVO staticNatIp = _ipAddressDao.findById(firewallRule.getSourceIpAddressId()); if (staticNatIp != null) { VlanVO staticNatVlan = _vlanDao.findById(staticNatIp.getVlanId()); NicVO nic = _nicDao.findByIp4AddressAndNetworkId(staticNatIp.getVmIp(), staticNatIp.getAssociatedWithNetworkId()); vspAclRuleBuilder.staticNat(buildVspStaticNat(null, staticNatIp, staticNatVlan, nic)); } } return vspAclRuleBuilder.build(); }
final String dstIp = ipAddress.getVmIp(); return Transaction.execute(new TransactionCallbackWithException<StaticNatRule, NetworkRuleConflictException>() { @Override
AllFieldsSearch.and("physicalNetworkId", AllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ); AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ); AllFieldsSearch.and("associatedVmIp", AllFieldsSearch.entity().getVmIp(), Op.EQ); AllFieldsSearch.done();