|
73 | 73 | import com.cloud.server.ManagementService; |
74 | 74 | import com.cloud.service.dao.ServiceOfferingDao; |
75 | 75 | import com.cloud.storage.StoragePool; |
| 76 | +import com.cloud.storage.VMTemplateStoragePoolVO; |
| 77 | +import com.cloud.storage.VMTemplateVO; |
76 | 78 | import com.cloud.storage.Volume; |
77 | 79 | import com.cloud.storage.dao.DiskOfferingDao; |
78 | 80 | import com.cloud.storage.dao.VMTemplateDao; |
| 81 | +import com.cloud.storage.dao.VMTemplatePoolDao; |
79 | 82 | import com.cloud.template.VirtualMachineTemplate; |
80 | 83 | import com.cloud.user.Account; |
81 | 84 | import com.cloud.user.AccountService; |
@@ -108,6 +111,8 @@ public class VmIngestionManagerImpl implements VmIngestionService { |
108 | 111 | @Inject |
109 | 112 | private VMTemplateDao templateDao; |
110 | 113 | @Inject |
| 114 | + private VMTemplatePoolDao templatePoolDao; |
| 115 | + @Inject |
111 | 116 | private ServiceOfferingDao serviceOfferingDao; |
112 | 117 | @Inject |
113 | 118 | private DiskOfferingDao diskOfferingDao; |
@@ -152,9 +157,27 @@ public ListResponse<UnmanagedInstanceResponse> listUnmanagedInstances(ListUnmana |
152 | 157 |
|
153 | 158 | List<HostVO> hosts = resourceManager.listHostsInClusterByStatus(clusterId, Status.Up); |
154 | 159 |
|
| 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 | + |
155 | 170 | List<UnmanagedInstanceResponse> responses = new ArrayList<>(); |
156 | 171 | for (HostVO host : hosts) { |
157 | 172 | 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 | + } |
158 | 181 | try { |
159 | 182 | ListVMsCmdByAdmin vmsCmd = new ListVMsCmdByAdmin(); |
160 | 183 | vmsCmd = ComponentContext.inject(vmsCmd); |
@@ -200,6 +223,7 @@ public ListResponse<UnmanagedInstanceResponse> listUnmanagedInstances(ListUnmana |
200 | 223 | } catch (Exception e) { |
201 | 224 | LOGGER.warn(String.format("Unable to retrieve virtual router vms for host ID: %s", host.getUuid())); |
202 | 225 | } |
| 226 | + |
203 | 227 | GetUnmanagedInstancesCommand command = new GetUnmanagedInstancesCommand(); |
204 | 228 | command.setManagedInstancesNames(managedVms); |
205 | 229 | Answer answer = agentManager.easySend(host.getId(), command); |
|
0 commit comments