- establish model for transferring portable IP association from a network

with which it is associated to another network.

- enabling static nat api, extended to transfer potrtable IP across the
  networks if the VM/network is different from the current associate
  network of the portable ip
This commit is contained in:
Murali Reddy 2013-05-13 15:12:19 +05:30
parent 51509751b2
commit 895a27c277
6 changed files with 77 additions and 0 deletions

View File

@ -91,6 +91,11 @@ public class EnableStaticNatCmd extends BaseCmd{
} else {
ntwkId = networkId;
}
if (ip.isPortable() && networkId!= null ) {
ntwkId = networkId;
}
if (ntwkId == null) {
throw new InvalidParameterValueException("Unable to enable static nat for the ipAddress id=" + ipAddressId +
" as ip is not associated with any network and no networkId is passed in");

View File

@ -245,6 +245,8 @@ public interface NetworkManager {
IPAddressVO disassociatePortableIPToGuestNetwork(long ipAddrId, long networkId) throws ResourceAllocationException, ResourceUnavailableException,
InsufficientAddressCapacityException, ConcurrentOperationException;
boolean isPortableIpTransferableFromNetwork(long ipAddrId, long networkId);
/**
* @param network
* @param provider

View File

@ -989,6 +989,33 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
}
}
@Override
public boolean isPortableIpTransferableFromNetwork(long ipAddrId, long networkId) {
Network network = _networksDao.findById(networkId);
if (network == null) {
throw new InvalidParameterValueException("Invalid network id is given");
}
IPAddressVO ip = _ipAddressDao.findById(ipAddrId);
if (ip == null) {
throw new InvalidParameterValueException("Invalid network id is given");
}
// Check if IP has any services (rules) associated in the network
List<PublicIpAddress> ipList = new ArrayList<PublicIpAddress>();
PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId()));
ipList.add(publicIp);
Map<PublicIpAddress, Set<Service>> ipToServices = _networkModel.getIpToServices(ipList, false, true);
if (ipToServices != null & !ipToServices.isEmpty()) {
Set<Service> ipServices = ipToServices.get(publicIp);
if (ipServices != null && !ipServices.isEmpty()) {
return false;
}
}
return true;
}
@Override
@DB
public boolean disassociatePublicIpAddress(long addrId, long userId, Account caller) {

View File

@ -492,6 +492,39 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
}
performedIpAssoc = true;
}
if (ipAddress.isPortable()) {
s_logger.info("Portable IP " + ipAddress.getUuid() + " is not associated with the network, so" +
"associated IP with the network " + network.getUuid());
try {
_networkMgr.associatePortableIPToGuestNetwork(ipId, networkId, false);
} catch (Exception e) {
s_logger.warn("Failed to associate portable id=" + ipId + " to network id=" + networkId + " as " +
"a part of enable static nat");
return false;
}
}
} else if (ipAddress.getAssociatedWithNetworkId() != networkId) {
if (ipAddress.isPortable()) {
// check if portable IP can transferred across the network
if (_networkMgr.isPortableIpTransferableFromNetwork(ipId, ipAddress.getAssociatedWithNetworkId() )) {
try {
_networkMgr.disassociatePortableIPToGuestNetwork(ipId, ipAddress.getAssociatedWithNetworkId());
_networkMgr.associatePortableIPToGuestNetwork(ipId, networkId, false);
} catch (Exception e) {
s_logger.warn("Failed to associate portable id=" + ipId + " to network id=" + networkId + " as " +
"a part of enable static nat");
return false;
}
} else {
throw new InvalidParameterValueException("Portable IP: " + ipId + " has associated services" +
"in network " + ipAddress.getAssociatedWithNetworkId() + " so can not be transferred to " +
" network " + networkId);
}
} else {
throw new InvalidParameterValueException("Invalid network Id=" + networkId + " IP is associated with"
+ " a different network than passed network id");
}
} else {
_networkModel.checkIpForService(ipAddress, Service.StaticNat, null);
}

View File

@ -97,6 +97,11 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
return null; // TODO Auto-generated method stub
}
@Override
public boolean isPortableIpTransferableFromNetwork(long ipAddrId, long networkId) {
return false;
}
@Override
public boolean releaseIpAddress(long ipAddressId) {
// TODO Auto-generated method stub

View File

@ -213,6 +213,11 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
return false;// TODO Auto-generated method stub
}
@Override
public boolean isPortableIpTransferableFromNetwork(long ipAddrId, long networkId) {
return false;
}
/* (non-Javadoc)
* @see com.cloud.network.NetworkService#releaseIpAddress(long)
*/