cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [09/16] Divided NetworkManagerImpl into two files: NetworkManagerImpl and IpAddressManagerImpl
Date Mon, 19 Aug 2013 21:12:17 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/092e2020/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index 09ca758..cc5d246 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -40,7 +40,6 @@ import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
 
 import org.apache.cloudstack.acl.ControlledEntity.ACLType;
 import org.apache.cloudstack.acl.SecurityChecker.AccessType;
@@ -180,7 +179,6 @@ import com.cloud.vm.dao.VMInstanceDao;
 /**
  * NetworkServiceImpl implements NetworkService.
  */
-@Component
 @Local(value = { NetworkService.class })
 public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
     private static final Logger s_logger = Logger.getLogger(NetworkServiceImpl.class);
@@ -279,7 +277,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
     HostDao _hostDao;
     @Inject
     HostPodDao _hostPodDao;
-    @Inject 
+    @Inject
     InternalLoadBalancerElementService _internalLbElementSvc;
     @Inject
     DataCenterVnetDao _datacneter_vnet;
@@ -289,6 +287,8 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
     VpcDao _vpcDao;
     @Inject
     NetworkACLDao _networkACLDao;
+    @Inject
+    IpAddressManager _ipAddrMgr;
 
     int _cidrLimit;
     boolean _allowSubdomainNetworkAccess;
@@ -526,7 +526,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
                         if (s_logger.isDebugEnabled()) {
                             s_logger.debug("Associate IP address called by the user " + callerUserId + " account " + ipOwner.getId());
                         }
-                        return _networkMgr.allocateIp(ipOwner, false, caller, callerUserId, zone);
+                        return _ipAddrMgr.allocateIp(ipOwner, false, caller, callerUserId, zone);
                     } else {
                         throw new InvalidParameterValueException("Associate IP address can only be called on the shared networks in the advanced zone" +
                                 " with Firewall/Source Nat/Static Nat/Port Forwarding/Load balancing services enabled");
@@ -537,7 +537,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
             _accountMgr.checkAccess(caller, null, false, ipOwner);
         }
 
-        return _networkMgr.allocateIp(ipOwner, false, caller, callerUserId, zone);
+        return _ipAddrMgr.allocateIp(ipOwner, false, caller, callerUserId, zone);
     }
 
     @Override
@@ -569,7 +569,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
                         if (s_logger.isDebugEnabled()) {
                             s_logger.debug("Associate IP address called by the user " + callerUserId + " account " + ipOwner.getId());
                         }
-                        return _networkMgr.allocatePortableIp(ipOwner, caller, zoneId, networkId, null);
+                        return _ipAddrMgr.allocatePortableIp(ipOwner, caller, zoneId, networkId, null);
                     } else {
                         throw new InvalidParameterValueException("Associate IP address can only be called on the shared networks in the advanced zone" +
                                 " with Firewall/Source Nat/Static Nat/Port Forwarding/Load balancing services enabled");
@@ -587,7 +587,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
 
         _accountMgr.checkAccess(caller, null, false, ipOwner);
 
-        return _networkMgr.allocatePortableIp(ipOwner, caller, zoneId, null, null);
+        return _ipAddrMgr.allocatePortableIp(ipOwner, caller, zoneId, null, null);
     }
 
     @Override
@@ -680,7 +680,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
         s_logger.debug("Calling the ip allocation ...");
         if (dc.getNetworkType() == NetworkType.Advanced && network.getGuestType() == Network.GuestType.Isolated) {
             try {
-                ipaddr = _networkMgr.allocateGuestIP(ipOwner, false,  zoneId, networkId, requestedIp);
+                ipaddr = _ipAddrMgr.allocateGuestIP(ipOwner, false, zoneId, networkId, requestedIp);
             } catch (InsufficientAddressCapacityException e) {
                 throw new InvalidParameterValueException("Allocating guest ip for nic failed");
             }
@@ -697,7 +697,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
             }
 
             try {
-                ipaddr = _networkMgr.allocatePublicIpForGuestNic(networkId, dc, pod, caller, requestedIp);
+                ipaddr = _ipAddrMgr.allocatePublicIpForGuestNic(networkId, dc, pod, caller, requestedIp);
                 if (ipaddr == null) {
                     throw new InvalidParameterValueException("Allocating ip to guest nic " + nicId + " failed");
                 }
@@ -803,7 +803,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
             if (ip != null) {
                 Transaction txn = Transaction.currentTxn();
                 txn.start();
-                _networkMgr.markIpAsUnavailable(ip.getId());
+                _ipAddrMgr.markIpAsUnavailable(ip.getId());
                 _ipAddressDao.unassignIpAddress(ip.getId());
                 txn.commit();
             }
@@ -885,7 +885,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
             throw ex;
         }
 
-        boolean success = _networkMgr.disassociatePublicIpAddress(ipAddressId, userId, caller);
+        boolean success = _ipAddrMgr.disassociatePublicIpAddress(ipAddressId, userId, caller);
 
         if (success) {
             Long networkId = ipVO.getAssociatedWithNetworkId();
@@ -1289,7 +1289,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
                     }
                 }
             }
-            network = _vpcMgr.createVpcGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, 
+            network = _vpcMgr.createVpcGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
                     networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, aclId, caller, displayNetwork);
         } else {
             if (_configMgr.isOfferingForVpc(ntwkOff)){
@@ -1299,7 +1299,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
                 throw new InvalidParameterValueException("Internal Lb can be enabled on vpc networks only");
             }
 
-            network = _networkMgr.createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, 
+            network = _networkMgr.createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
             		networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId,
             		ip6Gateway, ip6Cidr, displayNetwork, isolatedPvlan);
         }
@@ -1497,7 +1497,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
             if (!permittedAccounts.isEmpty()) {
                 //get account level networks
                 networksToReturn.addAll(listAccountSpecificNetworks(
-                        buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, 
+                        buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
                                 physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags), searchFilter,
                         permittedAccounts));
                 //get domain level networks
@@ -1511,12 +1511,12 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
             } else {
                 //add account specific networks
                 networksToReturn.addAll(listAccountSpecificNetworksByDomainPath(
-                        buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, 
+                        buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
                                 physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags), searchFilter, path,
                         isRecursive));
                 //add domain specific networks of domain + parent domains
                 networksToReturn.addAll(listDomainSpecificNetworksByDomainPath(
-                        buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, 
+                        buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
                                 physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags), searchFilter, path,
                                 isRecursive));
                 //add networks of subdomains
