|
19 | 19 | import static com.cloud.configuration.ConfigurationManagerImpl.MIGRATE_VM_ACROSS_CLUSTERS; |
20 | 20 | import static com.cloud.configuration.ConfigurationManagerImpl.SET_HOST_DOWN_TO_MAINTENANCE; |
21 | 21 |
|
| 22 | +import java.net.InetAddress; |
22 | 23 | import java.net.URI; |
23 | 24 | import java.net.URISyntaxException; |
24 | 25 | import java.net.URLDecoder; |
| 26 | +import java.net.UnknownHostException; |
25 | 27 | import java.util.ArrayList; |
26 | 28 | import java.util.Arrays; |
27 | 29 | import java.util.Collections; |
@@ -2613,19 +2615,22 @@ private Host createHostAndAgent(final ServerResource resource, final Map<String, |
2613 | 2615 |
|
2614 | 2616 | void checkForDuplicateHost(final String url) { |
2615 | 2617 | String hostIpOrName = null; |
| 2618 | + String ipAddress = null; |
2616 | 2619 | try { |
2617 | 2620 | hostIpOrName = new URI(UriUtils.encodeURIComponent(url)).getHost(); |
2618 | | - } catch (final URISyntaxException ignore) { |
2619 | | - // unparseable URL - discoverer will reject it shortly anyway |
| 2621 | + InetAddress ip = InetAddress.getByName(hostIpOrName); |
| 2622 | + ipAddress = ip.getHostAddress(); |
| 2623 | + } catch (final URISyntaxException | UnknownHostException ignore) { |
| 2624 | + // unparseable URL or unknown host - discoverer will reject it shortly anyway |
2620 | 2625 | } |
2621 | 2626 | if (StringUtils.isBlank(hostIpOrName)) { |
2622 | 2627 | return; |
2623 | 2628 | } |
2624 | | - final HostVO existingByIp = _hostDao.findByIp(hostIpOrName); |
| 2629 | + final HostVO existingByIp = _hostDao.findByIp(ipAddress); |
2625 | 2630 | if (existingByIp != null) { |
2626 | 2631 | throw new InvalidParameterValueException(String.format( |
2627 | | - "A host with IP address / hostname '%s' already exists (id: %s). Remove it before adding again.", |
2628 | | - hostIpOrName, existingByIp.getUuid())); |
| 2632 | + "A host with IP address / hostname '%s' (%s) already exists (id: %s). Remove it before adding again.", |
| 2633 | + hostIpOrName, ipAddress, existingByIp.getUuid())); |
2629 | 2634 | } |
2630 | 2635 | } |
2631 | 2636 |
|
|
0 commit comments