@Override public List<DomainRouterVO> findInternalLbVms(final long guestNetworkId, final Ip requestedGuestIp) { final List<DomainRouterVO> internalLbVms = _internalLbVmDao.listByNetworkAndRole(guestNetworkId, Role.INTERNAL_LB_VM); if (requestedGuestIp != null && !internalLbVms.isEmpty()) { final Iterator<DomainRouterVO> it = internalLbVms.iterator(); while (it.hasNext()) { final DomainRouterVO vm = it.next(); final Nic nic = _nicDao.findByNtwkIdAndInstanceId(guestNetworkId, vm.getId()); if (!nic.getIPv4Address().equalsIgnoreCase(requestedGuestIp.addr())) { it.remove(); } } } return internalLbVms; }
public String addr() { return toString(); }
@Test public void testIsSameAddressAs() { Assert.assertTrue("1 and one should be considdered the same address", new Ip(1L).isSameAddressAs("0.0.0.1")); Assert.assertTrue("zero and 0L should be considdered the same address", new Ip("0.0.0.0").isSameAddressAs(0L)); }
throw new InvalidParameterValueException("Vm doesn't belong to network associated with ipAddress"); } else { dstIp = new Ip(guestNic.getIPv4Address()); if (!dstIp.equals(vmGuestIp)) { NicSecondaryIp secondaryIp = _nicSecondaryDao.findByIp4AddressAndNicId(vmGuestIp.toString(), guestNic.getId()); if (secondaryIp == null) { throw new InvalidParameterValueException("IP Address is not in the VM nic's network ");
public Ip getVmSecondaryIp() { if (vmSecondaryIp == null) { return null; } return new Ip(vmSecondaryIp); }
IPAddressVO ipaddr = new IPAddressVO(new Ip(allocatedPortableIp.getAddress()), dcId, networkId, vpcID, physicalNetworkId, network.getId(), vlan.getId(), true); ipaddr.setState(State.Allocated); ipaddr.setAllocatedTime(new Date()); ipaddr.getAddress().toString(), ipaddr.isSourceNat(), null, ipaddr.getSystem(), ipaddr.getClass().getName(), ipaddr.getUuid());
public boolean isSameAddressAs(Object obj) { if (this.equals(obj)) { return true; } else if (obj instanceof String) { return ip == NetUtils.ip2Long((String)obj); } else if (obj instanceof Long) { return ip == (Long)obj; } else { return false; } }
throw new InvalidParameterValueException("Vm doesn't belong to network associated with ipAddress"); } else { dstIp = new Ip(guestNic.getIPv4Address()); if (!dstIp.equals(vmIp)) { NicSecondaryIp secondaryIp = _nicSecondaryDao.findByIp4AddressAndNicId(vmIp.toString(), guestNic.getId()); if (secondaryIp == null) { throw new InvalidParameterValueException("IP Address is not in the VM nic's network ");
public Ip getVmGuestIp() { if (vmGuestIp == null) { return null; } return new Ip(vmGuestIp); }
public void createFloatingIp(IPAddressVO dbIp, StringBuffer syncLogMesg) throws Exception { if (dbIp.getState() == IpAddress.State.Releasing) { /* Don't need to push releasing ip */ syncLogMesg.append("fip# DB: " + dbIp.getUuid() + ", state releasing, don't create in vnc\n"); return; } syncLogMesg.append("fip# DB: " + dbIp.getAddress().addr() + "; VNC: none; action: create\n"); if (!_manager.createFloatingIp(PublicIp.createFromAddrAndVlan(dbIp, _vlanDao.findById(dbIp.getVlanId())))) { syncLogMesg.append("fip# VNC: " + dbIp.getAddress().addr() + " unable to create\n"); return; } syncLogMesg.append("fip# VNC: " + dbIp.getUuid() + " created\n"); }
@Override public String toString() { return _addr.getAddress().toString(); }
/** * Gets source ip address based on the LB rule scheme/source IP network/requested IP address * @param scheme * @param sourceIpNtwk * @param requestedIp * @return * @throws InsufficientVirtualNetworkCapacityException */ protected Ip getSourceIp(Scheme scheme, Network sourceIpNtwk, String requestedIp) throws InsufficientVirtualNetworkCapacityException { if (requestedIp != null) { if (_lbDao.countBySourceIp(new Ip(requestedIp), sourceIpNtwk.getId()) > 0) { s_logger.debug("IP address " + requestedIp + " is already used by existing LB rule, returning it"); return new Ip(requestedIp); } validateRequestedSourceIpForLbRule(sourceIpNtwk, new Ip(requestedIp), scheme); } requestedIp = allocateSourceIpForLbRule(scheme, sourceIpNtwk, requestedIp); if (requestedIp == null) { throw new InsufficientVirtualNetworkCapacityException("Unable to acquire IP address for network " + sourceIpNtwk, Network.class, sourceIpNtwk.getId()); } return new Ip(requestedIp); }
@Override public String allocatePublicIpForGuestNic(Network network, Long podId, Account owner, String requestedIp) throws InsufficientAddressCapacityException { PublicIp ip = assignPublicIpAddress(network.getDataCenterId(), podId, owner, VlanType.DirectAttached, network.getId(), requestedIp, false, false); if (ip == null) { s_logger.debug("There is no free public ip address"); return null; } Ip ipAddr = ip.getAddress(); return ipAddr.addr(); }
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_RELEASE, acctVln.get(0).getAccountId(), ip.getDataCenterId(), ip.getId(), ip.getAddress().toString(), ip.isSourceNat(), vlan.getVlanType().toString(), ip.getSystem(), ip.getClass().getName(), ip.getUuid());
@Override public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> services) throws ResourceUnavailableException { for (PublicIpAddress ip : ipAddress) { if (ip.isSourceNat()) { continue; } if (isFloatingIpCreate(ip)) { if (_manager.createFloatingIp(ip)) { s_logger.debug("Successfully created floating ip: " + ip.getAddress().addr()); } } else { if (_manager.deleteFloatingIp(ip)) { s_logger.debug("Successfully deleted floating ip: " + ip.getAddress().addr()); } } } return true; }