3939import com .cloud .api .ApiDBUtils ;
4040import com .cloud .capacity .Capacity ;
4141import com .cloud .capacity .CapacityManager ;
42+ import com .cloud .capacity .CapacityState ;
4243import com .cloud .capacity .CapacityVO ;
4344import com .cloud .capacity .dao .CapacityDao ;
4445import com .cloud .capacity .dao .CapacityDaoImpl .SummedCapacity ;
4546import com .cloud .configuration .Config ;
47+ import com .cloud .configuration .ConfigurationManager ;
4648import com .cloud .configuration .dao .ConfigurationDao ;
4749import com .cloud .dc .ClusterVO ;
4850import com .cloud .dc .DataCenter .NetworkType ;
5759import com .cloud .host .HostVO ;
5860import com .cloud .host .dao .HostDao ;
5961import com .cloud .network .dao .IPAddressDao ;
62+ import com .cloud .org .Grouping .AllocationState ;
6063import com .cloud .resource .ResourceManager ;
6164import com .cloud .storage .StorageManager ;
6265import com .cloud .storage .StoragePoolVO ;
@@ -97,6 +100,7 @@ public class AlertManagerImpl implements AlertManager {
97100 @ Inject private StoragePoolDao _storagePoolDao ;
98101 @ Inject private ConfigurationDao _configDao ;
99102 @ Inject private ResourceManager _resourceMgr ;
103+ @ Inject private ConfigurationManager _configMgr ;
100104
101105 private Timer _timer = null ;
102106 private float _cpuOverProvisioningFactor = 1 ;
@@ -319,15 +323,15 @@ public void recalculateCapacity() {
319323
320324 // Calculate new Public IP capacity for Virtual Network
321325 if (datacenter .getNetworkType () == NetworkType .Advanced ){
322- createOrUpdateIpCapacity (dcId , null , CapacityVO .CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP );
326+ createOrUpdateIpCapacity (dcId , null , CapacityVO .CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP , datacenter . getAllocationState () );
323327 }
324328
325329 // Calculate new Public IP capacity for Direct Attached Network
326- createOrUpdateIpCapacity (dcId , null , CapacityVO .CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP );
330+ createOrUpdateIpCapacity (dcId , null , CapacityVO .CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP , datacenter . getAllocationState () );
327331
328332 if (datacenter .getNetworkType () == NetworkType .Advanced ){
329333 //Calculate VLAN's capacity
330- createOrUpdateVlanCapacity (dcId );
334+ createOrUpdateVlanCapacity (dcId , datacenter . getAllocationState () );
331335 }
332336 }
333337
@@ -342,7 +346,7 @@ public void recalculateCapacity() {
342346 long podId = pod .getId ();
343347 long dcId = pod .getDataCenterId ();
344348
345- createOrUpdateIpCapacity (dcId , podId , CapacityVO .CAPACITY_TYPE_PRIVATE_IP );
349+ createOrUpdateIpCapacity (dcId , podId , CapacityVO .CAPACITY_TYPE_PRIVATE_IP , _configMgr . findPodAllocationState ( pod ) );
346350 }
347351
348352 if (s_logger .isDebugEnabled ()) {
@@ -355,7 +359,9 @@ public void recalculateCapacity() {
355359 }
356360 }
357361
358- private void createOrUpdateVlanCapacity (long dcId ) {
362+
363+
364+ private void createOrUpdateVlanCapacity (long dcId , AllocationState capacityState ) {
359365
360366 SearchCriteria <CapacityVO > capacitySC = _capacityDao .createSearchCriteria ();
361367
@@ -369,8 +375,11 @@ private void createOrUpdateVlanCapacity(long dcId) {
369375 int allocatedVlans = _dcDao .countZoneVlans (dcId , true );
370376
371377 if (capacities .size () == 0 ){
372- CapacityVO newPublicIPCapacity = new CapacityVO (null , dcId , null , null , allocatedVlans , totalVlans , Capacity .CAPACITY_TYPE_VLAN );
373- _capacityDao .persist (newPublicIPCapacity );
378+ CapacityVO newVlanCapacity = new CapacityVO (null , dcId , null , null , allocatedVlans , totalVlans , Capacity .CAPACITY_TYPE_VLAN );
379+ if (capacityState == AllocationState .Disabled ){
380+ newVlanCapacity .setCapacityState (CapacityState .Disabled );
381+ }
382+ _capacityDao .persist (newVlanCapacity );
374383 }else if ( !(capacities .get (0 ).getUsedCapacity () == allocatedVlans
375384 && capacities .get (0 ).getTotalCapacity () == totalVlans ) ){
376385 CapacityVO capacity = capacities .get (0 );
@@ -382,7 +391,7 @@ private void createOrUpdateVlanCapacity(long dcId) {
382391
383392 }
384393
385- public void createOrUpdateIpCapacity (Long dcId , Long podId , short capacityType ){
394+ public void createOrUpdateIpCapacity (Long dcId , Long podId , short capacityType , AllocationState capacityState ){
386395 SearchCriteria <CapacityVO > capacitySC = _capacityDao .createSearchCriteria ();
387396
388397 List <CapacityVO > capacities = _capacityDao .search (capacitySC , null );
@@ -407,6 +416,9 @@ public void createOrUpdateIpCapacity(Long dcId, Long podId, short capacityType){
407416
408417 if (capacities .size () == 0 ){
409418 CapacityVO newPublicIPCapacity = new CapacityVO (null , dcId , podId , null , allocatedIPs , totalIPs , capacityType );
419+ if (capacityState == AllocationState .Disabled ){
420+ newPublicIPCapacity .setCapacityState (CapacityState .Disabled );
421+ }
410422 _capacityDao .persist (newPublicIPCapacity );
411423 }else if ( !(capacities .get (0 ).getUsedCapacity () == allocatedIPs
412424 && capacities .get (0 ).getTotalCapacity () == totalIPs ) ){
0 commit comments