@Override public String call(IpRangeInventory arg) { return arg.getL3NetworkUuid(); } });
@Override public void afterDeleteIpRange(IpRangeInventory ipRange) { String dhcpServerIp = getDHCPServerIP(ipRange.getL3NetworkUuid()); boolean ipRangeExisted = Q.New(IpRangeVO.class).eq(IpRangeVO_.l3NetworkUuid, ipRange.getL3NetworkUuid()).isExists(); if (!ipRangeExisted && dhcpServerIp != null) { deleteDhcpServerIp(ipRange.getL3NetworkUuid(), dhcpServerIp); logger.debug(String.format("delete DHCP IP[%s] of the flat network[uuid:%s] as the IP range[uuid:%s] is deleted", dhcpServerIp, ipRange.getL3NetworkUuid(), ipRange.getUuid())); } }
if (NetworkUtils.isInRange(dhcpServerIp, ipr.getStartIp(), ipr.getEndIp())) { allocateDhcpIp(ipr.getL3NetworkUuid(), true, dhcpServerIp); } else { allocateDhcpIp(ipr.getL3NetworkUuid(), false, dhcpServerIp); String oldDhcpServerIp = getDHCPServerIP(ipr.getL3NetworkUuid()); if (oldDhcpServerIp != null && NetworkUtils.isInRange(oldDhcpServerIp, ipr.getStartIp(), ipr.getEndIp())) { deleteDhcpServerIp(ipr.getL3NetworkUuid(), oldDhcpServerIp); allocateDhcpIp(ipr.getL3NetworkUuid(), true, oldDhcpServerIp);
private UsedIpInventory reserveIpv4(IpRangeInventory ipRange, String ip) { try { UsedIpVO vo = new UsedIpVO(ipRange.getUuid(), ip); vo.setIpInLong(NetworkUtils.ipv4StringToLong(ip)); String uuid = ipRange.getUuid() + ip; uuid = UUID.nameUUIDFromBytes(uuid.getBytes()).toString().replaceAll("-", ""); vo.setUuid(uuid); vo.setL3NetworkUuid(ipRange.getL3NetworkUuid()); vo.setNetmask(ipRange.getNetmask()); vo.setGateway(ipRange.getGateway()); vo.setIpVersion(IPv6Constants.IPv4); vo = dbf.persistAndRefresh(vo); return UsedIpInventory.valueOf(vo); } catch (JpaSystemException e) { if (e.getRootCause() instanceof MySQLIntegrityConstraintViolationException) { logger.debug(String.format("Concurrent ip allocation. " + "Ip[%s] in ip range[uuid:%s] has been allocated, try allocating another one. " + "The error[Duplicate entry] printed by jdbc.spi.SqlExceptionHelper is no harm, " + "we will try finding another ip", ip, ipRange.getUuid())); logger.trace("", e); } else { throw e; } return null; } }
private UsedIpInventory reserveIpv6(IpRangeInventory ipRange, String ip) { try { UsedIpVO vo = new UsedIpVO(); //vo.setIpInLong(NetworkUtils.ipv4StringToLong(ip)); String uuid = ipRange.getUuid() + ip; uuid = UUID.nameUUIDFromBytes(uuid.getBytes()).toString().replaceAll("-", ""); vo.setUuid(uuid); vo.setIpRangeUuid(ipRange.getUuid()); vo.setIp(IPv6NetworkUtils.getIpv6AddressCanonicalString(ip)); vo.setL3NetworkUuid(ipRange.getL3NetworkUuid()); vo.setNetmask(ipRange.getNetmask()); vo.setGateway(ipRange.getGateway()); vo.setIpVersion(IPv6Constants.IPv6); vo = dbf.persistAndRefresh(vo); return UsedIpInventory.valueOf(vo); } catch (JpaSystemException e) { if (e.getRootCause() instanceof MySQLIntegrityConstraintViolationException) { logger.debug(String.format("Concurrent ip allocation. " + "Ip[%s] in ip range[uuid:%s] has been allocated, try allocating another one. " + "The error[Duplicate entry] printed by jdbc.spi.SqlExceptionHelper is no harm, " + "we will try finding another ip", ip, ipRange.getUuid())); logger.trace("", e); } else { throw e; } return null; } }
private void handleDeletion(final CascadeAction action, final Completion completion) { final List<IpRangeInventory> iprinvs = ipRangeFromAction(action); if (iprinvs == null) { completion.success(); return; } List<IpRangeDeletionMsg> msgs = new ArrayList<IpRangeDeletionMsg>(); for (IpRangeInventory iprinv : iprinvs) { IpRangeDeletionMsg msg = new IpRangeDeletionMsg(); msg.setForceDelete(action.isActionCode(CascadeConstant.DELETION_FORCE_DELETE_CODE)); msg.setL3NetworkUuid(iprinv.getL3NetworkUuid()); msg.setIpRangeUuid(iprinv.getUuid()); bus.makeTargetServiceIdByResourceUuid(msg, L3NetworkConstant.SERVICE_ID, iprinv.getUuid()); msgs.add(msg); } bus.send(msgs, new CloudBusListCallBack(completion) { @Override public void run(List<MessageReply> replies) { if (!action.isActionCode(CascadeConstant.DELETION_FORCE_DELETE_CODE)) { for (MessageReply r : replies) { if (!r.isSuccess()) { completion.fail(r.getError()); return; } } } completion.success(); } }); }
L3NetworkVO l3Vo = Q.New(L3NetworkVO.class).eq(L3NetworkVO_.uuid, ipr.getL3NetworkUuid()).find(); if (l3Vo.getIpVersion() != IPv6Constants.IPv6) { throw new ApiMessageInterceptionException(argerr("l3 network [uuid %s: name %s] is not a ipv6 network", l3Vo.getUuid(), l3Vo.getName())); List<IpRangeVO> rangeVOS = Q.New(IpRangeVO.class).eq(IpRangeVO_.l3NetworkUuid, ipr.getL3NetworkUuid()).list(); if (rangeVOS != null && !rangeVOS.isEmpty()) { if (!rangeVOS.get(0).getAddressMode().equals(ipr.getAddressMode())) { if (!r.getL3NetworkUuid().equals(ipr.getL3NetworkUuid())) { continue; List<IpRangeVO> l3IpRanges = Q.New(IpRangeVO.class).eq(IpRangeVO_.l3NetworkUuid, ipr.getL3NetworkUuid()).list(); for (IpRangeVO r : l3IpRanges) { if (!r.getGateway().equals(ipr.getGateway())) {
String oldDhcpServer = FlatNetworkSystemTags.L3_NETWORK_DHCP_IP.getTokenByResourceUuid(inv.getL3NetworkUuid(), FlatNetworkSystemTags.L3_NETWORK_DHCP_IP_TOKEN); if (oldDhcpServer != null) { throw new ApiMessageInterceptionException(argerr("DHCP server ip [%s] is already existed in l3 network [%s]", IPv6NetworkUtils.ipv6TagValueToAddress(oldDhcpServer), inv.getL3NetworkUuid())); L3NetworkVO l3Vo = Q.New(L3NetworkVO.class).eq(L3NetworkVO_.uuid, inv.getL3NetworkUuid()).find(); if (l3Vo.isSystem()) { throw new ApiMessageInterceptionException(argerr("DHCP server ip [%s] can not be configured to system l3",
@Override protected IpRangeVO scripts() { IpRangeVO vo = new IpRangeVO(); vo.setUuid(ipr.getUuid() == null ? Platform.getUuid() : ipr.getUuid()); vo.setDescription(ipr.getDescription()); vo.setEndIp(ipr.getEndIp()); vo.setGateway(ipr.getGateway()); vo.setL3NetworkUuid(ipr.getL3NetworkUuid()); vo.setName(ipr.getName()); vo.setNetmask(ipr.getNetmask()); vo.setStartIp(ipr.getStartIp()); vo.setNetworkCidr(ipr.getNetworkCidr()); vo.setAccountUuid(msg.getSession().getAccountUuid()); vo.setIpVersion(ipr.getIpVersion()); vo.setAddressMode(ipr.getAddressMode()); vo.setPrefixLen(ipr.getPrefixLen()); dbf.getEntityManager().persist(vo); dbf.getEntityManager().flush(); dbf.getEntityManager().refresh(vo); return vo; } }.execute();
private void validate(IpRangeInventory ipr) { L3NetworkVO l3Vo = Q.New(L3NetworkVO.class).eq(L3NetworkVO_.uuid, ipr.getL3NetworkUuid()).find(); if (l3Vo.getIpVersion() != IPv6Constants.IPv4) { throw new ApiMessageInterceptionException(argerr("l3 network [uuid %s: name %s] is not a ipv4 network", l3Vo.getUuid(), l3Vo.getName())); if (!r.getL3NetworkUuid().equals(ipr.getL3NetworkUuid())) { continue; List<IpRangeVO> l3IpRanges = Q.New(IpRangeVO.class).eq(IpRangeVO_.l3NetworkUuid, ipr.getL3NetworkUuid()).list(); for (IpRangeVO r : l3IpRanges) { if (!r.getGateway().equals(ipr.getGateway())) {