private boolean podHasAllocatedPrivateIPs(final long podId) { final HostPodVO pod = _podDao.findById(podId); final int count = _privateIpAddressDao.countIPs(podId, pod.getDataCenterId(), true); return count > 0; }
@Override public boolean deletePrivateIpAddressByPod(long podId) { return _ipAllocDao.deleteIpAddressByPod(podId); }
@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()); }
@Override public void doInTransactionWithoutResult(final TransactionStatus status) { final List<DataCenterIpAddressVO> privateIps = _privateIpAddressDao.listByPodIdDcId(podId, pod.getDataCenterId()); if (!privateIps.isEmpty()) { if (!_privateIpAddressDao.deleteIpAddressByPod(podId)) { throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId);
@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()); } }
throw new ResourceAllocationException("No sush pod exists", ResourceType.network); vo = _privateIPAddressDao.takeIpAddress(zone.getId(), podvo.getId(), 0, caller.getId() + "", false); if(vo == null) throw new ResourceAllocationException("Unable to allocate IP from this Pod", ResourceType.network);
@Override public void addPrivateIpAddress(long dcId, long podId, String start, String end, boolean forSystemVms, Integer vlan) { _ipAllocDao.addIpRange(dcId, podId, start, end, forSystemVms, vlan); }
@Override public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { if (!super.configure(name, params)) { return false; } String value = (String)params.get("mac.address.prefix"); _prefix = (long)NumbersUtil.parseInt(value, 06) << 40; if (!_ipAllocDao.configure("Ip Alloc", params)) { return false; } if (!_vnetAllocDao.configure("vnet Alloc", params)) { return false; } return true; }
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 public void doInTransactionWithoutResult(final TransactionStatus status) { pod.setDescription(newPodIpRange.toString()); HostPodVO lock = null; try { lock = _podDao.acquireInLockTable(podId); if (lock == null) { String msg = "Unable to acquire lock on table to update the ip range of POD: " + pod.getName() + ", Deletion failed."; s_logger.warn(msg); throw new CloudRuntimeException(msg); } _podDao.update(podId, pod); } finally { if (lock != null) { _podDao.releaseFromLockTable(podId); } } for(long ipAddr = NetUtils.ip2Long(startIp); ipAddr <= NetUtils.ip2Long(endIp); ipAddr++) { if (!_privateIpAddressDao.deleteIpAddressByPodDc(NetUtils.long2Ip(ipAddr), podId, pod.getDataCenterId())) { throw new CloudRuntimeException("Failed to cleanup private ip address: " + NetUtils.long2Ip(ipAddr) + " of Pod: " + podId + " DC: " + pod.getDataCenterId()); } } } });
if(_privateIpAddressDao.countIpAddressUsage(NetUtils.long2Ip(ipAddr), podId, pod.getDataCenterId(), true) > 0) { throw new CloudRuntimeException("Some IPs of the range has been allocated, so it cannot be deleted.");
private void addIpAddressMetrics(final List<Item> metricsList, final long dcId, final String zoneName, final String zoneUuid) { metricsList.add(new ItemPrivateIp(zoneName, zoneUuid, ALLOCATED, privateIpAddressDao.countIPs(dcId, true))); metricsList.add(new ItemPrivateIp(zoneName, zoneUuid, TOTAL, privateIpAddressDao.countIPs(dcId, false))); metricsList.add(new ItemPublicIp(zoneName, zoneUuid, ALLOCATED, publicIpAddressDao.countIPsForNetwork(dcId, true, Vlan.VlanType.VirtualNetwork))); metricsList.add(new ItemPublicIp(zoneName, zoneUuid, TOTAL, publicIpAddressDao.countIPsForNetwork(dcId, false, Vlan.VlanType.VirtualNetwork))); metricsList.add(new ItemSharedNetworkIp(zoneName, zoneUuid, ALLOCATED, publicIpAddressDao.countIPsForNetwork(dcId, true, Vlan.VlanType.DirectAttached))); metricsList.add(new ItemSharedNetworkIp(zoneName, zoneUuid, TOTAL, publicIpAddressDao.countIPsForNetwork(dcId, false, Vlan.VlanType.DirectAttached))); }
protected void checkIfPodIsDeletable(final long podId) { final HostPodVO pod = _podDao.findById(podId); final String errorMsg = "The pod cannot be deleted because "; // Check if there are allocated private IP addresses in the pod if (_privateIpAddressDao.countIPs(podId, pod.getDataCenterId(), true) != 0) { throw new CloudRuntimeException(errorMsg + "there are private IP addresses allocated in this pod."); } // Check if there are any non-removed volumes in the pod. if (!_volumeDao.findByPod(podId).isEmpty()) { throw new CloudRuntimeException(errorMsg + "there are storage volumes in this pod."); } // Check if there are any non-removed hosts in the pod. if (!_hostDao.findByPodId(podId).isEmpty()) { throw new CloudRuntimeException(errorMsg + "there are servers in this pod."); } // Check if there are any non-removed vms in the pod. if (!_vmInstanceDao.listByPodId(podId).isEmpty()) { throw new CloudRuntimeException(errorMsg + "there are virtual machines in this pod."); } // Check if there are any non-removed clusters in the pod. if (!_clusterDao.listByPodId(podId).isEmpty()) { throw new CloudRuntimeException(errorMsg + "there are clusters in this pod."); } }
if (_privateIpAddressDao.countIPs(zoneId, true) != 0) { throw new CloudRuntimeException(errorMsg + "there are private IP addresses allocated in this zone.");
capacities = _capacityDao.search(capacitySC, null); if (capacityType == Capacity.CAPACITY_TYPE_PRIVATE_IP) { totalIPs = _privateIPAddressDao.countIPs(podId, dcId, false); allocatedIPs = _privateIPAddressDao.countIPs(podId, dcId, true); } else if (capacityType == Capacity.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP) { totalIPs = _publicIPAddressDao.countIPsForNetwork(dcId, false, VlanType.VirtualNetwork);