@@ -2681,6 +2681,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
 
     public  String generateVnetString(List<String> vnetList) {
         Collections.sort(vnetList, new Comparator<String>() {
+            @Override
             public int compare(String s1, String s2) {
                 return Integer.valueOf(s1).compareTo(Integer.valueOf(s2));
             }
@@ -3700,7 +3701,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
     
     protected PhysicalNetworkServiceProvider addDefaultInternalLbProviderToPhysicalNetwork(long physicalNetworkId) {
 
-        PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId, 
+        PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId,
                 Network.Provider.InternalLbVm.getName(), null, null);
  
         NetworkElement networkElement =  _networkModel.getElementImplementingProvider(Network.Provider.InternalLbVm.getName());
@@ -3794,7 +3795,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService {
             throw new InvalidParameterValueException("Can't assign ip to the network directly when network belongs" +
                     " to VPC.Specify vpcId to associate ip address to VPC");
         }
-        return _networkMgr.associateIPToGuestNetwork(ipId, networkId, true);
+        return _ipAddrMgr.associateIPToGuestNetwork(ipId, networkId, true);
 
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/092e2020/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/firewall/FirewallManagerImpl.java b/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
index 1262513..ca58b40 100644
--- a/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
+++ b/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
@@ -5,7 +5,7 @@
 // to you under the Apache License, Version 2.0 (the
 // "License"); you may not use this file except in compliance
 // with the License.  You may obtain a copy of the License at
-// 
+//
 //   http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing,
@@ -27,17 +27,14 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.cloudstack.api.command.user.firewall.ListEgressFirewallRulesCmd;
-
-import com.cloud.network.dao.*;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
+import org.apache.cloudstack.api.command.user.firewall.ListEgressFirewallRulesCmd;
 import org.apache.cloudstack.api.command.user.firewall.ListFirewallRulesCmd;
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
 import com.cloud.configuration.Config;
 import com.cloud.domain.dao.DomainDao;
 import com.cloud.event.ActionEvent;
@@ -49,12 +46,19 @@ import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.NetworkRuleConflictException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.IpAddress;
+import com.cloud.network.IpAddressManager;
 import com.cloud.network.Network;
 import com.cloud.network.Network.Capability;
 import com.cloud.network.Network.Service;
 import com.cloud.network.NetworkManager;
 import com.cloud.network.NetworkModel;
 import com.cloud.network.NetworkRuleApplier;
+import com.cloud.network.dao.FirewallRulesCidrsDao;
+import com.cloud.network.dao.FirewallRulesDao;
+import com.cloud.network.dao.IPAddressDao;
+import com.cloud.network.dao.IPAddressVO;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.network.dao.NetworkVO;
 import com.cloud.network.element.FirewallServiceProvider;
 import com.cloud.network.element.NetworkACLServiceProvider;
 import com.cloud.network.element.PortForwardingServiceProvider;
@@ -136,6 +140,8 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
     @Inject List<StaticNatServiceProvider> _staticNatElements;
 
     @Inject List<NetworkACLServiceProvider> _networkAclElements;
+    @Inject
+    IpAddressManager _ipAddrMgr;
 
     private boolean _elbEnabled = false;
 
@@ -157,7 +163,7 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
             throw new InvalidParameterValueException("Egress firewall rules are not supported for " + network.getGuestType() + "  networks");
         }
         
-        return createFirewallRule(null, caller, rule.getXid(), rule.getSourcePortStart(), 
+        return createFirewallRule(null, caller, rule.getXid(), rule.getSourcePortStart(),
                 rule.getSourcePortEnd(), rule.getProtocol(), rule.getSourceCidrList(), rule.getIcmpCode(),
                 rule.getIcmpType(), null, rule.getType(), rule.getNetworkId(), rule.getTrafficType());
     }
@@ -167,7 +173,7 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
          Account caller = CallContext.current().getCallingAccount();
         Long sourceIpAddressId = rule.getSourceIpAddressId();
  
-        return createFirewallRule(sourceIpAddressId, caller, rule.getXid(), rule.getSourcePortStart(), 
+        return createFirewallRule(sourceIpAddressId, caller, rule.getXid(), rule.getSourcePortStart(),
                  rule.getSourcePortEnd(), rule.getProtocol(), rule.getSourceCidrList(), rule.getIcmpCode(),
                 rule.getIcmpType(), null, rule.getType(), rule.getNetworkId(), rule.getTrafficType());
     }
@@ -188,7 +194,7 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
               throw new InvalidParameterValueException("Unable to create firewall rule; " +
                     "couldn't locate IP address by id in the system");
         }
-        _networkModel.checkIpForService(ipAddress, Service.Firewall, null);  
+        _networkModel.checkIpForService(ipAddress, Service.Firewall, null);
         }
 
         validateFirewallRule(caller, ipAddress, portStart, portEnd, protocol, Purpose.Firewall, type, networkId, trafficType);
