Skip to content

Commit 04b9cd7

Browse files
committed
added template filter check
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 7775c88 commit 04b9cd7

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

server/src/main/java/org/apache/cloudstack/ingestion/VmIngestionManagerImpl.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,12 @@
7373
import com.cloud.server.ManagementService;
7474
import com.cloud.service.dao.ServiceOfferingDao;
7575
import com.cloud.storage.StoragePool;
76+
import com.cloud.storage.VMTemplateStoragePoolVO;
77+
import com.cloud.storage.VMTemplateVO;
7678
import com.cloud.storage.Volume;
7779
import com.cloud.storage.dao.DiskOfferingDao;
7880
import com.cloud.storage.dao.VMTemplateDao;
81+
import com.cloud.storage.dao.VMTemplatePoolDao;
7982
import com.cloud.template.VirtualMachineTemplate;
8083
import com.cloud.user.Account;
8184
import com.cloud.user.AccountService;
@@ -108,6 +111,8 @@ public class VmIngestionManagerImpl implements VmIngestionService {
108111
@Inject
109112
private VMTemplateDao templateDao;
110113
@Inject
114+
private VMTemplatePoolDao templatePoolDao;
115+
@Inject
111116
private ServiceOfferingDao serviceOfferingDao;
112117
@Inject
113118
private DiskOfferingDao diskOfferingDao;
@@ -152,9 +157,27 @@ public ListResponse<UnmanagedInstanceResponse> listUnmanagedInstances(ListUnmana
152157

153158
List<HostVO> hosts = resourceManager.listHostsInClusterByStatus(clusterId, Status.Up);
154159

160+
List<VMTemplateVO> templates = new ArrayList<>();
161+
162+
if (cluster.getHypervisorType() == Hypervisor.HypervisorType.VMware) { // Add filter for templates for VMware
163+
try {
164+
templates.addAll(templateDao.listAll());
165+
} catch (Exception e) {
166+
LOGGER.warn(String.format("Unable to retrieve vm templates for cluster's zone ID: %s", cluster.getDataCenterId()));
167+
}
168+
}
169+
155170
List<UnmanagedInstanceResponse> responses = new ArrayList<>();
156171
for (HostVO host : hosts) {
157172
List<String> managedVms = new ArrayList<>();
173+
if (cluster.getHypervisorType() == Hypervisor.HypervisorType.VMware) { // Add filter for templates for VMware
174+
for (VMTemplateVO template : templates) {
175+
VMTemplateStoragePoolVO templateStoragePoolVO = templatePoolDao.findByPoolTemplate(host.getId(), template.getId());
176+
if (templateStoragePoolVO != null) {
177+
managedVms.add(templateStoragePoolVO.getInstallPath());
178+
}
179+
}
180+
}
158181
try {
159182
ListVMsCmdByAdmin vmsCmd = new ListVMsCmdByAdmin();
160183
vmsCmd = ComponentContext.inject(vmsCmd);
@@ -200,6 +223,7 @@ public ListResponse<UnmanagedInstanceResponse> listUnmanagedInstances(ListUnmana
200223
} catch (Exception e) {
201224
LOGGER.warn(String.format("Unable to retrieve virtual router vms for host ID: %s", host.getUuid()));
202225
}
226+
203227
GetUnmanagedInstancesCommand command = new GetUnmanagedInstancesCommand();
204228
command.setManagedInstancesNames(managedVms);
205229
Answer answer = agentManager.easySend(host.getId(), command);

0 commit comments

Comments
 (0)