private ExternalLoadBalancerDeviceVO getNetScalerForEIP(StaticNat rule) { String guestIP = rule.getDestIpAddress(); List<DataCenterIpAddressVO> dcGuestIps = _privateIpAddressDao.listAll(); if (dcGuestIps != null) { for (DataCenterIpAddressVO dcGuestIp : dcGuestIps) { if (dcGuestIp.getIpAddress().equalsIgnoreCase(guestIP)) { long podId = dcGuestIp.getPodId(); NetScalerPodVO nsPodVO = _netscalerPodDao.findByPodId(podId); if (nsPodVO != null) { ExternalLoadBalancerDeviceVO lbDeviceVO = _lbDeviceDao.findById(nsPodVO.getNetscalerDeviceId()); return lbDeviceVO; } } } } return null; }
@Override @DB public DataCenterIpAddressVO takeDataCenterIpAddress(long dcId, String reservationId) { SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create(); sc.setParameters("dc", dcId); sc.setParameters("taken", (Date)null); TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start(); DataCenterIpAddressVO vo = lockOneRandomRow(sc, true); if (vo == null) { txn.rollback(); return null; } vo.setTakenAt(new Date()); vo.setReservationId(reservationId); update(vo.getId(), vo); txn.commit(); return vo; }
@Override public PrivateAllocationData allocatePrivateIpAddress(long dcId, long podId, long instanceId, String reservationId, boolean forSystemVms) { _ipAllocDao.releaseIpAddress(instanceId); DataCenterIpAddressVO vo = _ipAllocDao.takeIpAddress(dcId, podId, instanceId, reservationId, forSystemVms); if (vo == null) { return null; } return new PrivateAllocationData(vo.getIpAddress(), vo.getMacAddress(), vo.getVlan()); }
AllFieldsSearch.and("ip", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ); AllFieldsSearch.and("dc", AllFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("pod", AllFieldsSearch.entity().getPodId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("instance", AllFieldsSearch.entity().getInstanceId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("ipAddress", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ); AllFieldsSearch.and("reservation", AllFieldsSearch.entity().getReservationId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("taken", AllFieldsSearch.entity().getTakenAt(), SearchCriteria.Op.EQ); AllFieldsSearch.and("forSystemVms", AllFieldsSearch.entity().isForSystemVms(), SearchCriteria.Op.EQ); AllFieldsSearch.done(); AllIpCount.select(null, Func.COUNT, AllIpCount.entity().getId()); AllIpCount.and("pod", AllIpCount.entity().getPodId(), SearchCriteria.Op.EQ); AllIpCount.done(); AllIpCountForDc.select(null, Func.COUNT, AllIpCountForDc.entity().getId()); AllIpCountForDc.and("data_center_id", AllIpCountForDc.entity().getPodId(), SearchCriteria.Op.EQ); AllIpCountForDc.done(); AllAllocatedIpCount.select(null, Func.COUNT, AllAllocatedIpCount.entity().getId()); AllAllocatedIpCount.and("pod", AllAllocatedIpCount.entity().getPodId(), SearchCriteria.Op.EQ); AllAllocatedIpCount.and("removed", AllAllocatedIpCount.entity().getTakenAt(), SearchCriteria.Op.NNULL); AllAllocatedIpCount.done(); AllAllocatedIpCountForDc.select(null, Func.COUNT, AllAllocatedIpCountForDc.entity().getId()); AllAllocatedIpCountForDc.and("data_center_id", AllAllocatedIpCountForDc.entity().getDataCenterId(), SearchCriteria.Op.EQ); AllAllocatedIpCountForDc.and("removed", AllAllocatedIpCountForDc.entity().getTakenAt(), SearchCriteria.Op.NNULL); AllAllocatedIpCountForDc.done();
if(vo == null) throw new ResourceAllocationException("Unable to allocate IP from this Pod", ResourceType.network); if (vo.getIpAddress() == null) throw new ResourceAllocationException("Unable to allocate IP from this Pod", ResourceType.network); HostPodVO pod_vo = _hpDao.findById(vo.getPodId()); AcquirePodIpCmdResponse ret = new AcquirePodIpCmdResponse(); ret.setCidrAddress(pod_vo.getCidrAddress()); ret.setGateway(pod_vo.getGateway()); ret.setInstanceId(vo.getInstanceId()); ret.setIpAddress(vo.getIpAddress()); ret.setMacAddress(vo.getMacAddress()); ret.setPodId(vo.getPodId()); ret.setId(vo.getId());
@Override @DB public DataCenterIpAddressVO takeIpAddress(long dcId, long podId, long instanceId, String reservationId, boolean forSystemVms) { SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create(); sc.setParameters("pod", podId); sc.setParameters("taken", (Date)null); sc.setParameters("forSystemVms", forSystemVms); TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start(); DataCenterIpAddressVO vo = lockOneRandomRow(sc, true); // If there is no explicitly created range for system vms and reservation mode is preferred (strictness = false) if (forSystemVms && vo == null && !SystemVmManagementIpReservationModeStrictness.value()) { sc.setParameters("forSystemVms", false); vo = lockOneRandomRow(sc, true); } if (vo == null) { txn.rollback(); return null; } vo.setTakenAt(new Date()); vo.setInstanceId(instanceId); vo.setReservationId(reservationId); update(vo.getId(), vo); txn.commit(); return vo; }
@DB @Override public void releasePodIp(Long id) throws CloudRuntimeException { // Verify input parameters DataCenterIpAddressVO ipVO = _privateIPAddressDao.findById(id); if (ipVO == null) { throw new CloudRuntimeException("Unable to find ip address by id:" + id); } if (ipVO.getTakenAt() == null) { s_logger.debug("Ip Address with id= " + id + " is not allocated, so do nothing."); throw new CloudRuntimeException("Ip Address with id= " + id + " is not allocated, so do nothing."); } // Verify permission DataCenter zone = _entityMgr.findById(DataCenter.class, ipVO.getDataCenterId()); Account caller = CallContext.current().getCallingAccount(); if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getId())) { throw new CloudRuntimeException("Cannot perform this operation, " + "Zone is currently disabled" + "zoneId=" + ipVO.getDataCenterId()); } try { _privateIPAddressDao.releasePodIpAddress(id); } catch (Exception e) { new CloudRuntimeException(e.getMessage()); } }
if (vo.getInstanceId() != null) { throw new IllegalArgumentException("The private ip address of the server (" + serverPrivateIP + ") is already in use in pod: " + pod.getName() + " and zone: " + dc.getName());
" needed for management IP of the load balancer appliance", DataCenter.class, guestConfig.getDataCenterId()); Pod pod = _podDao.findById(dcPrivateIp.getPodId()); String lbIP = dcPrivateIp.getIpAddress(); String netmask = NetUtils.getCidrNetmask(pod.getCidrSize()); String gateway = pod.getGateway();