@@ -369,7 +375,7 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
 
             if (!oneOfRulesIsFirewall) {
                 if (rule.getPurpose() == Purpose.StaticNat && newRule.getPurpose() != Purpose.StaticNat) {
-                    throw new NetworkRuleConflictException("There is 1 to 1 Nat rule specified for the ip address id=" 
+                    throw new NetworkRuleConflictException("There is 1 to 1 Nat rule specified for the ip address id="
                             + newRule.getSourceIpAddressId());
                 } else if (rule.getPurpose() != Purpose.StaticNat && newRule.getPurpose() == Purpose.StaticNat) {
                     throw new NetworkRuleConflictException("There is already firewall rule specified for the ip address id="
@@ -383,25 +389,25 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
             }
 
             if (newRule.getProtocol().equalsIgnoreCase(NetUtils.ICMP_PROTO) && newRule.getProtocol().equalsIgnoreCase(rule.getProtocol())) {
-                if (newRule.getIcmpCode().longValue() == rule.getIcmpCode().longValue() 
+                if (newRule.getIcmpCode().longValue() == rule.getIcmpCode().longValue()
                         && newRule.getIcmpType().longValue() == rule.getIcmpType().longValue()
                         && newRule.getProtocol().equalsIgnoreCase(rule.getProtocol()) && duplicatedCidrs) {
                     throw new InvalidParameterValueException("New rule conflicts with existing rule id=" + rule.getId());
                 }
             }
 
-            boolean notNullPorts = (newRule.getSourcePortStart() != null && newRule.getSourcePortEnd() != null && 
+            boolean notNullPorts = (newRule.getSourcePortStart() != null && newRule.getSourcePortEnd() != null &&
                     rule.getSourcePortStart() != null && rule.getSourcePortEnd() != null);
             if (!notNullPorts) {
                 continue;
             } else if (!oneOfRulesIsFirewall && !(bothRulesFirewall && !duplicatedCidrs)
-                    && ((rule.getSourcePortStart().intValue() <= newRule.getSourcePortStart().intValue() 
+                    && ((rule.getSourcePortStart().intValue() <= newRule.getSourcePortStart().intValue()
                     && rule.getSourcePortEnd().intValue() >= newRule.getSourcePortStart().intValue())
-                    || (rule.getSourcePortStart().intValue() <= newRule.getSourcePortEnd().intValue() 
+                    || (rule.getSourcePortStart().intValue() <= newRule.getSourcePortEnd().intValue()
                     && rule.getSourcePortEnd().intValue() >= newRule.getSourcePortEnd().intValue())
-                    || (newRule.getSourcePortStart().intValue() <= rule.getSourcePortStart().intValue() 
+                    || (newRule.getSourcePortStart().intValue() <= rule.getSourcePortStart().intValue()
                     && newRule.getSourcePortEnd().intValue() >= rule.getSourcePortStart().intValue())
-                    || (newRule.getSourcePortStart().intValue() <= rule.getSourcePortEnd().intValue() 
+                    || (newRule.getSourcePortStart().intValue() <= rule.getSourcePortEnd().intValue()
                     && newRule.getSourcePortEnd().intValue() >= rule.getSourcePortEnd().intValue()))) {
 
                 // we allow port forwarding rules with the same parameters but different protocols
@@ -423,7 +429,7 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
     }
 
     @Override
-    public void validateFirewallRule(Account caller, IPAddressVO ipAddress, Integer portStart, Integer portEnd, 
+    public void validateFirewallRule(Account caller, IPAddressVO ipAddress, Integer portStart, Integer portEnd,
             String proto, Purpose purpose, FirewallRuleType type, Long networkId, FirewallRule.TrafficType trafficType ) {
         if (portStart != null && !NetUtils.isValidPort(portStart)) {
             throw new InvalidParameterValueException("publicPort is an invalid value: " + portStart);
@@ -452,7 +458,7 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
             _accountMgr.checkAccess(caller, null, true, ipAddress);
         }
         
-        //network id either has to be passed explicitly, or implicitly as a part of ipAddress object 
+        //network id either has to be passed explicitly, or implicitly as a part of ipAddress object
         if (networkId == null) {
             throw new InvalidParameterValueException("Unable to retrieve network id to validate the rule");
         }
@@ -502,7 +508,7 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
     }
 
     @Override
-    public boolean applyRules(List<? extends FirewallRule> rules, boolean continueOnError, boolean updateRulesInDB) 
+    public boolean applyRules(List<? extends FirewallRule> rules, boolean continueOnError, boolean updateRulesInDB)
             throws ResourceUnavailableException {
         boolean success = true;
         if (rules == null || rules.size() == 0) {
@@ -510,7 +516,7 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
             return true;
         }
         Purpose purpose = rules.get(0).getPurpose();
-        if (!_networkMgr.applyRules(rules, purpose, this, continueOnError)) {
+        if (!_ipAddrMgr.applyRules(rules, purpose, this, continueOnError)) {
             s_logger.warn("Rules are not completely applied");
             return false;
         } else {
@@ -519,7 +525,7 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
                     if (rule.getState() == FirewallRule.State.Revoke) {
                         FirewallRuleVO relatedRule = _firewallDao.findByRelatedId(rule.getId());
                         if (relatedRule != null) {
-                            s_logger.warn("Can't remove the firewall rule id=" + rule.getId() + 
+                            s_logger.warn("Can't remove the firewall rule id=" + rule.getId() +
                                     " as it has related firewall rule id=" + relatedRule.getId() + "; leaving it in Revoke state");
                             success = false;
                         } else {
@@ -543,7 +549,7 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
     }
 
     @Override
-    public  boolean applyRules(Network network, Purpose purpose, List<? extends FirewallRule> rules) 
+    public  boolean applyRules(Network network, Purpose purpose, List<? extends FirewallRule> rules)
             throws ResourceUnavailableException {
         boolean handled = false;
         switch (purpose){
@@ -704,7 +710,7 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
 
         if (apply) {
             // ingress firewall rule
-            if (rule.getSourceIpAddressId() != null){ 
+            if (rule.getSourceIpAddressId() != null){
                 //feteches ingress firewall, ingress firewall rules associated with the ip
             List<FirewallRuleVO> rules = _firewallDao.listByIpAndPurpose(rule.getSourceIpAddressId(), Purpose.Firewall);
             return applyFirewallRules(rules, false, caller);
@@ -916,8 +922,8 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
             try {
                 if (rule.getSourceCidrList() == null && (rule.getPurpose() == Purpose.Firewall || rule.getPurpose() == Purpose.NetworkACL)) {
                     _firewallDao.loadSourceCidrs(rule);
-                } 
-                this.createFirewallRule(ip.getId(), acct, rule.getXid(), rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(),
+                }
+                createFirewallRule(ip.getId(), acct, rule.getXid(), rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(),
                         rule.getSourceCidrList(), rule.getIcmpCode(), rule.getIcmpType(), rule.getRelated(), FirewallRuleType.System, rule.getNetworkId(), rule.getTrafficType());
             } catch (Exception e) {
                 s_logger.debug("Failed to add system wide firewall rule, due to:" + e.toString());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/092e2020/server/src/com/cloud/network/guru/DirectNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/DirectNetworkGuru.java b/server/src/com/cloud/network/guru/DirectNetworkGuru.java
index 5d0e7b1..98533a0 100755
--- a/server/src/com/cloud/network/guru/DirectNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/DirectNetworkGuru.java
@@ -33,6 +33,7 @@ import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientAddressCapacityException;
 import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
 import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.network.IpAddressManager;
 import com.cloud.network.Ipv6AddressManager;
 import com.cloud.network.Network;
 import com.cloud.network.Network.GuestType;
@@ -88,6 +89,8 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
     NicSecondaryIpDao _nicSecondaryIpDao;
     @Inject
     NicDao _nicDao;
+    @Inject
+    IpAddressManager _ipAddrMgr;
 
     private static final TrafficType[] _trafficTypes = {TrafficType.Guest};
     
@@ -191,7 +194,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
     public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException,
             InsufficientAddressCapacityException, ConcurrentOperationException {
 
-        DataCenter dc = _dcDao.findById(network.getDataCenterId());    
+        DataCenter dc = _dcDao.findById(network.getDataCenterId());
 
         if (nic == null) {
             nic = new NicProfile(ReservationStrategy.Create, null, null, null, null);
@@ -223,7 +226,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
         
         Transaction txn = Transaction.currentTxn();
         txn.start();
-        _networkMgr.allocateDirectIp(nic, dc, vm, network, requestedIp4Addr, requestedIp6Addr);
+        _ipAddrMgr.allocateDirectIp(nic, dc, vm, network, requestedIp4Addr, requestedIp6Addr);
         //save the placeholder nic if the vm is the Virtual router
         if (vm.getType() == VirtualMachine.Type.DomainRouter) {
             Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, null);
@@ -262,7 +265,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
                 if (placeholderNic != null && placeholderNic.getIp4Address().equalsIgnoreCase(ip.getAddress().addr())) {
                     s_logger.debug("Not releasing direct ip " + ip.getId() +" yet as its ip is saved in the placeholder");
                 } else {
-                    _networkMgr.markIpAsUnavailable(ip.getId());
+                    _ipAddrMgr.markIpAsUnavailable(ip.getId());
                     _ipAddressDao.unassignIpAddress(ip.getId());
                 }
                
@@ -272,7 +275,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
                 nicSecIps = _nicSecondaryIpDao.getSecondaryIpAddressesForNic(nic.getId());
                 for (String secIp: nicSecIps) {
                     IPAddressVO pubIp = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), secIp);
-                    _networkMgr.markIpAsUnavailable(pubIp.getId());
+                    _ipAddrMgr.markIpAsUnavailable(pubIp.getId());
                     _ipAddressDao.unassignIpAddress(pubIp.getId());
                 }
     
@@ -301,7 +304,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
             if (nic.getIp4Address() != null) {
                 s_logger.debug("Releasing ip " + nic.getIp4Address() + " of placeholder nic " + nic);
                 IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
-                _networkMgr.markIpAsUnavailable(ip.getId());
+                _ipAddrMgr.markIpAsUnavailable(ip.getId());
                 _ipAddressDao.unassignIpAddress(ip.getId());
                 s_logger.debug("Removing placeholder nic " + nic);
                 _nicDao.remove(nic.getId());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/092e2020/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java b/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
index 110096b..5b87d54 100755
--- a/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
@@ -40,6 +40,7 @@ import com.cloud.deploy.DeployDestination;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientAddressCapacityException;
 import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
+import com.cloud.network.IpAddressManager;
 import com.cloud.network.Network;
 import com.cloud.network.NetworkManager;
 import com.cloud.network.Networks.AddressFormat;
@@ -75,6 +76,8 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
     NetworkOfferingDao _networkOfferingDao;
     @Inject
     PodVlanMapDao _podVlanDao;
+    @Inject
+    IpAddressManager _ipAddrMgr;
 
     @Override
     protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
@@ -137,7 +140,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
                     txn.start();
                     
                     //release the old ip here
-                    _networkMgr.markIpAsUnavailable(ipVO.getId());
+                    _ipAddrMgr.markIpAsUnavailable(ipVO.getId());
                     _ipAddressDao.unassignIpAddress(ipVO.getId());
                     
                     txn.commit();
@@ -149,7 +152,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
         }
         
         if (getNewIp) {
-            //we don't set reservationStrategy to Create because we need this method to be called again for the case when vm fails to deploy in Pod1, and we try to redeploy it in Pod2 
+            //we don't set reservationStrategy to Create because we need this method to be called again for the case when vm fails to deploy in Pod1, and we try to redeploy it in Pod2
             getIp(nic, dest.getPod(), vm, network);
         }
         
@@ -183,7 +186,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
             }
             
             if (ip == null) {
-                ip = _networkMgr.assignPublicIpAddress(dc.getId(), pod.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId(), null, false);
+                ip = _ipAddrMgr.assignPublicIpAddress(dc.getId(), pod.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId(), null, false);
             }
             
             nic.setIp4Address(ip.getAddress().toString());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/092e2020/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
index fdab0c6..00598dd 100644
--- a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
@@ -21,10 +21,6 @@ import java.util.List;
 import javax.ejb.Local;
 import javax.inject.Inject;
 
-import com.cloud.event.ActionEventUtils;
-
-import com.cloud.network.dao.IPAddressDao;
-import com.cloud.network.dao.IPAddressVO;
 import org.apache.log4j.Logger;
 
 import org.apache.cloudstack.context.CallContext;
@@ -35,10 +31,12 @@ import com.cloud.dc.DataCenter.NetworkType;
 import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.deploy.DeployDestination;
 import com.cloud.deploy.DeploymentPlan;
+import com.cloud.event.ActionEventUtils;
 import com.cloud.event.EventTypes;
 import com.cloud.event.EventVO;
 import com.cloud.exception.InsufficientAddressCapacityException;
 import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
+import com.cloud.network.IpAddressManager;
 import com.cloud.network.Network;
 import com.cloud.network.Network.GuestType;
 import com.cloud.network.Network.State;
@@ -46,6 +44,8 @@ import com.cloud.network.NetworkManager;
 import com.cloud.network.Networks.BroadcastDomainType;
 import com.cloud.network.PhysicalNetwork;
 import com.cloud.network.PhysicalNetwork.IsolationMethod;
+import com.cloud.network.dao.IPAddressDao;
+import com.cloud.network.dao.IPAddressVO;
 import com.cloud.network.dao.NetworkDao;
 import com.cloud.network.dao.NetworkVO;
 import com.cloud.network.rules.PortForwardingRuleVO;
@@ -60,7 +60,6 @@ import com.cloud.vm.Nic.ReservationStrategy;
 import com.cloud.vm.NicProfile;
 import com.cloud.vm.NicVO;
 import com.cloud.vm.ReservationContext;
-import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachineProfile;
 
 @Local(value = NetworkGuru.class)
@@ -76,6 +75,8 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
     PortForwardingRulesDao _pfRulesDao;
     @Inject
     IPAddressDao _ipAddressDao;
+    @Inject
+    IpAddressManager _ipAddrMgr;
 
 
     public ExternalGuestNetworkGuru() {
@@ -83,6 +84,7 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
         _isolationMethods = new IsolationMethod[] { IsolationMethod.GRE, IsolationMethod.L3, IsolationMethod.VLAN };
     }
 
+    @Override
     protected boolean canHandle(NetworkOffering offering,
             final NetworkType networkType, final PhysicalNetwork physicalNetwork) {
         // This guru handles only Guest Isolated network that supports Source
@@ -98,7 +100,7 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
                     + NetworkType.Advanced);
             return false;
         }
-    }    
+    }
     
     @Override
     public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
@@ -278,7 +280,7 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
             nic.setGateway(config.getGateway());
 
             if (nic.getIp4Address() == null) {
-                String guestIp = _networkMgr.acquireGuestIpAddress(config, null);
+                String guestIp = _ipAddrMgr.acquireGuestIpAddress(config, null);
                 if (guestIp == null) {
                     throw new InsufficientVirtualNetworkCapcityException("Unable to acquire guest IP address for network " + config, DataCenter.class, dc.getId());
                 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/092e2020/server/src/com/cloud/network/guru/GuestNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/GuestNetworkGuru.java b/server/src/com/cloud/network/guru/GuestNetworkGuru.java
index 3fa0dd7..b0da42f 100755
--- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java
@@ -5,7 +5,7 @@
 // to you under the Apache License, Version 2.0 (the
 // "License"); you may not use this file except in compliance
 // with the License.  You may obtain a copy of the License at
-// 
+//
 //   http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing,
@@ -19,16 +19,10 @@ package com.cloud.network.guru;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Random;
-import java.util.SortedSet;
-import java.util.TreeSet;
 
 import javax.ejb.Local;
 import javax.inject.Inject;
 
-import com.cloud.event.ActionEventUtils;
-import com.cloud.server.ConfigurationServer;
-import com.cloud.utils.Pair;
-
 import org.apache.log4j.Logger;
 
 import org.apache.cloudstack.context.CallContext;
@@ -41,12 +35,16 @@ import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.dc.dao.VlanDao;
 import com.cloud.deploy.DeployDestination;
 import com.cloud.deploy.DeploymentPlan;
+import com.cloud.event.ActionEventUtils;
 import com.cloud.event.EventTypes;
 import com.cloud.event.EventVO;
 import com.cloud.exception.InsufficientAddressCapacityException;
 import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
 import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.network.IpAddressManager;
 import com.cloud.network.Network;
+import com.cloud.network.Network.Provider;
+import com.cloud.network.Network.Service;
 import com.cloud.network.Network.State;
 import com.cloud.network.NetworkManager;
 import com.cloud.network.NetworkModel;
@@ -64,12 +62,13 @@ import com.cloud.network.dao.NetworkVO;
 import com.cloud.network.dao.PhysicalNetworkDao;
 import com.cloud.network.dao.PhysicalNetworkVO;
 import com.cloud.offering.NetworkOffering;
+import com.cloud.server.ConfigurationServer;
 import com.cloud.user.Account;
+import com.cloud.utils.Pair;
 import com.cloud.utils.component.AdapterBase;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.net.Ip4Address;
 import com.cloud.utils.net.NetUtils;
 import com.cloud.vm.Nic.ReservationStrategy;
 import com.cloud.vm.NicProfile;
@@ -77,8 +76,6 @@ import com.cloud.vm.ReservationContext;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.dao.NicDao;
-import com.cloud.network.Network.Provider;
-import com.cloud.network.Network.Service;
 
 @Local(value = NetworkGuru.class)
 public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
@@ -99,10 +96,12 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
     protected NetworkDao _networkDao;
     @Inject
     IPAddressDao _ipAddressDao;
-    @Inject 
-    protected PhysicalNetworkDao _physicalNetworkDao;    
+    @Inject
+    protected PhysicalNetworkDao _physicalNetworkDao;
     @Inject
     ConfigurationServer _configServer;
+    @Inject
+    IpAddressManager _ipAddrMgr;
     Random _rand = new Random(System.currentTimeMillis());
 
     private static final TrafficType[] _trafficTypes = {TrafficType.Guest};
@@ -179,7 +178,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
         NetworkVO network = new NetworkVO(offering.getTrafficType(), Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(),
                 State.Allocated, plan.getDataCenterId(), plan.getPhysicalNetworkId());
         if (userSpecified != null) {
-            if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) || 
+            if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) ||
                     (userSpecified.getCidr() != null && userSpecified.getGateway() == null)) {
                 throw new InvalidParameterValueException("cidr and gateway must be specified together.");
             }
@@ -226,7 +225,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
             if (ip != null) {
                 Transaction txn = Transaction.currentTxn();
                 txn.start();
-                _networkMgr.markIpAsUnavailable(ip.getId());
+                _ipAddrMgr.markIpAsUnavailable(ip.getId());
                 _ipAddressDao.unassignIpAddress(ip.getId());
                 txn.commit();
             }
@@ -285,7 +284,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
     }
     
     @Override
-    public Network implement(Network network, NetworkOffering offering, DeployDestination dest, 
+    public Network implement(Network network, NetworkOffering offering, DeployDestination dest,
             ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
         assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
 
@@ -295,11 +294,11 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
         Long physicalNetworkId = network.getPhysicalNetworkId();
         
        // physical network id can be null in Guest Network in Basic zone, so locate the physical network
-       if (physicalNetworkId == null) {        
+       if (physicalNetworkId == null) {
            physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
        }
 
-        NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), 
+        NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(),
                 network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
                 network.getDataCenterId(), physicalNetworkId);
 
@@ -332,11 +331,11 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
         if (nic.getIp4Address() == null) {
             nic.setBroadcastUri(network.getBroadcastUri());
             nic.setIsolationUri(network.getBroadcastUri());
-            nic.setGateway(network.getGateway()); 
+            nic.setGateway(network.getGateway());
 
             String guestIp = null;
             if (network.getSpecifyIpRanges()) {
-                _networkMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIpv4(), null);
+                _ipAddrMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIpv4(), null);
             } else {
                 //if Vm is router vm and source nat is enabled in the network, set ip4 to the network gateway
                 boolean isGateway = false;
@@ -355,7 +354,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
                 if (isGateway) {
                     guestIp = network.getGateway();
                 } else {
-                    guestIp = _networkMgr.acquireGuestIpAddress(network, nic.getRequestedIpv4());
+                    guestIp = _ipAddrMgr.acquireGuestIpAddress(network, nic.getRequestedIpv4());
                     if (guestIp == null) {
                         throw new InsufficientVirtualNetworkCapcityException("Unable to acquire Guest IP" +
                                 " address for network " + network, DataCenter.class, dc.getId());
@@ -412,10 +411,10 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
     @Override
     public void shutdown(NetworkProfile profile, NetworkOffering offering) {
         
-        if (profile.getBroadcastDomainType() == BroadcastDomainType.Vlan && 
+        if (profile.getBroadcastDomainType() == BroadcastDomainType.Vlan &&
         		profile.getBroadcastUri() != null && !offering.getSpecifyVlan()) {
         s_logger.debug("Releasing vnet for the network id=" + profile.getId());
-            _dcDao.releaseVnet(profile.getBroadcastUri().getHost(), profile.getDataCenterId(), 
+            _dcDao.releaseVnet(profile.getBroadcastUri().getHost(), profile.getDataCenterId(),
                     profile.getPhysicalNetworkId(), profile.getAccountId(), profile.getReservationId());
             ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), profile.getAccountId(),
                     EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_RELEASE, "Released Zone Vlan: "

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/092e2020/server/src/com/cloud/network/guru/PublicNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/PublicNetworkGuru.java b/server/src/com/cloud/network/guru/PublicNetworkGuru.java
index 8beb42e..d109468 100755
--- a/server/src/com/cloud/network/guru/PublicNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/PublicNetworkGuru.java
@@ -5,7 +5,7 @@
 // to you under the Apache License, Version 2.0 (the
 // "License"); you may not use this file except in compliance
 // with the License.  You may obtain a copy of the License at
-// 
+//
 //   http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing,
@@ -30,6 +30,7 @@ import com.cloud.deploy.DeploymentPlan;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientAddressCapacityException;
 import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
+import com.cloud.network.IpAddressManager;
 import com.cloud.network.Network;
 import com.cloud.network.Network.State;
 import com.cloud.network.NetworkManager;
@@ -67,6 +68,8 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
     NetworkManager _networkMgr;
     @Inject
     IPAddressDao _ipAddressDao;
+    @Inject
+    IpAddressManager _ipAddrMgr;
 
     private static final TrafficType[] _trafficTypes = {TrafficType.Public};
 
@@ -110,7 +113,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
     protected void getIp(NicProfile nic, DataCenter dc, VirtualMachineProfile vm, Network network) throws InsufficientVirtualNetworkCapcityException,
     InsufficientAddressCapacityException, ConcurrentOperationException {
         if (nic.getIp4Address() == null) {
-            PublicIp ip = _networkMgr.assignPublicIpAddress(dc.getId(), null, vm.getOwner(), VlanType.VirtualNetwork, null, null, false);
+            PublicIp ip = _ipAddrMgr.assignPublicIpAddress(dc.getId(), null, vm.getOwner(), VlanType.VirtualNetwork, null, null, false);
             nic.setIp4Address(ip.getAddress().toString());
             nic.setGateway(ip.getGateway());
             nic.setNetmask(ip.getNetmask());
@@ -136,11 +139,11 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
     }
 
     @Override
-    public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) 
+    public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm)
             throws InsufficientVirtualNetworkCapcityException,
     InsufficientAddressCapacityException, ConcurrentOperationException {
 
-        DataCenter dc = _dcDao.findById(network.getDataCenterId());       
+        DataCenter dc = _dcDao.findById(network.getDataCenterId());
 
         if (nic != null && nic.getRequestedIpv4() != null) {
             throw new CloudRuntimeException("Does not support custom ip allocation at this time: " + nic);
@@ -194,7 +197,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
             Transaction txn = Transaction.currentTxn();
             txn.start();
 
-            _networkMgr.markIpAsUnavailable(ip.getId());
+            _ipAddrMgr.markIpAsUnavailable(ip.getId());
             _ipAddressDao.unassignIpAddress(ip.getId());
 
             txn.commit();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/092e2020/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
index 79f3cf8..e97fd56 100755
--- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
+++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
@@ -5,7 +5,7 @@
 // to you under the Apache License, Version 2.0 (the
 // "License"); you may not use this file except in compliance
 // with the License.  You may obtain a copy of the License at
-// 
+//
 //   http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing,
@@ -30,12 +30,11 @@ import java.util.Set;
 import javax.ejb.Local;
 import javax.inject.Inject;
 
-import com.cloud.network.ExternalDeviceUsageManager;
-import com.cloud.network.IpAddress;
-import com.cloud.network.LBHealthCheckPolicyVO;
-import com.cloud.network.Network;
-import com.cloud.network.NetworkManager;
-import com.cloud.network.NetworkModel;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
 
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.command.user.loadbalancer.CreateLBHealthCheckPolicyCmd;
@@ -51,9 +50,6 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
 import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao;
 
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
 import com.cloud.agent.api.to.LoadBalancerTO;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.ConfigurationManager;
@@ -72,9 +68,16 @@ import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.NetworkRuleConflictException;
 import com.cloud.exception.PermissionDeniedException;
 import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.ExternalDeviceUsageManager;
+import com.cloud.network.IpAddress;
+import com.cloud.network.IpAddressManager;
+import com.cloud.network.LBHealthCheckPolicyVO;
+import com.cloud.network.Network;
 import com.cloud.network.Network.Capability;
 import com.cloud.network.Network.Provider;
 import com.cloud.network.Network.Service;
+import com.cloud.network.NetworkManager;
+import com.cloud.network.NetworkModel;
 import com.cloud.network.addr.PublicIp;
 import com.cloud.network.as.AutoScalePolicy;
 import com.cloud.network.as.AutoScalePolicyConditionMapVO;
@@ -158,9 +161,6 @@ import com.cloud.vm.VirtualMachine.State;
 import com.cloud.vm.dao.NicDao;
 import com.cloud.vm.dao.UserVmDao;
 
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
-
 @Component
 @Local(value = { LoadBalancingRulesManager.class, LoadBalancingRulesService.class })
 public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements LoadBalancingRulesManager,
@@ -247,6 +247,8 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
     @Inject
     List<LoadBalancingServiceProvider> _lbProviders;
     @Inject ApplicationLoadBalancerRuleDao _appLbRuleDao;
+    @Inject
+    IpAddressManager _ipAddrMgr;
 
     // Will return a string. For LB Stickiness this will be a json, for
     // autoscale this will be "," separated values
@@ -901,7 +903,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
                     if (lbrules.size() > 0) {
                         isHandled = false;
                         for (LoadBalancingServiceProvider lbElement : _lbProviders) {
-                            stateRules = lbElement.updateHealthChecks(network, (List<LoadBalancingRule>) lbrules);
+                            stateRules = lbElement.updateHealthChecks(network, lbrules);
                             if (stateRules != null && stateRules.size() > 0) {
                                 for (LoadBalancerTO lbto : stateRules) {
                                     LoadBalancerVO ulb = _lbDao.findByUuid(lbto.getUuid());
@@ -1299,7 +1301,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_CREATE, eventDescription = "creating load balancer")
-    public LoadBalancer createPublicLoadBalancerRule(String xId, String name, String description, 
+    public LoadBalancer createPublicLoadBalancerRule(String xId, String name, String description,
             int srcPortStart, int srcPortEnd, int defPortStart, int defPortEnd, Long ipAddrId, String protocol, String algorithm, long networkId, long lbOwnerId, boolean openFirewall)
             throws NetworkRuleConflictException, InsufficientAddressCapacityException {
         Account lbOwner = _accountMgr.getAccount(lbOwnerId);
@@ -1325,7 +1327,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
             IpAddress systemIp = null;
             NetworkOffering off = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
             if (off.getElasticLb() && ipVO == null && network.getVpcId() == null) {
-                systemIp = _networkMgr.assignSystemIp(networkId, lbOwner, true, false);
+                systemIp = _ipAddrMgr.assignSystemIp(networkId, lbOwner, true, false);
                 ipVO = _ipAddressDao.findById(systemIp.getId());
             }
 
@@ -1348,7 +1350,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
 
                         s_logger.debug("The ip is not associated with the VPC network id=" + networkId
                                 + " so assigning");
-                        ipVO = _networkMgr.associateIPToGuestNetwork(ipAddrId, networkId, false);
+                        ipVO = _ipAddrMgr.associateIPToGuestNetwork(ipAddrId, networkId, false);
                         performedIpAssoc = true;
                     }
                 } else {
@@ -1370,7 +1372,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
                 if (result == null && systemIp != null) {
                     s_logger.debug("Releasing system IP address " + systemIp
                             + " as corresponding lb rule failed to create");
-                    _networkMgr.handleSystemIpRelease(systemIp);
+                    _ipAddrMgr.handleSystemIpRelease(systemIp);
                 }
                 // release ip address if ipassoc was perfored
                 if (performedIpAssoc) {
@@ -1389,7 +1391,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
 
     @DB
     @Override
-    public LoadBalancer createPublicLoadBalancer(String xId, String name, String description, 
+    public LoadBalancer createPublicLoadBalancer(String xId, String name, String description,
             int srcPort, int destPort, long sourceIpId, String protocol, String algorithm, boolean openFirewall, CallContext caller)
             throws NetworkRuleConflictException {
         
@@ -1410,7 +1412,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
                 ex.addProxyObject(String.valueOf(sourceIpId), "sourceIpId");
             }
             else{
-                ex.addProxyObject(ipAddr.getUuid(), "sourceIpId");                
+                ex.addProxyObject(ipAddr.getUuid(), "sourceIpId");
             }
             throw ex;
         } else if (ipAddr.isOneToOneNat()) {
@@ -1677,7 +1679,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
         boolean success = true;
         if (ip.getSystem()) {
             s_logger.debug("Releasing system ip address " + lb.getSourceIpAddressId() + " as a part of delete lb rule");
-            if (!_networkMgr.disassociatePublicIpAddress(lb.getSourceIpAddressId(), CallContext.current()
+            if (!_ipAddrMgr.disassociatePublicIpAddress(lb.getSourceIpAddressId(), CallContext.current()
                     .getCallingUserId(), CallContext.current().getCallingAccount())) {
                 s_logger.warn("Unable to release system ip address id=" + lb.getSourceIpAddressId()
                         + " as a part of delete lb rule");
@@ -2085,7 +2087,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
         // service provider, so run IP assoication for
         // the network so as to ensure IP is associated before applying
         // rules (in add state)
-        _networkMgr.applyIpAssociations(network, false, continueOnError, publicIps);
+        _ipAddrMgr.applyIpAssociations(network, false, continueOnError, publicIps);
         
 
         try {
@@ -2100,7 +2102,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
 
         // if all the rules configured on public IP are revoked then
         // dis-associate IP with network service provider
-        _networkMgr.applyIpAssociations(network, true, continueOnError, publicIps);
+        _ipAddrMgr.applyIpAssociations(network, true, continueOnError, publicIps);
         
         return success;
     }
@@ -2140,7 +2142,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
             }
         } else {
             if (!off.getInternalLb()) {
-                throw new InvalidParameterValueException("Scheme " + scheme + " is not supported by the network offering " + off);    
+                throw new InvalidParameterValueException("Scheme " + scheme + " is not supported by the network offering " + off);
             }
         }
         

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/092e2020/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index 584c070..42990ec 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -134,6 +134,7 @@ import com.cloud.host.Status;
 import com.cloud.host.dao.HostDao;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.network.IpAddress;
+import com.cloud.network.IpAddressManager;
 import com.cloud.network.Network;
 import com.cloud.network.Network.GuestType;
 import com.cloud.network.Network.Provider;
@@ -359,6 +360,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     UserIpv6AddressDao _ipv6Dao;
     @Inject
     NetworkService _networkSvc;
+    @Inject
+    IpAddressManager _ipAddrMgr;
 
     
     int _routerRamSize;
@@ -1530,7 +1533,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
             PublicIp sourceNatIp = null;
             if (publicNetwork) {
-                sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork);
+                    sourceNatIp = _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork);
             }
 
                 // 3) deploy virtual router(s)
@@ -1791,7 +1794,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp, defaultNetworkStartIpv6);
             if (setupPublicNetwork) {
                 if (isRedundant) {
-                    gatewayNic.setIp4Address(_networkMgr.acquireGuestIpAddress(guestNetwork, null));
+                    gatewayNic.setIp4Address(_ipAddrMgr.acquireGuestIpAddress(guestNetwork, null));
                 } else {
                     gatewayNic.setIp4Address(guestNetwork.getGateway());
                 }
@@ -2817,10 +2820,24 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                             vlanDbIdList.add(vlan.getId());
                         }
                         if (dc.getNetworkType() == NetworkType.Basic) {
-                        routerPublicIP = _networkMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(), vm.getPodIdToDeployIn(), caller, Vlan.VlanType.DirectAttached, vlanDbIdList, nic.getNetworkId(), null, false);
+                            routerPublicIP = _ipAddrMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(),
+                                vm.getPodIdToDeployIn(),
+                                caller,
+                                Vlan.VlanType.DirectAttached,
+                                vlanDbIdList,
+                                nic.getNetworkId(),
+                                null,
+                                false);
                         }
                         else {
-                            routerPublicIP = _networkMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(), null, caller, Vlan.VlanType.DirectAttached, vlanDbIdList, nic.getNetworkId(), null, false);
+                            routerPublicIP = _ipAddrMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(),
+                                null,
+                                caller,
+                                Vlan.VlanType.DirectAttached,
+                                vlanDbIdList,
+                                nic.getNetworkId(),
+                                null,
+                                false);
                         }
 
                         routerAliasIp = routerPublicIP.getAddress().addr();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/092e2020/server/src/com/cloud/network/rules/RulesManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java
index a2f5da3..7233506 100755
--- a/server/src/com/cloud/network/rules/RulesManagerImpl.java
+++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java
@@ -5,7 +5,7 @@
 // to you under the Apache License, Version 2.0 (the
 // "License"); you may not use this file except in compliance
 // with the License.  You may obtain a copy of the License at
-// 
+//
 //   http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing,
@@ -25,12 +25,12 @@ import java.util.Set;
 import javax.ejb.Local;
 import javax.inject.Inject;
 
-import org.apache.cloudstack.api.command.user.firewall.ListPortForwardingRulesCmd;
-import org.apache.cloudstack.context.CallContext;
-
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
+import org.apache.cloudstack.api.command.user.firewall.ListPortForwardingRulesCmd;
+import org.apache.cloudstack.context.CallContext;
+
 import com.cloud.configuration.ConfigurationManager;
 import com.cloud.domain.dao.DomainDao;
 import com.cloud.event.ActionEvent;
@@ -43,6 +43,7 @@ import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.NetworkRuleConflictException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.IpAddress;
+import com.cloud.network.IpAddressManager;
 import com.cloud.network.Network;
 import com.cloud.network.Network.Service;
 import com.cloud.network.NetworkManager;
@@ -97,6 +98,9 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
     private static final Logger s_logger = Logger.getLogger(RulesManagerImpl.class);
 
     @Inject
+    IpAddressManager _ipAddrMgr;
+
+    @Inject
     PortForwardingRulesDao _portForwardingDao;
     @Inject
     FirewallRulesCidrsDao _firewallCidrsDao;
@@ -212,14 +216,14 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
         boolean performedIpAssoc = false;
         Nic guestNic;
         if (ipAddress.getAssociatedWithNetworkId() == null) {
-            boolean assignToVpcNtwk =  network.getVpcId() != null 
+            boolean assignToVpcNtwk =  network.getVpcId() != null
                     && ipAddress.getVpcId() != null && ipAddress.getVpcId().longValue() == network.getVpcId();
             if (assignToVpcNtwk) {
                 _networkModel.checkIpForService(ipAddress, Service.PortForwarding, networkId);
 
                 s_logger.debug("The ip is not associated with the VPC network id="+ networkId + ", so assigning");
                 try {
-                    ipAddress = _networkMgr.associateIPToGuestNetwork(ipAddrId, networkId, false);
+                    ipAddress = _ipAddrMgr.associateIPToGuestNetwork(ipAddrId, networkId, false);
                     performedIpAssoc = true;
                 } catch (Exception ex) {
                     throw new CloudRuntimeException("Failed to associate ip to VPC network as " +
@@ -230,12 +234,12 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
             _networkModel.checkIpForService(ipAddress, Service.PortForwarding, null);
         }
 
-        if (ipAddress.getAssociatedWithNetworkId() == null) { 
+        if (ipAddress.getAssociatedWithNetworkId() == null) {
             throw new InvalidParameterValueException("Ip address " + ipAddress + " is not assigned to the network " + network);
         }
 
         try {
-            _firewallMgr.validateFirewallRule(caller, ipAddress, rule.getSourcePortStart(), rule.getSourcePortEnd(), 
+            _firewallMgr.validateFirewallRule(caller, ipAddress, rule.getSourcePortStart(), rule.getSourcePortEnd(),
                     rule.getProtocol(), Purpose.PortForwarding, FirewallRuleType.User, networkId, rule.getTrafficType());
 
             Long accountId = ipAddress.getAllocatedToAccountId();
@@ -254,7 +258,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
             // validate user VM exists
             UserVm vm = _vmDao.findById(vmId);
             if (vm == null) {
-                throw new InvalidParameterValueException("Unable to create port forwarding rule on address " + ipAddress + 
+                throw new InvalidParameterValueException("Unable to create port forwarding rule on address " + ipAddress +
                         ", invalid virtual machine id specified (" + vmId + ").");
             } else {
                 checkRuleAndUserVm(rule, vm, caller);
@@ -285,7 +289,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
 
             //if start port and end port are passed in, and they are not equal to each other, perform the validation
             boolean validatePortRange = false;
-            if (rule.getSourcePortStart().intValue() != rule.getSourcePortEnd().intValue() 
+            if (rule.getSourcePortStart().intValue() != rule.getSourcePortEnd().intValue()
                     || rule.getDestinationPortStart() != rule.getDestinationPortEnd()) {
                 validatePortRange = true;
             }
@@ -304,7 +308,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
             Transaction txn = Transaction.currentTxn();
             txn.start();
 
-            PortForwardingRuleVO newRule = new PortForwardingRuleVO(rule.getXid(), rule.getSourceIpAddressId(), 
+            PortForwardingRuleVO newRule = new PortForwardingRuleVO(rule.getXid(), rule.getSourceIpAddressId(),
                     rule.getSourcePortStart(), rule.getSourcePortEnd(), dstIp, rule.getDestinationPortStart(),
                     rule.getDestinationPortEnd(), rule.getProtocol().toLowerCase(), networkId, accountId, domainId, vmId);
             newRule = _portForwardingDao.persist(newRule);
@@ -346,7 +350,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
             if (performedIpAssoc) {
                 //if the rule is the last one for the ip address assigned to VPC, unassign it from the network
                 IpAddress ip = _ipAddressDao.findById(ipAddress.getId());
-                _vpcMgr.unassignIPFromVpcNetwork(ip.getId(), networkId);  
+                _vpcMgr.unassignIPFromVpcNetwork(ip.getId(), networkId);
             }
         }
     }
@@ -475,19 +479,19 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
             if (!isSystemVm) {
                 UserVmVO vm = _vmDao.findById(vmId);
                 if (vm == null) {
-                    throw new InvalidParameterValueException("Can't enable static nat for the address id=" + ipId + 
+                    throw new InvalidParameterValueException("Can't enable static nat for the address id=" + ipId +
                             ", invalid virtual machine id specified (" + vmId + ").");
                 }
                 //associate ip address to network (if needed)
                 if (ipAddress.getAssociatedWithNetworkId() == null) {
-                    boolean assignToVpcNtwk = network.getVpcId() != null 
+                    boolean assignToVpcNtwk = network.getVpcId() != null
                             && ipAddress.getVpcId() != null && ipAddress.getVpcId().longValue() == network.getVpcId();
                     if (assignToVpcNtwk) {
                         _networkModel.checkIpForService(ipAddress, Service.StaticNat, networkId);
 
                         s_logger.debug("The ip is not associated with the VPC network id="+ networkId + ", so assigning");
                         try {
-                            ipAddress = _networkMgr.associateIPToGuestNetwork(ipId, networkId, false);
+                            ipAddress = _ipAddrMgr.associateIPToGuestNetwork(ipId, networkId, false);
                         } catch (Exception ex) {
                             s_logger.warn("Failed to associate ip id=" + ipId + " to VPC network id=" + networkId + " as " +
                                     "a part of enable static nat");
@@ -506,7 +510,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
                             }
 
                             // associate portable IP with guest network
-                            ipAddress = _networkMgr.associatePortableIPToGuestNetwork(ipId, networkId, false);
+                            ipAddress = _ipAddrMgr.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");
@@ -519,10 +523,10 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
                         _networkModel.checkIpForService(ipAddress, Service.StaticNat, networkId);
 
                         // check if portable IP can be transferred across the networks
-                        if (_networkMgr.isPortableIpTransferableFromNetwork(ipId, ipAddress.getAssociatedWithNetworkId() )) {
+                        if (_ipAddrMgr.isPortableIpTransferableFromNetwork(ipId, ipAddress.getAssociatedWithNetworkId())) {
                             try {
                                 // transfer the portable IP and refresh IP details
-                                _networkMgr.transferPortableIP(ipId, ipAddress.getAssociatedWithNetworkId(), networkId);
+                                _ipAddrMgr.transferPortableIP(ipId, ipAddress.getAssociatedWithNetworkId(), networkId);
                                 ipAddress = _ipAddressDao.findById(ipId);
                             } catch (Exception e) {
                                 s_logger.warn("Failed to associate portable id=" + ipId + " to network id=" + networkId + " as " +
@@ -542,7 +546,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
                     _networkModel.checkIpForService(ipAddress, Service.StaticNat, null);
                 }
 
-                if (ipAddress.getAssociatedWithNetworkId() == null) { 
+                if (ipAddress.getAssociatedWithNetworkId() == null) {
                     throw new InvalidParameterValueException("Ip address " + ipAddress + " is not assigned to the network " + network);
                 }
 
@@ -972,7 +976,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
         }
 
         try {
-            if (!_networkMgr.applyStaticNats(staticNats, continueOnError, false)) {
+            if (!_ipAddrMgr.applyStaticNats(staticNats, continueOnError, false)) {
                 return false;
             }
         } catch (ResourceUnavailableException ex) {
@@ -1145,7 +1149,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
 
     @Override
     @DB
-    public FirewallRuleVO[] reservePorts(IpAddress ip, String protocol, FirewallRule.Purpose purpose, 
+    public FirewallRuleVO[] reservePorts(IpAddress ip, String protocol, FirewallRule.Purpose purpose,
             boolean openFirewall, Account caller, int... ports) throws NetworkRuleConflictException {
         FirewallRuleVO[] rules = new FirewallRuleVO[ports.length];
 
@@ -1157,7 +1161,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
             rules[i] = _firewallDao.persist(rules[i]);
 
             if (openFirewall) {
-                _firewallMgr.createRuleForAllCidrs(ip.getId(), caller, ports[i], ports[i], protocol, null, null, 
+                _firewallMgr.createRuleForAllCidrs(ip.getId(), caller, ports[i], ports[i], protocol, null, null,
                         rules[i].getId(), ip.getAssociatedWithNetworkId());
             }
         }
@@ -1197,14 +1201,14 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
 
         if (ipAddress.getSystem()) {
             InvalidParameterValueException ex = new InvalidParameterValueException("Can't disable static nat for system IP address with specified id");
-            ex.addProxyObject(ipAddress.getUuid(), "ipId");            
+            ex.addProxyObject(ipAddress.getUuid(), "ipId");
             throw ex;
         }
 
         Long vmId = ipAddress.getAssociatedWithVmId();
         if (vmId == null) {
             InvalidParameterValueException ex = new InvalidParameterValueException("Specified IP address id is not associated with any vm Id");
-            ex.addProxyObject(ipAddress.getUuid(), "ipId");            
+            ex.addProxyObject(ipAddress.getUuid(), "ipId");
             throw ex;
         }
 
@@ -1232,7 +1236,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
 
         if (!ipAddress.isOneToOneNat()) {
             InvalidParameterValueException ex = new InvalidParameterValueException("One to one nat is not enabled for the specified ip id");
-            ex.addProxyObject(ipAddress.getUuid(), "ipId");            
+            ex.addProxyObject(ipAddress.getUuid(), "ipId");
             throw ex;
         }
 
@@ -1264,7 +1268,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
             _ipAddressDao.update(ipAddress.getId(), ipAddress);
             _vpcMgr.unassignIPFromVpcNetwork(ipAddress.getId(), networkId);
 
-            if (isIpSystem && releaseIpIfElastic && !_networkMgr.handleSystemIpRelease(ipAddress)) {
+            if (isIpSystem && releaseIpIfElastic && !_ipAddrMgr.handleSystemIpRelease(ipAddress)) {
                 s_logger.warn("Failed to release system ip address " + ipAddress);
                 success = false;
             }
@@ -1315,7 +1319,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
 
         if (staticNats != null && !staticNats.isEmpty()) {
             try {
-                if (!_networkMgr.applyStaticNats(staticNats, continueOnError, forRevoke)) {
+                if (!_ipAddrMgr.applyStaticNats(staticNats, continueOnError, forRevoke)) {
                     return false;
                 }
             } catch (ResourceUnavailableException ex) {
@@ -1342,7 +1346,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
                 s_logger.debug("Found " + staticNats.size() + " static nats to disable for network id " + networkId);
             }
             try {
-                if (!_networkMgr.applyStaticNats(staticNats, continueOnError, forRevoke)) {
+                if (!_ipAddrMgr.applyStaticNats(staticNats, continueOnError, forRevoke)) {
                     return false;
                 }
             } catch (ResourceUnavailableException ex) {
@@ -1372,7 +1376,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
         Network network = _networkModel.getNetwork(networkId);
         if (network == null) {
             CloudRuntimeException ex = new CloudRuntimeException("Unable to find an ip address to map to specified vm id");
-            ex.addProxyObject(vm.getUuid(), "vmId");            
+            ex.addProxyObject(vm.getUuid(), "vmId");
             throw ex;
         }
 
@@ -1422,9 +1426,9 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
                 }
 
                 s_logger.debug("Allocating system ip and enabling static nat for it for the vm " + vm + " in guest network " + guestNetwork);
-                IpAddress ip = _networkMgr.assignSystemIp(guestNetwork.getId(), _accountMgr.getAccount(vm.getAccountId()), false, true);
+                IpAddress ip = _ipAddrMgr.assignSystemIp(guestNetwork.getId(), _accountMgr.getAccount(vm.getAccountId()), false, true);
                 if (ip == null) {
-                    throw new CloudRuntimeException("Failed to allocate system ip for vm " + vm + " in guest network " + guestNetwork);                    
+                    throw new CloudRuntimeException("Failed to allocate system ip for vm " + vm + " in guest network " + guestNetwork);
                 }
 
                 s_logger.debug("Allocated system ip " + ip + ", now enabling static nat on it for vm " + vm);
@@ -1432,18 +1436,18 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
                 try {
                     success = enableStaticNat(ip.getId(), vm.getId(), guestNetwork.getId(), isSystemVM, null);
                 } catch (NetworkRuleConflictException ex) {
-                    s_logger.warn("Failed to enable static nat as a part of enabling elasticIp and staticNat for vm " + 
+                    s_logger.warn("Failed to enable static nat as a part of enabling elasticIp and staticNat for vm " +
                             vm + " in guest network " + guestNetwork + " due to exception ", ex);
                     success = false;
                 } catch (ResourceUnavailableException ex) {
-                    s_logger.warn("Failed to enable static nat as a part of enabling elasticIp and staticNat for vm " + 
+                    s_logger.warn("Failed to enable static nat as a part of enabling elasticIp and staticNat for vm " +
                             vm + " in guest network " + guestNetwork + " due to exception ", ex);
                     success = false;
                 }
 
                 if (!success) {
                     s_logger.warn("Failed to enable static nat on system ip " + ip + " for the vm " + vm + ", releasing the ip...");
-                    _networkMgr.handleSystemIpRelease(ip);
+                    _ipAddrMgr.handleSystemIpRelease(ip);
                     throw new CloudRuntimeException("Failed to enable static nat on system ip for the vm " + vm);
                 } else {
                     s_logger.warn("Succesfully enabled static nat on system ip " + ip + " for the vm " + vm);
@@ -1474,7 +1478,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
                 VMInstanceVO vm = _vmInstanceDao.findById(nic.getInstanceId());
                 // generate a static Nat rule on the fly because staticNATrule does not persist into db anymore
                 // FIX ME
-                FirewallRuleVO staticNatRule = new FirewallRuleVO(null, ip.getId(), 0, 65535, NetUtils.ALL_PROTO.toString(), 
+                FirewallRuleVO staticNatRule = new FirewallRuleVO(null, ip.getId(), 0, 65535, NetUtils.ALL_PROTO.toString(),
                         nic.getNetworkId(), vm.getAccountId(), vm.getDomainId(), Purpose.StaticNat, null, null, null, null, null);
                 result.add(staticNatRule);
             }


Mime
View raw message