stephankruggg commented on code in PR #7213:
URL: https://github.com/apache/cloudstack/pull/7213#discussion_r1124806898
##########
server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java:
##########
@@ -588,34 +580,31 @@ private void
checkUnmanagedNicAndNetworkForImport(UnmanagedInstanceTO.Nic nic, N
}
String pvLanType = nic.getPvlanType() == null ? "" :
nic.getPvlanType().toLowerCase().substring(0, 1);
if (nic.getVlan() != null && nic.getVlan() != 0 && nic.getPvlan() !=
null && nic.getPvlan() != 0 &&
- (StringUtils.isEmpty(network.getBroadcastUri().toString()) ||
-
!networkBroadcastUri.equals(String.format("pvlan://%d-%s%d", nic.getVlan(),
pvLanType, nic.getPvlan())))) {
+ (StringUtils.isEmpty(networkBroadcastUri) ||
!String.format("pvlan://%d-%s%d", nic.getVlan(), pvLanType,
nic.getPvlan()).equals(networkBroadcastUri))) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
String.format("PVLAN of network(ID: %s) %s is found different from the VLAN of
nic(ID: %s) pvlan://%d-%s%d during VM import", network.getUuid(),
networkBroadcastUri, nic.getNicId(), nic.getVlan(), pvLanType, nic.getPvlan()));
}
}
- private void
checkUnmanagedNicAndNetworkHostnameForImport(UnmanagedInstanceTO.Nic nic,
Network network, final String hostName) throws ServerApiException {
+ private void basicNetworkChecks(String instanceName,
UnmanagedInstanceTO.Nic nic, Network network) {
if (nic == null) {
- throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
String.format("Unable to retrieve NIC details during VM import"));
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
String.format("Unable to retrieve, from VMware, the NIC details used by VM
[%s]. Please check if this VM have NICs in VMWare.", instanceName));
}
if (network == null) {
- throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
String.format("Network for nic ID: %s not found during VM import",
nic.getNicId()));
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
String.format("Network for nic ID: %s not found during VM import.",
nic.getNicId()));
}
+ }
+
+ private void checkUnmanagedNicAndNetworkHostnameForImport(String
instanceName, UnmanagedInstanceTO.Nic nic, Network network, final String
hostName) throws ServerApiException {
+ basicNetworkChecks(instanceName, nic, network);
// Check for duplicate hostname in network, get all vms hostNames in
the network
List<String> hostNames = vmDao.listDistinctHostNames(network.getId());
if (CollectionUtils.isNotEmpty(hostNames) &&
hostNames.contains(hostName)) {
- throw new InvalidParameterValueException("The vm with hostName " +
hostName + " already exists in the network domain: " +
network.getNetworkDomain() + "; network="
- + network);
+ throw new InvalidParameterValueException(String.format("VM with
Name [%s] already exists in the network [%s] domain [%s]. Cannot import another
VM with the same name again. Pleasy try again with a different name.",
hostName, network, network.getNetworkDomain()));
Review Comment:
```suggestion
throw new InvalidParameterValueException(String.format("VM with
Name [%s] already exists in the network [%s] domain [%s]. Cannot import another
VM with the same name. Pleasy try again with a different name.", hostName,
network, network.getNetworkDomain()));
```
##########
server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java:
##########
@@ -588,34 +580,31 @@ private void
checkUnmanagedNicAndNetworkForImport(UnmanagedInstanceTO.Nic nic, N
}
String pvLanType = nic.getPvlanType() == null ? "" :
nic.getPvlanType().toLowerCase().substring(0, 1);
if (nic.getVlan() != null && nic.getVlan() != 0 && nic.getPvlan() !=
null && nic.getPvlan() != 0 &&
- (StringUtils.isEmpty(network.getBroadcastUri().toString()) ||
-
!networkBroadcastUri.equals(String.format("pvlan://%d-%s%d", nic.getVlan(),
pvLanType, nic.getPvlan())))) {
+ (StringUtils.isEmpty(networkBroadcastUri) ||
!String.format("pvlan://%d-%s%d", nic.getVlan(), pvLanType,
nic.getPvlan()).equals(networkBroadcastUri))) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
String.format("PVLAN of network(ID: %s) %s is found different from the VLAN of
nic(ID: %s) pvlan://%d-%s%d during VM import", network.getUuid(),
networkBroadcastUri, nic.getNicId(), nic.getVlan(), pvLanType, nic.getPvlan()));
}
}
- private void
checkUnmanagedNicAndNetworkHostnameForImport(UnmanagedInstanceTO.Nic nic,
Network network, final String hostName) throws ServerApiException {
+ private void basicNetworkChecks(String instanceName,
UnmanagedInstanceTO.Nic nic, Network network) {
if (nic == null) {
- throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
String.format("Unable to retrieve NIC details during VM import"));
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
String.format("Unable to retrieve, from VMware, the NIC details used by VM
[%s]. Please check if this VM have NICs in VMWare.", instanceName));
Review Comment:
```suggestion
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
String.format("Unable to retrieve the NIC details used by VM [%s] from VMware.
Please check if this VM have NICs in VMWare.", instanceName));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]