use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class NetworkModelImpl method getIpToServices.
@Override
public Map<PublicIpAddress, Set<Service>> getIpToServices(final List<? extends PublicIpAddress> publicIps, final boolean postApplyRules, final boolean includingFirewall) {
final Map<PublicIpAddress, Set<Service>> ipToServices = new HashMap<>();
if (publicIps != null && !publicIps.isEmpty()) {
final Set<Long> networkSNAT = new HashSet<>();
for (final PublicIpAddress ip : publicIps) {
Set<Service> services = ipToServices.get(ip);
if (services == null) {
services = new HashSet<>();
}
if (ip.isSourceNat()) {
if (!networkSNAT.contains(ip.getAssociatedWithNetworkId())) {
services.add(Service.SourceNat);
networkSNAT.add(ip.getAssociatedWithNetworkId());
} else {
final CloudRuntimeException ex = new CloudRuntimeException("Multiple generic soure NAT IPs provided for network");
// see the IPAddressVO.java class.
final IPAddressVO ipAddr = ApiDBUtils.findIpAddressById(ip.getAssociatedWithNetworkId());
String ipAddrUuid = ip.getAssociatedWithNetworkId().toString();
if (ipAddr != null) {
ipAddrUuid = ipAddr.getUuid();
}
ex.addProxyObject(ipAddrUuid, "networkId");
throw ex;
}
}
ipToServices.put(ip, services);
// provider
if (ip.getState() == State.Allocating) {
continue;
}
// check if any active rules are applied on the public IP
Set<Purpose> purposes = getPublicIpPurposeInRules(ip, false, includingFirewall);
// Firewall rules didn't cover static NAT
if (ip.isOneToOneNat() && ip.getAssociatedWithVmId() != null) {
if (purposes == null) {
purposes = new HashSet<>();
}
purposes.add(Purpose.StaticNat);
}
if (purposes == null || purposes.isEmpty()) {
// since no active rules are there check if any rules are applied on the public IP but are in
// revoking state
purposes = getPublicIpPurposeInRules(ip, true, includingFirewall);
if (ip.isOneToOneNat()) {
if (purposes == null) {
purposes = new HashSet<>();
}
purposes.add(Purpose.StaticNat);
}
if (purposes == null || purposes.isEmpty()) {
// IP is not being used for any purpose so skip IPAssoc to network service provider
continue;
} else {
if (postApplyRules) {
// association with the provider
if (ip.isSourceNat()) {
s_logger.debug("Not releasing ip " + ip.getAddress().addr() + " as it is in use for SourceNat");
} else {
ip.setState(State.Releasing);
}
} else {
if (ip.getState() == State.Releasing) {
// rules are not revoked yet, so don't let the network service provider revoke the IP
// association
// mark IP is allocated so that IP association will not be removed from the provider
ip.setState(State.Allocated);
}
}
}
}
if (purposes.contains(Purpose.StaticNat)) {
services.add(Service.StaticNat);
}
if (purposes.contains(Purpose.LoadBalancing)) {
services.add(Service.Lb);
}
if (purposes.contains(Purpose.PortForwarding)) {
services.add(Service.PortForwarding);
}
if (purposes.contains(Purpose.Vpn)) {
services.add(Service.Vpn);
}
if (purposes.contains(Purpose.Firewall)) {
services.add(Service.Firewall);
}
if (services.isEmpty()) {
continue;
}
ipToServices.put(ip, services);
}
}
return ipToServices;
}
use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class IpAddressManagerImpl method assignSystemIp.
@Override
public IpAddress assignSystemIp(final long networkId, final Account owner, final boolean forElasticLb, final boolean forElasticIp) throws InsufficientAddressCapacityException {
final Network guestNetwork = _networksDao.findById(networkId);
final NetworkOffering off = _entityMgr.findById(NetworkOffering.class, guestNetwork.getNetworkOfferingId());
IpAddress ip = null;
if ((off.getElasticLb() && forElasticLb) || (off.getElasticIp() && forElasticIp)) {
try {
s_logger.debug("Allocating system IP address for load balancer rule...");
// allocate ip
ip = allocateIP(owner, true, guestNetwork.getDataCenterId());
// apply ip associations
ip = associateIPToGuestNetwork(ip.getId(), networkId, true);
} catch (final ResourceAllocationException ex) {
throw new CloudRuntimeException("Failed to allocate system ip due to ", ex);
} catch (final ConcurrentOperationException ex) {
throw new CloudRuntimeException("Failed to allocate system lb ip due to ", ex);
} catch (final ResourceUnavailableException ex) {
throw new CloudRuntimeException("Failed to allocate system lb ip due to ", ex);
}
if (ip == null) {
throw new CloudRuntimeException("Failed to allocate system ip");
}
}
return ip;
}
use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class Ipv6AddressManagerImpl method assignDirectIp6Address.
@Override
public UserIpv6Address assignDirectIp6Address(final long dcId, final Account owner, final Long networkId, final String requestedIp6) throws InsufficientAddressCapacityException {
final Network network = _networkDao.findById(networkId);
if (network == null) {
return null;
}
final List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
if (vlans == null) {
s_logger.debug("Cannot find related vlan attached to network " + networkId);
return null;
}
String ip = null;
Vlan ipVlan = null;
if (requestedIp6 == null) {
if (!_networkModel.isIP6AddressAvailableInNetwork(networkId)) {
throw new InsufficientAddressCapacityException("There is no more address available in the network " + network.getName(), DataCenter.class, network.getDataCenterId());
}
for (final Vlan vlan : vlans) {
if (!_networkModel.isIP6AddressAvailableInVlan(vlan.getId())) {
continue;
}
ip = NetUtils.getIp6FromRange(vlan.getIp6Range());
int count = 0;
while (_ipv6Dao.findByNetworkIdAndIp(networkId, ip) != null) {
ip = NetUtils.getNextIp6InRange(ip, vlan.getIp6Range());
count++;
// It's an arbitrate number to prevent the infinite loop
if (count > _ipv6RetryMax) {
ip = null;
break;
}
}
if (ip != null) {
ipVlan = vlan;
}
}
if (ip == null) {
throw new InsufficientAddressCapacityException("Cannot find a usable IP in the network " + network.getName() + " after " + _ipv6RetryMax + "(network.ipv6.search.retry.max) times retry!", DataCenter.class, network.getDataCenterId());
}
} else {
for (final Vlan vlan : vlans) {
if (NetUtils.isIp6InRange(requestedIp6, vlan.getIp6Range())) {
ipVlan = vlan;
break;
}
}
if (ipVlan == null) {
throw new CloudRuntimeException("Requested IPv6 is not in the predefined range!");
}
ip = requestedIp6;
if (_ipv6Dao.findByNetworkIdAndIp(networkId, ip) != null) {
throw new CloudRuntimeException("The requested IP is already taken!");
}
}
final Zone zone = zoneRepository.findById(dcId).orElse(null);
final Long mac = zone.getMacAddress();
final Long nextMac = mac + 1;
zone.setMacAddress(nextMac);
zoneRepository.save(zone);
final String macAddress = NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(mac));
final UserIpv6AddressVO ipVO = new UserIpv6AddressVO(ip, dcId, macAddress, ipVlan.getId());
ipVO.setPhysicalNetworkId(network.getPhysicalNetworkId());
ipVO.setSourceNetworkId(networkId);
ipVO.setState(UserIpv6Address.State.Allocated);
ipVO.setDomainId(owner.getDomainId());
ipVO.setAccountId(owner.getAccountId());
_ipv6Dao.persist(ipVO);
return ipVO;
}
use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class NetworkModelImpl method getSystemAccountNetworkOfferings.
@Override
public List<NetworkOfferingVO> getSystemAccountNetworkOfferings(final String... offeringNames) {
final List<NetworkOfferingVO> offerings = new ArrayList<>(offeringNames.length);
for (final String offeringName : offeringNames) {
final NetworkOfferingVO network = _systemNetworks.get(offeringName);
if (network == null) {
throw new CloudRuntimeException("Unable to find system network profile for " + offeringName);
}
offerings.add(network);
}
return offerings;
}
use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class StorageNetworkManagerImpl method checkOverlapPrivateIpRange.
private void checkOverlapPrivateIpRange(final long podId, final String startIp, final String endIp) {
final HostPodVO pod = _podDao.findById(podId);
if (pod == null) {
throw new CloudRuntimeException("Cannot find pod " + podId);
}
final String[] IpRange = pod.getDescription().split("-");
if ((IpRange[0] == null || IpRange[1] == null) || (!NetUtils.isValidIp4(IpRange[0]) || !NetUtils.isValidIp4(IpRange[1]))) {
return;
}
if (NetUtils.ipRangesOverlap(startIp, endIp, IpRange[0], IpRange[1])) {
throw new InvalidParameterValueException("The Storage network Start IP and endIP address range overlap with private IP :" + IpRange[0] + ":" + IpRange[1]);
}
}
Aggregations