Skip to content

Commit 0c057af

Browse files
committed
splitting out root disk size issue
1 parent c72482d commit 0c057af

2 files changed

Lines changed: 5 additions & 34 deletions

File tree

server/src/main/java/com/cloud/network/NetworkModelImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,9 +2017,6 @@ public boolean isNetworkAvailableInDomain(long networkId, long domainId) {
20172017
@Override
20182018
public Set<Long> getAvailableIps(Network network, String requestedIp) {
20192019
if (network.getCidr() == null) {
2020-
if (s_logger.isDebugEnabled()) {
2021-
s_logger.debug(String.format("network %s[%s] has no CIDR, returning empty addrress set.", network.getName(), network.getUuid()));
2022-
}
20232020
return Collections.emptySet();
20242021
}
20252022
String[] cidr = network.getCidr().split("/");
@@ -2029,7 +2026,7 @@ public Set<Long> getAvailableIps(Network network, String requestedIp) {
20292026
for (String ip : ips) {
20302027
if (requestedIp != null && requestedIp.equals(ip)) {
20312028
s_logger.warn("Requested ip address " + requestedIp + " is already in use in network" + network);
2032-
return Collections.emptySet();
2029+
return null;
20332030
}
20342031

20352032
usedIps.add(NetUtils.ip2Long(ip));

server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@
174174
import org.apache.log4j.Logger;
175175

176176
import javax.inject.Inject;
177-
import java.net.InetAddress;
178-
import java.net.UnknownHostException;
179177
import java.util.ArrayList;
180178
import java.util.Arrays;
181179
import java.util.HashMap;
@@ -697,30 +695,9 @@ private void checkUnmanagedNicIpAndNetworkForImport(String instanceName, Unmanag
697695
}
698696
// If network is non L2, IP v4 is assigned and not set to auto-assign, check it is available for network
699697
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()));
724701
}
725702
}
726703
}
@@ -1136,10 +1113,7 @@ private UserVm importVirtualMachineInternal(final UnmanagedInstanceTO unmanagedI
11361113
}
11371114
allDetails.put(VmDetailConstants.ROOT_DISK_CONTROLLER, rootDisk.getController());
11381115
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);
11431117
allDetails.put(VmDetailConstants.ROOT_DISK_SIZE, String.valueOf(size));
11441118
}
11451119

0 commit comments

Comments
 (0)