3636import com .cloud .dc .dao .DataCenterDao ;
3737import com .cloud .dc .dao .HostPodDao ;
3838import com .cloud .exception .InsufficientServerCapacityException ;
39+ import com .cloud .host .Host ;
3940import com .cloud .host .HostVO ;
4041import com .cloud .host .Status ;
4142import com .cloud .host .dao .HostDao ;
@@ -87,18 +88,17 @@ public DeployDestination plan(VirtualMachineProfile<? extends VirtualMachine> vm
8788 }
8889 }
8990
90- List <ClusterVO > clusters = _clusterDao .listByDcHyType (vm .getDataCenterIdToDeployIn (), HypervisorType .BareMetal .toString ());
91+ List <ClusterVO > clusters = _clusterDao .listByDcHyType (vm .getDataCenterIdToDeployIn (), HypervisorType .BareMetal .toString ());
9192 int cpu_requested ;
9293 long ram_requested ;
9394 HostVO target = null ;
94- List <HostVO > hosts ;
95+ List <HostVO > hosts ;
9596 for (ClusterVO cluster : clusters ) {
96- hosts = _resourceMgr .listAllHostsInCluster ( cluster .getId ());
97+ hosts = _resourceMgr .listAllUpAndEnabledHosts ( Host . Type . Routing , cluster .getId (), cluster . getPodId (), cluster . getDataCenterId ());
9798 if (hostTag != null ) {
9899 for (HostVO h : hosts ) {
99100 _hostDao .loadDetails (h );
100- if (h .getDetail ("hostTag" ) != null
101- && h .getDetail ("hostTag" ).equalsIgnoreCase (hostTag )) {
101+ if (h .getDetail ("hostTag" ) != null && h .getDetail ("hostTag" ).equalsIgnoreCase (hostTag )) {
102102 target = h ;
103103 break ;
104104 }
@@ -115,17 +115,18 @@ public DeployDestination plan(VirtualMachineProfile<? extends VirtualMachine> vm
115115 ram_requested = target .getTotalMemory ();
116116 }
117117
118- for (HostVO h : hosts ) {
119- if (h .getStatus () == Status .Up ) {
120- if (_capacityMgr .checkIfHostHasCapacity (h .getId (), cpu_requested , ram_requested , false , cpuOverprovisioningFactor , true )){
118+ for (ClusterVO cluster : clusters ) {
119+ hosts = _resourceMgr .listAllUpAndEnabledHosts (Host .Type .Routing , cluster .getId (), cluster .getPodId (), cluster .getDataCenterId ());
120+ for (HostVO h : hosts ) {
121+ if (_capacityMgr .checkIfHostHasCapacity (h .getId (), cpu_requested , ram_requested , false , cpuOverprovisioningFactor , true )) {
121122 s_logger .debug ("Find host " + h .getId () + " has enough capacity" );
122123 DataCenter dc = _dcDao .findById (h .getDataCenterId ());
123124 Pod pod = _podDao .findById (h .getPodId ());
124125 return new DeployDestination (dc , pod , cluster , h );
125126 }
126127 }
127128 }
128-
129+
129130 s_logger .warn (String .format ("Cannot find enough capacity(requested cpu=%1$s memory=%2$s)" , cpu_requested , ram_requested ));
130131 return null ;
131132 }
0 commit comments