|
174 | 174 | import org.apache.log4j.Logger; |
175 | 175 |
|
176 | 176 | import javax.inject.Inject; |
177 | | -import java.net.InetAddress; |
178 | | -import java.net.UnknownHostException; |
179 | 177 | import java.util.ArrayList; |
180 | 178 | import java.util.Arrays; |
181 | 179 | import java.util.HashMap; |
@@ -697,30 +695,9 @@ private void checkUnmanagedNicIpAndNetworkForImport(String instanceName, Unmanag |
697 | 695 | } |
698 | 696 | // If network is non L2, IP v4 is assigned and not set to auto-assign, check it is available for network |
699 | 697 | if (!network.getGuestType().equals(Network.GuestType.L2) && ipAddresses != null && StringUtils.isNotEmpty(ipAddresses.getIp4Address()) && !ipAddresses.getIp4Address().equals("auto")) { |
700 | | - canIpBeUsedForNicInNetwork(nic, network, ipAddresses); |
701 | | - } |
702 | | - } |
703 | | - |
704 | | - private void canIpBeUsedForNicInNetwork(UnmanagedInstanceTO.Nic nic, Network network, Network.IpAddresses ipAddresses) { |
705 | | - List<String> usedIps = networkModel.getUsedIpsInNetwork(network); |
706 | | - if (LOGGER.isDebugEnabled() && usedIps != null) { |
707 | | - String s = usedIps.stream().collect(Collectors.joining(", ")); |
708 | | - LOGGER.debug(String.format("used IPs for network(ID: %s) to check against are [%s]", network.getUuid(), s)); |
709 | | - } |
710 | | - for (String usedIp : usedIps) { |
711 | | - // only half witted support for ipv6 here :( |
712 | | - if (usedIp.equals(ipAddresses.getIp4Address()) || usedIp.equals(ipAddresses.getIp6Address())) { |
713 | | - throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, String.format("Cannot assign IP address %s to NIC(ID: %s) as it is in use in network(ID: %s)", ipAddresses.getIp4Address(), nic.getNicId(), network.getUuid())); |
714 | | - } |
715 | | - } |
716 | | - if (network.getCidr() != null) { |
717 | | - String[] cidrs = Arrays.asList(network.getCidr()).toArray(new String[0]); |
718 | | - try { |
719 | | - NetUtils.isIpInCidrList(InetAddress.getByName(ipAddresses.getIp4Address()), cidrs); |
720 | | - } catch (UnknownHostException e) { |
721 | | - String msg = String.format("request an invalid IP address during import %s, ignoring", ipAddresses.getIp4Address()); |
722 | | - LOGGER.warn(msg); |
723 | | - throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, msg, e); |
| 698 | + Set<Long> ips = networkModel.getAvailableIps(network, ipAddresses.getIp4Address()); |
| 699 | + if (CollectionUtils.isEmpty(ips) || !ips.contains(NetUtils.ip2Long(ipAddresses.getIp4Address()))) { |
| 700 | + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("IP address %s for NIC(ID: %s) is not available in network(ID: %s)", ipAddresses.getIp4Address(), nic.getNicId(), network.getUuid())); |
724 | 701 | } |
725 | 702 | } |
726 | 703 | } |
@@ -1136,10 +1113,7 @@ private UserVm importVirtualMachineInternal(final UnmanagedInstanceTO unmanagedI |
1136 | 1113 | } |
1137 | 1114 | allDetails.put(VmDetailConstants.ROOT_DISK_CONTROLLER, rootDisk.getController()); |
1138 | 1115 | if (cluster.getHypervisorType() != Hypervisor.HypervisorType.VMware) { |
1139 | | - long size = rootDisk.getCapacity() / Resource.ResourceType.bytesToGiB; |
1140 | | - if (size <= 0) { |
1141 | | - size = 1; |
1142 | | - } |
| 1116 | + long size = (long) Math.ceil((double)rootDisk.getCapacity() / Resource.ResourceType.bytesToGiB); |
1143 | 1117 | allDetails.put(VmDetailConstants.ROOT_DISK_SIZE, String.valueOf(size)); |
1144 | 1118 | } |
1145 | 1119 |
|
|
0 commit comments