Skip to content

Commit 1004ddb

Browse files
committed
unify three similar reasons to thow an exception in a method
1 parent bef6589 commit 1004ddb

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

‎server/src/main/java/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4048,15 +4048,15 @@ private synchronized UserVmVO getPermittedVmResource(DataCenter zone, String hos
40484048
profile.setDefaultNic(true);
40494049
if (!_networkModel.areServicesSupportedInNetwork(network.getId(), new Service[]{Service.UserData})) {
40504050
if ((userData != null) && (!userData.isEmpty())) {
4051-
throw new InvalidParameterValueException("Unable to deploy VM as UserData is provided while deploying the VM, but there is no support for " + Service.UserData.getName() + " service in the default network " + network.getId());
4051+
throwInvalidParemeterExceptionForNet(network, "Unable to deploy VM as UserData is provided while deploying the VM");
40524052
}
40534053

40544054
if ((sshPublicKeys != null) && (!sshPublicKeys.isEmpty())) {
4055-
throw new InvalidParameterValueException("Unable to deploy VM as SSH keypair is provided while deploying the VM, but there is no support for " + Service.UserData.getName() + " service in the default network " + network.getId());
4055+
throwInvalidParemeterExceptionForNet(network, "Unable to deploy VM as SSH keypair is provided while deploying the VM");
40564056
}
40574057

40584058
if (template.isEnablePassword()) {
4059-
throw new InvalidParameterValueException("Unable to deploy VM as template " + template.getId() + " is password enabled, but there is no support for " + Service.UserData.getName() + " service in the default network " + network.getId());
4059+
throwInvalidParemeterExceptionForNet(network, String.format("Unable to deploy VM as template %d is password enabled", template.getId()));
40604060
}
40614061
}
40624062
}
@@ -4167,6 +4167,14 @@ private synchronized UserVmVO getPermittedVmResource(DataCenter zone, String hos
41674167
return vm;
41684168
}
41694169

4170+
private static void throwInvalidParemeterExceptionForNet(NetworkVO network, String reason) {
4171+
String message = String.format("%s, but there is no support for %s service in the default network %d."
4172+
, reason
4173+
, Service.UserData.getName()
4174+
, network.getId());
4175+
throw new InvalidParameterValueException(message);
4176+
}
4177+
41704178
private long verifyAndGetDiskSize(DiskOfferingVO diskOffering, Long diskSize) {
41714179
long size = 0l;
41724180
if (diskOffering == null) {

0 commit comments

Comments
 (0)