|
45 | 45 | import com.cloud.host.dao.HostDao; |
46 | 46 | import com.cloud.hypervisor.Hypervisor; |
47 | 47 | import com.cloud.hypervisor.Hypervisor.HypervisorType; |
| 48 | +import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao; |
48 | 49 | import com.cloud.hypervisor.vmware.manager.VmwareManager; |
49 | 50 | import com.cloud.hypervisor.vmware.mo.ClusterMO; |
50 | 51 | import com.cloud.hypervisor.vmware.mo.HostMO; |
@@ -95,78 +96,69 @@ public class VmwareServerDiscoverer extends DiscovererBase implements |
95 | 96 | CiscoNexusVSMDeviceDao _nexusDao; |
96 | 97 | @Inject |
97 | 98 | NetworkModel _netmgr; |
98 | | - |
| 99 | + @Inject |
| 100 | + HypervisorCapabilitiesDao _hvCapabilitiesDao; |
| 101 | + |
99 | 102 | public VmwareServerDiscoverer() { |
100 | 103 | s_logger.info("VmwareServerDiscoverer is constructed"); |
101 | 104 | } |
102 | | - |
103 | | - @Override |
104 | | - public Map<? extends ServerResource, Map<String, String>> find(long dcId, |
105 | | - Long podId, Long clusterId, URI url, String username, |
106 | | - String password, List<String> hostTags) throws DiscoveryException { |
107 | | - |
108 | | - if (s_logger.isInfoEnabled()) |
109 | | - s_logger.info("Discover host. dc: " + dcId + ", pod: " + podId |
110 | | - + ", cluster: " + clusterId + ", uri host: " |
111 | | - + url.getHost()); |
112 | | - |
113 | | - if (podId == null) { |
114 | | - if (s_logger.isInfoEnabled()) |
115 | | - s_logger.info("No pod is assigned, assuming that it is not for vmware and skip it to next discoverer"); |
116 | | - return null; |
117 | | - } |
118 | | - |
119 | | - ClusterVO cluster = _clusterDao.findById(clusterId); |
120 | | - if (cluster == null |
121 | | - || cluster.getHypervisorType() != HypervisorType.VMware) { |
122 | | - if (s_logger.isInfoEnabled()) |
123 | | - s_logger.info("invalid cluster id or cluster is not for VMware hypervisors"); |
124 | | - return null; |
125 | | - } |
126 | 105 |
|
127 | | - List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId); |
128 | | - if (hosts.size() >= _vmwareMgr.getMaxHostsPerCluster()) { |
129 | | - String msg = "VMware cluster " |
130 | | - + cluster.getName() |
131 | | - + " is too big to add new host now. (current configured cluster size: " |
132 | | - + _vmwareMgr.getMaxHostsPerCluster() + ")"; |
133 | | - s_logger.error(msg); |
134 | | - throw new DiscoveredWithErrorException(msg); |
135 | | - } |
136 | | - |
137 | | - String privateTrafficLabel = null; |
138 | | - String publicTrafficLabel = null; |
139 | | - String guestTrafficLabel = null; |
140 | | - Map<String, String> vsmCredentials = null; |
141 | | - |
142 | | - privateTrafficLabel = _netmgr.getDefaultManagementTrafficLabel(dcId, |
143 | | - HypervisorType.VMware); |
144 | | - if (privateTrafficLabel != null) { |
145 | | - s_logger.info("Detected private network label : " |
146 | | - + privateTrafficLabel); |
147 | | - } |
148 | | - |
149 | | - if (_vmwareMgr.getNexusVSwitchGlobalParameter()) { |
150 | | - DataCenterVO zone = _dcDao.findById(dcId); |
151 | | - NetworkType zoneType = zone.getNetworkType(); |
152 | | - if (zoneType != NetworkType.Basic) { |
153 | | - publicTrafficLabel = _netmgr.getDefaultPublicTrafficLabel(dcId, |
154 | | - HypervisorType.VMware); |
155 | | - if (publicTrafficLabel != null) { |
156 | | - s_logger.info("Detected public network label : " |
157 | | - + publicTrafficLabel); |
158 | | - } |
159 | | - } |
160 | | - // Get physical network label |
161 | | - guestTrafficLabel = _netmgr.getDefaultGuestTrafficLabel(dcId, |
162 | | - HypervisorType.VMware); |
163 | | - if (guestTrafficLabel != null) { |
164 | | - s_logger.info("Detected guest network label : " |
165 | | - + guestTrafficLabel); |
166 | | - } |
167 | | - vsmCredentials = _vmwareMgr |
168 | | - .getNexusVSMCredentialsByClusterId(clusterId); |
169 | | - } |
| 106 | + @Override |
| 107 | + public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url, |
| 108 | + String username, String password, List<String> hostTags) throws DiscoveryException { |
| 109 | + |
| 110 | + if(s_logger.isInfoEnabled()) |
| 111 | + s_logger.info("Discover host. dc: " + dcId + ", pod: " + podId + ", cluster: " + clusterId + ", uri host: " + url.getHost()); |
| 112 | + |
| 113 | + if(podId == null) { |
| 114 | + if(s_logger.isInfoEnabled()) |
| 115 | + s_logger.info("No pod is assigned, assuming that it is not for vmware and skip it to next discoverer"); |
| 116 | + return null; |
| 117 | + } |
| 118 | + |
| 119 | + ClusterVO cluster = _clusterDao.findById(clusterId); |
| 120 | + if(cluster == null || cluster.getHypervisorType() != HypervisorType.VMware) { |
| 121 | + if(s_logger.isInfoEnabled()) |
| 122 | + s_logger.info("invalid cluster id or cluster is not for VMware hypervisors"); |
| 123 | + return null; |
| 124 | + } |
| 125 | + |
| 126 | + List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId); |
| 127 | + if (hosts != null && hosts.size() > 0) { |
| 128 | + int maxHostsPerCluster = _hvCapabilitiesDao.getMaxHostsPerCluster(hosts.get(0).getHypervisorType(), hosts.get(0).getHypervisorVersion()); |
| 129 | + if (hosts.size() > maxHostsPerCluster) { |
| 130 | + String msg = "VMware cluster " + cluster.getName() + " is too big to add new host now. (current configured cluster size: " + maxHostsPerCluster + ")"; |
| 131 | + s_logger.error(msg); |
| 132 | + throw new DiscoveredWithErrorException(msg); |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + String privateTrafficLabel = null; |
| 137 | + String publicTrafficLabel = null; |
| 138 | + String guestTrafficLabel = null; |
| 139 | + Map<String, String> vsmCredentials = null; |
| 140 | + |
| 141 | + privateTrafficLabel = _netmgr.getDefaultManagementTrafficLabel(dcId, HypervisorType.VMware); |
| 142 | + if (privateTrafficLabel != null) { |
| 143 | + s_logger.info("Detected private network label : " + privateTrafficLabel); |
| 144 | + } |
| 145 | + |
| 146 | + if (_vmwareMgr.getNexusVSwitchGlobalParameter()) { |
| 147 | + DataCenterVO zone = _dcDao.findById(dcId); |
| 148 | + NetworkType zoneType = zone.getNetworkType(); |
| 149 | + if (zoneType != NetworkType.Basic) { |
| 150 | + publicTrafficLabel = _netmgr.getDefaultPublicTrafficLabel(dcId, HypervisorType.VMware); |
| 151 | + if (publicTrafficLabel != null) { |
| 152 | + s_logger.info("Detected public network label : " + publicTrafficLabel); |
| 153 | + } |
| 154 | + } |
| 155 | + // Get physical network label |
| 156 | + guestTrafficLabel = _netmgr.getDefaultGuestTrafficLabel(dcId, HypervisorType.VMware); |
| 157 | + if (guestTrafficLabel != null) { |
| 158 | + s_logger.info("Detected guest network label : " + guestTrafficLabel); |
| 159 | + } |
| 160 | + vsmCredentials = _vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId); |
| 161 | + } |
170 | 162 |
|
171 | 163 | VmwareContext context = null; |
172 | 164 | try { |
|
0 commit comments